Bug 1257380 - Fix Intermittent test_ext_bookmarks.html, r?kmag draft
authorbsilverberg <bsilverberg@mozilla.com>
Thu, 17 Mar 2016 11:17:16 +0100
changeset 342461 3824a63f87cd174decb0c43af36950ebbadeb5f4
parent 341520 8671dfbbff2dfa2fa6c410f4c0799f4b7c2e7484
child 516590 8f82d73c274a49c83321a5affc0d74740a37b152
push id13425
push userbmo:bob.silverberg@gmail.com
push dateSat, 19 Mar 2016 14:51:59 +0000
reviewerskmag
bugs1257380
milestone48.0a1
Bug 1257380 - Fix Intermittent test_ext_bookmarks.html, r?kmag I don't think we can rely on the bookmarks being created in a specific order, although that mostly seems to happen, so rather than check for an exact list of bookmarks returned from getRecent(), we can just check that the bookmarks we get back are in reverse chronological order and that the 4 most recently created bookmarks are returned. MozReview-Commit-ID: DhT7raJRe7N
toolkit/components/extensions/test/mochitest/test_ext_bookmarks.html
--- a/toolkit/components/extensions/test/mochitest/test_ext_bookmarks.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_bookmarks.html
@@ -390,24 +390,31 @@ function backgroundScript() {
 
       return browser.bookmarks.move(corporationBookmark.id, {parentId: bookmarkGuids.toolbarGuid, index: 1});
     }).then(result => {
       browser.test.assertEq(bookmarkGuids.toolbarGuid, result.parentId, "Bookmark has the expected parent");
       browser.test.assertEq(1, result.index, "Bookmark has the expected index");
       createdBookmarks.add(corporationBookmark.id);
     });
   }).then(() => {
-    return browser.bookmarks.getRecent(5);
+    return browser.bookmarks.getRecent(4);
   }).then(results => {
-    browser.test.assertEq(5, results.length, "Expected number of results returned by getRecent");
-    browser.test.assertEq("About Mozilla", results[0].title, "Bookmark has the expected title");
-    browser.test.assertEq("Firefox", results[1].title, "Bookmark has the expected title");
-    browser.test.assertEq("Mozilla Corporation", results[2].title, "Bookmark has the expected title");
-    browser.test.assertEq("Mozilla", results[3].title, "Bookmark has the expected title");
-    browser.test.assertEq("Toolbar Item", results[4].title, "Bookmark has the expected title");
+    browser.test.assertEq(4, results.length, "Expected number of results returned by getRecent");
+    let prevDate = results[0].dateAdded;
+    for (let bookmark of results) {
+      browser.test.assertTrue(bookmark.dateAdded <= prevDate, "The recent bookmarks are sorted by dateAdded");
+      prevDate = bookmark.dateAdded;
+    }
+    let bookmarksByTitle = results.sort((a, b) => {
+      return a.title.localeCompare(b.title);
+    });
+    browser.test.assertEq("About Mozilla", bookmarksByTitle[0].title, "Bookmark has the expected title");
+    browser.test.assertEq("Firefox", bookmarksByTitle[1].title, "Bookmark has the expected title");
+    browser.test.assertEq("Mozilla", bookmarksByTitle[2].title, "Bookmark has the expected title");
+    browser.test.assertEq("Mozilla Corporation", bookmarksByTitle[3].title, "Bookmark has the expected title");
 
     return browser.bookmarks.search({});
   }).then(results => {
     let startBookmarkCount = results.length;
 
     return browser.bookmarks.search({title: "Mozilla Folder"}).then(result => {
       return browser.bookmarks.removeTree(result[0].id);
     }).then(() => {