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
--- 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(() => {