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.

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

mercurial