browser/components/places/tests/chrome/test_treeview_date.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     4    - License, v. 2.0. If a copy of the MPL was not distributed with this
     5    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
     7 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     8 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
     9                  type="text/css"?>
    11 <?xml-stylesheet href="chrome://browser/content/places/places.css"?>
    12 <?xml-stylesheet href="chrome://browser/skin/places/places.css"?>
    13 <?xul-overlay href="chrome://browser/content/places/placesOverlay.xul"?>
    15 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    16         title="435322: Places tree view's formatting"
    17         onload="runTest();">
    19   <script type="application/javascript"
    20           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    21   <script type="application/javascript" src="head.js" />
    23   <body xmlns="http://www.w3.org/1999/xhtml" />
    25   <tree id="tree"
    26         type="places"
    27         flatList="true"
    28         flex="1">
    29     <treecols>
    30       <treecol label="Title" id="title" anonid="title" primary="true" ordinal="1" flex="1"/>
    31       <splitter class="tree-splitter"/>
    32       <treecol label="Tags" id="tags" anonid="tags" flex="1"/>
    33       <splitter class="tree-splitter"/>
    34       <treecol label="Url" id="url" anonid="url" flex="1"/>
    35       <splitter class="tree-splitter"/>
    36       <treecol label="Visit Date" id="date" anonid="date" flex="1"/>
    37       <splitter class="tree-splitter"/>
    38       <treecol label="Visit Count" id="visitCount" anonid="visitCount" flex="1"/>
    39     </treecols>
    40     <treechildren flex="1"/>
    41   </tree>
    43   <script type="application/javascript">
    44   <![CDATA[
    46     /**
    47      * Bug 435322
    48      * https://bugzilla.mozilla.org/show_bug.cgi?id=435322
    49      *
    50      * Ensures that date in places treeviews is correctly formatted.
    51      */
    53     SimpleTest.waitForExplicitFinish();
    55     function runTest() {
    56       // The mochitest page is added to history.
    57       waitForClearHistory(continue_test);
    58     }
    60     function continue_test() {
    61       var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
    62                getService(Ci.nsINavHistoryService);
    63       var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
    64       var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"].
    65                getService(Ci.nsINavBookmarksService);
    66       var ds = Cc["@mozilla.org/intl/scriptabledateformat;1"].
    67                getService(Ci.nsIScriptableDateFormat);
    69       var iosvc = Cc["@mozilla.org/network/io-service;1"].
    70                   getService(Ci.nsIIOService);
    71       function uri(spec) {
    72         return iosvc.newURI(spec, null, null);
    73       }
    75       var midnight = new Date();
    76       midnight.setHours(0);
    77       midnight.setMinutes(0);
    78       midnight.setSeconds(0);
    79       midnight.setMilliseconds(0);
    81       function addVisitsCallback() {
    82         // add a bookmark to the midnight visit
    83         var itemId = bs.insertBookmark(bs.toolbarFolder,
    84                                        uri("http://at.midnight.com/"),
    85                                        bs.DEFAULT_INDEX,
    86                                        "A bookmark at midnight");
    88         // Make a history query.
    89         var query = hs.getNewQuery();
    90         var opts = hs.getNewQueryOptions();
    91         var queryURI = hs.queriesToQueryString([query], 1, opts);
    93         // Setup the places tree contents.
    94         var tree = document.getElementById("tree");
    95         tree.place = queryURI;
    97         // loop through the rows and check formatting
    98         var treeView = tree.view;
    99         var rc = treeView.rowCount;
   100         ok(rc >= 3, "Rows found");
   101         var columns = tree.columns;
   102         ok(columns.count > 0, "Columns found");
   103         for (var r = 0; r < rc; r++) {
   104           var node = treeView.nodeForTreeIndex(r);
   105           ok(node, "Places node found");
   106           for (var ci = 0; ci < columns.count; ci++) {
   107             var c = columns.getColumnAt(ci);
   108             var text = treeView.getCellText(r, c);
   109             switch (c.element.getAttribute("anonid")) {
   110               case "title":
   111                 // The title can differ, we did not set any title so we would
   112                 // expect null, but in such a case the view will generate a title
   113                 // through PlacesUIUtils.getBestTitle.
   114                 if (node.title)
   115                   is(text, node.title, "Title is correct");
   116                 break;
   117               case "url":
   118                 is(text, node.uri, "Uri is correct");
   119                 break;
   120               case "date":
   121                 var timeObj = new Date(node.time / 1000);
   122                 // Default is short date format.
   123                 var dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
   124                 // For today's visits we don't show date portion.
   125                 if (node.uri == "http://at.midnight.com/" ||
   126                     node.uri == "http://after.midnight.com/")
   127                   dateFormat = Ci.nsIScriptableDateFormat.dateFormatNone;
   128                 else if (node.uri == "http://before.midnight.com/")
   129                   dateFormat = Ci.nsIScriptableDateFormat.dateFormatShort;
   130                 else {
   131                   // Avoid to test spurious uris, due to how the test works
   132                   // a redirecting uri could be put in the tree while we test.
   133                   break;
   134                 }
   135                 var timeStr = ds.FormatDateTime("", dateFormat,
   136                       Ci.nsIScriptableDateFormat.timeFormatNoSeconds,
   137                       timeObj.getFullYear(), timeObj.getMonth() + 1,
   138                       timeObj.getDate(), timeObj.getHours(),
   139                       timeObj.getMinutes(), timeObj.getSeconds())
   141                 is(text, timeStr, "Date format is correct");
   142                 break;
   143               case "visitCount":
   144                 is(text, 1, "Visit count is correct");
   145                 break;
   146             }
   147           }
   148         }
   149         // Cleanup.
   150         bs.removeItem(itemId);
   151         waitForClearHistory(SimpleTest.finish);
   152       }
   154       // Add a visit 1ms before midnight, a visit at midnight, and
   155       // a visit 1ms after midnight.
   156       addVisits(
   157         [{uri: uri("http://before.midnight.com/"),
   158            visitDate: (midnight.getTime() - 1) * 1000,
   159            transition: hs.TRANSITION_TYPED},
   160          {uri: uri("http://at.midnight.com/"),
   161            visitDate: (midnight.getTime()) * 1000,
   162            transition: hs.TRANSITION_TYPED},
   163          {uri: uri("http://after.midnight.com/"),
   164            visitDate: (midnight.getTime() + 1) * 1000,
   165            transition: hs.TRANSITION_TYPED}],
   166         addVisitsCallback);
   167     }
   169     /**
   170      * Clears history invoking callback when done.
   171      */
   172     function waitForClearHistory(aCallback) {
   173       const TOPIC_EXPIRATION_FINISHED = "places-expiration-finished";
   174       let observer = {
   175         observe: function(aSubject, aTopic, aData) {
   176           Services.obs.removeObserver(this, TOPIC_EXPIRATION_FINISHED);
   177           aCallback();
   178         }
   179       };
   180       Services.obs.addObserver(observer, TOPIC_EXPIRATION_FINISHED, false);
   181       let hs = Cc["@mozilla.org/browser/nav-history-service;1"].
   182                getService(Ci.nsINavHistoryService);
   183       hs.QueryInterface(Ci.nsIBrowserHistory).removeAllPages();
   184    }
   186   ]]>
   187   </script>
   188 </window>

mercurial