Bug 886054 - Ensure that the {Promise} is returned before checking the "icon" case in checkItem(). r=Mano, a=test-only
authorRaymond Lee <raymond@raysquare.com>
Thu, 10 Oct 2013 14:03:50 +0800
changeset 176082 d20c6ac43fcd701b457db99763cd4f88e0c5f683
parent 176081 99276938de235d35299198aba9a373bb8bb70d30
child 176083 a3c5fba01aef368a1ab9d04514a607c55f8df8ab
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMano, test-only
bugs886054
milestone28.0a2
Bug 886054 - Ensure that the {Promise} is returned before checking the "icon" case in checkItem(). r=Mano, a=test-only
toolkit/components/places/tests/unit/test_bookmarks_html.js
toolkit/components/places/tests/unit/test_bookmarks_json.js
--- a/toolkit/components/places/tests/unit/test_bookmarks_html.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_html.js
@@ -325,41 +325,40 @@ function checkItem(aExpected, aNode)
           do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(id),
                       aExpected.dateAdded);
           break;
         case "lastModified":
           do_check_eq(PlacesUtils.bookmarks.getItemLastModified(id),
                       aExpected.lastModified);
           break;
         case "url":
-          yield function() {
-            let deferred = Promise.defer();
+          let (deferred = Promise.defer()) {
             PlacesUtils.livemarks.getLivemark(
               { id: id },
               function (aStatus, aLivemark) {
-                if (!Components.isSuccessCode(aStatus)) {
-                  do_check_eq(aNode.uri, aExpected.url);
-                }
                 deferred.resolve();
-              }
-            );
-          return deferred.promise; }();
+              });
+            let status = yield deferred.promise;
+            if (!Components.isSuccessCode(status)) {
+              do_check_eq(aNode.uri, aExpected.url);
+            }
+          }
           break;
         case "icon":
-          yield function() {
-            let deferred = Promise.defer();
+          let (deferred = Promise.defer(), data) {
             PlacesUtils.favicons.getFaviconDataForPage(
               NetUtil.newURI(aExpected.url),
-              function (aURI, aDataLen, aData, aMimeType) {
-                let base64Icon = "data:image/png;base64," +
-                  base64EncodeString(String.fromCharCode.apply(String, aData));
-                do_check_true(base64Icon == aExpected.icon);
-                deferred.resolve();
-            });
-            return deferred.promise; }();
+                function (aURI, aDataLen, aData, aMimeType) {
+                deferred.resolve(aData);
+              });
+            data = yield deferred.promise;
+            let base64Icon = "data:image/png;base64," +
+                             base64EncodeString(String.fromCharCode.apply(String, data));
+            do_check_true(base64Icon == aExpected.icon);
+          }
           break;
         case "keyword":
           break;
         case "sidebar":
           do_check_eq(PlacesUtils.annotations
                                  .itemHasAnnotation(id, LOAD_IN_SIDEBAR_ANNO),
                       aExpected.sidebar);
           break;
@@ -368,28 +367,27 @@ function checkItem(aExpected, aNode)
                                  .getItemAnnotation(id, PlacesUtils.POST_DATA_ANNO),
                       aExpected.postData);
           break;
         case "charset":
           let testURI = NetUtil.newURI(aNode.uri);
           do_check_eq((yield PlacesUtils.getCharsetForURI(testURI)), aExpected.charset);
           break;
         case "feedUrl":
-          yield function() {
-            let deferred = Promise.defer();
+          let (deferred = Promise.defer(), data) {
             PlacesUtils.livemarks.getLivemark(
               { id: id },
               function (aStatus, aLivemark) {
-                do_check_true(Components.isSuccessCode(aStatus));
-                do_check_eq(aLivemark.siteURI.spec, aExpected.url);
-                do_check_eq(aLivemark.feedURI.spec, aExpected.feedUrl);
-                deferred.resolve();
-              }
-            );
-          return deferred.promise; }();
+                deferred.resolve({ status: aStatus, livemark: aLivemark });
+              });
+            data = yield deferred.promise;
+            do_check_true(Components.isSuccessCode(data.status));
+            do_check_eq(data.livemark.siteURI.spec, aExpected.url);
+            do_check_eq(data.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)));
--- a/toolkit/components/places/tests/unit/test_bookmarks_json.js
+++ b/toolkit/components/places/tests/unit/test_bookmarks_json.js
@@ -156,67 +156,67 @@ function checkItem(aExpected, aNode) {
           do_check_eq(PlacesUtils.bookmarks.getItemDateAdded(id),
                       aExpected.dateAdded);
           break;
         case "lastModified":
           do_check_eq(PlacesUtils.bookmarks.getItemLastModified(id),
                       aExpected.lastModified);
           break;
         case "url":
-          yield function() {
-            let deferred = Promise.defer();
+          let (deferred = Promise.defer()) {
             PlacesUtils.livemarks.getLivemark(
               { id: id },
               function (aStatus, aLivemark) {
-                if (!Components.isSuccessCode(aStatus)) {
-                  do_check_eq(aNode.uri, aExpected.url);
-                }
                 deferred.resolve();
               });
-            return deferred.promise; }();
+            let status = yield deferred.promise;
+            if (!Components.isSuccessCode(status)) {
+              do_check_eq(aNode.uri, aExpected.url);
+            }
+          }
           break;
         case "icon":
-          yield function() {
-            let deferred = Promise.defer();
+          let (deferred = Promise.defer(), data) {
             PlacesUtils.favicons.getFaviconDataForPage(
               NetUtil.newURI(aExpected.url),
               function (aURI, aDataLen, aData, aMimeType) {
-                let base64Icon = "data:image/png;base64," +
-                      base64EncodeString(String.fromCharCode.apply(String, aData));
-                do_check_true(base64Icon == aExpected.icon);
-                deferred.resolve();
+                deferred.resolve(aData);
               });
-            return deferred.promise; }();
+            data = yield deferred.promise;
+            let base64Icon = "data:image/png;base64," +
+                             base64EncodeString(String.fromCharCode.apply(String, data));
+            do_check_true(base64Icon == aExpected.icon);
+          }
           break;
         case "keyword":
           break;
         case "sidebar":
           do_check_eq(PlacesUtils.annotations.itemHasAnnotation(
                       id, LOAD_IN_SIDEBAR_ANNO), aExpected.sidebar);
           break;
         case "postData":
           do_check_eq(PlacesUtils.annotations.getItemAnnotation(
                       id, PlacesUtils.POST_DATA_ANNO), aExpected.postData);
           break;
         case "charset":
           let testURI = NetUtil.newURI(aNode.uri);
           do_check_eq((yield PlacesUtils.getCharsetForURI(testURI)), aExpected.charset);
           break;
         case "feedUrl":
-          yield function() {
-            let deferred = Promise.defer();
+          let (deferred = Promise.defer(), data) {
             PlacesUtils.livemarks.getLivemark(
               { id: id },
               function (aStatus, aLivemark) {
-                do_check_true(Components.isSuccessCode(aStatus));
-                do_check_eq(aLivemark.siteURI.spec, aExpected.url);
-                do_check_eq(aLivemark.feedURI.spec, aExpected.feedUrl);
-                deferred.resolve();
+                deferred.resolve({ status: aStatus, livemark: aLivemark });
               });
-            return deferred.promise; }();
+            data = yield deferred.promise;
+            do_check_true(Components.isSuccessCode(data.status));
+            do_check_eq(data.livemark.siteURI.spec, aExpected.url);
+            do_check_eq(data.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)));