Bug 1079387 - Need yield for checkItem to avoid intermittent failures. r=mak
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 09 Dec 2014 03:11:00 -0500
changeset 219081 1b2e93350b709e30a481230ee997ec725d8f2709
parent 219080 8e5fce59af55796464b339492e1bdc2963fcdc60
child 219082 5d39b220aa02079b7e80a8f88d5b1e51fd28feac
push id27954
push userryanvm@gmail.com
push dateWed, 10 Dec 2014 21:10:24 +0000
treeherdermozilla-central@0cf461e62ce5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1079387
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1079387 - Need yield for checkItem to avoid intermittent failures. r=mak
toolkit/components/places/tests/unit/test_bookmarks_html.js
--- a/toolkit/components/places/tests/unit/test_bookmarks_html.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html.js
@@ -74,17 +74,17 @@ let gBookmarksFileNew;
 
 Cu.import("resource://gre/modules/BookmarkHTMLUtils.jsm");
 
 function run_test()
 {
   run_next_test();
 }
 
-add_task(function setup() {
+add_task(function* setup() {
   // Avoid creating smart bookmarks during the test.
   Services.prefs.setIntPref("browser.places.smartBookmarksVersion", -1);
 
   // File pointer to legacy bookmarks file.
   gBookmarksFileOld = do_get_file("bookmarks.preplaces.html");
 
   // File pointer to a new Places-exported bookmarks file.
   gBookmarksFileNew = Services.dirsvc.get("ProfD", Ci.nsILocalFile);
@@ -102,31 +102,31 @@ add_task(function setup() {
   yield promiseAsyncUpdates();
   yield testImportedBookmarks();
 
   yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
   yield promiseAsyncUpdates();
   remove_all_bookmarks();
 });
 
-add_task(function test_import_new()
+add_task(function* test_import_new()
 {
   // Test importing a Places bookmarks.html file.
   // 1. import bookmarks.exported.html
   // 2. run the test-suite
   yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true);
   yield promiseAsyncUpdates();
 
   yield testImportedBookmarks();
   yield promiseAsyncUpdates();
 
   remove_all_bookmarks();
 });
 
-add_task(function test_emptytitle_export()
+add_task(function* test_emptytitle_export()
 {
   // Test exporting and importing with an empty-titled bookmark.
   // 1. import bookmarks
   // 2. create an empty-titled bookmark.
   // 3. export to bookmarks.exported.html
   // 4. empty bookmarks db
   // 5. import bookmarks.exported.html
   // 6. run the test-suite
@@ -154,17 +154,17 @@ add_task(function test_emptytitle_export
   test_bookmarks.unfiled.pop();
   PlacesUtils.bookmarks.removeItem(id);
 
   yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
   yield promiseAsyncUpdates();
   remove_all_bookmarks();
 });
 
-add_task(function test_import_chromefavicon()
+add_task(function* test_import_chromefavicon()
 {
   // Test exporting and importing with a bookmark pointing to a chrome favicon.
   // 1. import bookmarks
   // 2. create a bookmark pointing to a chrome favicon.
   // 3. export to bookmarks.exported.html
   // 4. empty bookmarks db
   // 5. import bookmarks.exported.html
   // 6. run the test-suite
@@ -220,17 +220,17 @@ add_task(function test_import_chromefavi
   test_bookmarks.unfiled.pop();
   PlacesUtils.bookmarks.removeItem(id);
 
   yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
   yield promiseAsyncUpdates();
   remove_all_bookmarks();
 });
 
-add_task(function test_import_ontop()
+add_task(function* test_import_ontop()
 {
   // Test importing the exported bookmarks.html file *on top of* the existing
   // bookmarks.
   // 1. empty bookmarks db
   // 2. import the exported bookmarks file
   // 3. export to file
   // 3. import the exported bookmarks file
   // 4. run the test-suite
@@ -239,17 +239,17 @@ add_task(function test_import_ontop()
   yield BookmarkHTMLUtils.exportToFile(gBookmarksFileNew);
   yield BookmarkHTMLUtils.importFromFile(gBookmarksFileNew, true);
   yield promiseAsyncUpdates();
   yield testImportedBookmarks();
   yield promiseAsyncUpdates();
   remove_all_bookmarks();
 });
 
-function testImportedBookmarks()
+function* testImportedBookmarks()
 {
   for (let group in test_bookmarks) {
     do_print("[testImportedBookmarks()] Checking group '" + group + "'");
 
     let root;
     switch (group) {
       case "menu":
         root = PlacesUtils.getFolderContents(PlacesUtils.bookmarksMenuFolderId).root;
@@ -268,47 +268,17 @@ function testImportedBookmarks()
     for (let key in items) {
       yield checkItem(items[key], root.getChild(key));
     }
 
     root.containerOpen = false;
   }
 }
 
-function testImportedBookmarksToFolder(aFolder)
-{
-  root = PlacesUtils.getFolderContents(aFolder).root;
-
-  // Menu bookmarks are put directly into the folder, while other roots are
-  // imported into subfolders.
-  let rootFolderCount = test_bookmarks.menu.length;
-
-  for (let i = 0; i < root.childCount; i++) {
-    let child = root.getChild(i);
-    // This check depends on all "menu" bookmarks being listed first in the imported file :-|
-    if (i < rootFolderCount) {
-      checkItem(test_bookmarks.menu[i], child);
-    }
-    else {
-      let container = child.QueryInterface(Ci.nsINavHistoryContainerResultNode);
-      let group = /Toolbar/.test(container.title) ? test_bookmarks.toolbar
-                                                  : test_bookmarks.unfiled;
-      container.containerOpen = true;
-      do_print("[testImportedBookmarksToFolder()] Checking container '" + container.title + "'");
-      for (let t = 0; t < container.childCount; t++) {
-        checkItem(group[t], container.getChild(t));
-      }
-      container.containerOpen = false;
-    }
-  }
-
-  root.containerOpen = false;
-}
-
-function checkItem(aExpected, aNode)
+function* checkItem(aExpected, aNode)
 {
   let id = aNode.itemId;
 
   return Task.spawn(function() {
     for (prop in aExpected) {
       switch (prop) {
         case "type":
           do_check_eq(aNode.type, aExpected.type);
@@ -368,17 +338,19 @@ function checkItem(aExpected, aNode)
           do_check_eq(livemark.feedURI.spec, aExpected.feedUrl);
           break;
         case "children":
           let folder = aNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
           do_check_eq(folder.hasChildren, aExpected.children.length > 0);
           folder.containerOpen = true;
           do_check_eq(folder.childCount, aExpected.children.length);
 
-          aExpected.children.forEach(function (item, index) checkItem(item, folder.getChild(index)));
+          for (let index = 0; index < aExpected.children.length; index++) {
+            yield checkItem(aExpected.children[index], folder.getChild(index));
+          }
 
           folder.containerOpen = false;
           break;
         default:
           throw new Error("Unknown property");
       }
     }
   });