Bug 1116457 - Intermittent browser_history_sidebar_search.js. r=adw
MozReview-Commit-ID: Dpsx7fw7pad
--- a/browser/components/places/tests/browser/browser.ini
+++ b/browser/components/places/tests/browser/browser.ini
@@ -28,17 +28,16 @@ support-files =
[browser_bookmarkProperties_addLivemark.js]
[browser_bookmarkProperties_editTagContainer.js]
[browser_bookmarkProperties_readOnlyRoot.js]
[browser_bookmarksProperties.js]
[browser_drag_bookmarks_on_toolbar.js]
skip-if = e10s # Bug ?????? - test fails - "Number of dragged items should be the same. - Got 0, expected 1"
[browser_forgetthissite_single.js]
[browser_history_sidebar_search.js]
-skip-if = e10s && (os == 'linux' || os == 'mac') # Bug 1116457
[browser_library_batch_delete.js]
[browser_library_commands.js]
[browser_library_downloads.js]
[browser_library_infoBox.js]
[browser_library_left_pane_fixnames.js]
[browser_library_left_pane_select_hierarchy.js]
[browser_library_middleclick.js]
[browser_library_open_leak.js]
--- a/browser/components/places/tests/browser/browser_history_sidebar_search.js
+++ b/browser/components/places/tests/browser/browser_history_sidebar_search.js
@@ -1,89 +1,64 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/**
- * Bug 392497 - search in history sidebar loses sort
- */
+add_task(function* test () {
+ let sidebar = document.getElementById("sidebar");
-var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
- getService(Ci.nsINavHistoryService);
-var bh = hs.QueryInterface(Ci.nsIBrowserHistory);
-var ios = Cc["@mozilla.org/network/io-service;1"].
- getService(Ci.nsIIOService);
-function uri(spec) {
- return ios.newURI(spec, null, null);
-}
+ // Visited pages listed by descending visit date.
+ let pages = [
+ "http://sidebar.mozilla.org/a",
+ "http://sidebar.mozilla.org/b",
+ "http://sidebar.mozilla.org/c",
+ "http://www.mozilla.org/d",
+ ];
-var sidebar = document.getElementById("sidebar");
+ // Number of pages that will be filtered out by the search.
+ const FILTERED_COUNT = 1;
+
+ yield PlacesTestUtils.clearHistory();
-// Visited pages listed by descending visit date.
-var pages = [
- "http://sidebar.mozilla.org/a",
- "http://sidebar.mozilla.org/b",
- "http://sidebar.mozilla.org/c",
- "http://www.mozilla.org/d",
-];
-// Number of pages that will be filtered out by the search.
-const FILTERED_COUNT = 1;
-
-function test() {
- waitForExplicitFinish();
+ // Add some visited page.
+ let time = Date.now();
+ let places = [];
+ for (let i = 0; i < pages.length; i++) {
+ places.push({ uri: NetUtil.newURI(pages[i]),
+ visitDate: (time - i) * 1000,
+ transition: PlacesUtils.history.TRANSITION_TYPED });
+ }
+ yield PlacesTestUtils.addVisits(places);
- // Cleanup.
- PlacesTestUtils.clearHistory().then(continue_test);
-}
+ yield withSidebarTree("history", function* () {
+ info("Set 'by last visited' view");
+ sidebar.contentDocument.getElementById("bylastvisited").doCommand();
+ let tree = sidebar.contentDocument.getElementById("historyTree");
+ check_tree_order(tree, pages);
-function continue_test() {
- // Add some visited page.
- var time = Date.now();
- var pagesLength = pages.length;
- var places = [];
- for (var i = 0; i < pagesLength; i++) {
- places.push({uri: uri(pages[i]), visitDate: (time - i) * 1000,
- transition: hs.TRANSITION_TYPED});
- }
- PlacesTestUtils.addVisits(places).then(() => {
- SidebarUI.show("viewHistorySidebar");
+ // Set a search value.
+ let searchBox = sidebar.contentDocument.getElementById("search-box");
+ ok(searchBox, "search box is in context");
+ searchBox.value = "sidebar.mozilla";
+ searchBox.doCommand();
+ check_tree_order(tree, pages, -FILTERED_COUNT);
+
+ // Resete the search
+ searchBox.value = "";
+ searchBox.doCommand();
+ check_tree_order(tree, pages);
});
- sidebar.addEventListener("load", function() {
- sidebar.removeEventListener("load", arguments.callee, true);
- executeSoon(function() {
- // Set "by last visited" in the sidebar (sort by visit date descendind).
- sidebar.contentDocument.getElementById("bylastvisited").doCommand();
- check_sidebar_tree_order(pages.length);
- var searchBox = sidebar.contentDocument.getElementById("search-box");
- ok(searchBox, "search box is in context");
- searchBox.value = "sidebar.mozilla";
- searchBox.doCommand();
- check_sidebar_tree_order(pages.length - FILTERED_COUNT);
- searchBox.value = "";
- searchBox.doCommand();
- check_sidebar_tree_order(pages.length);
+ yield PlacesTestUtils.clearHistory();
+});
- // Cleanup.
- SidebarUI.hide();
- PlacesTestUtils.clearHistory().then(finish);
- });
- }, true);
-}
+function check_tree_order(tree, pages, aNumberOfRowsDelta = 0) {
+ let treeView = tree.view;
+ let columns = tree.columns;
+ is(columns.count, 1, "There should be only 1 column in the sidebar");
-function check_sidebar_tree_order(aExpectedRows) {
- var tree = sidebar.contentDocument.getElementById("historyTree");
- var treeView = tree.view;
- var rc = treeView.rowCount;
- var columns = tree.columns;
- is(columns.count, 1, "There should be only 1 column in the sidebar");
- var found = 0;
- for (var r = 0; r < rc; r++) {
- var node = treeView.nodeForTreeIndex(r);
- // We could inherit visits from previous tests, skip them since they are
- // not interesting for us.
+ let found = 0;
+ for (let i = 0; i < treeView.rowCount; i++) {
+ let node = treeView.nodeForTreeIndex(i);
+ // We could inherit delayed visits from previous tests, skip them.
if (!pages.includes(node.uri))
continue;
- is(node.uri, pages[r], "Node is in correct position based on its visit date");
+ is(node.uri, pages[i], "Node is in correct position based on its visit date");
found++;
}
- ok(found, aExpectedRows, "Found all expected results");
+ ok(found, pages.length + aNumberOfRowsDelta, "Found all expected results");
}