Bug 1296201 - Wait for SafeBrowsing,jsm to be initialized before running testcase. r=francois
authordimi <dlee@mozilla.com>
Wed, 24 Aug 2016 17:00:08 +0800
changeset 311064 a1431a26359cfc23352d425e2e2ecda346c5299c
parent 311063 0f17004b8c213b8ad8931a689f5c6df3455a808b
child 311065 c857c69bd7397cdf374fde23abd158f8688f9d78
push id81034
push userryanvm@gmail.com
push dateThu, 25 Aug 2016 12:27:32 +0000
treeherdermozilla-inbound@87049fc2117f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1296201
milestone51.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 1296201 - Wait for SafeBrowsing,jsm to be initialized before running testcase. r=francois MozReview-Commit-ID: 8o3cszqJK36
toolkit/components/url-classifier/tests/mochitest/test_classifier.html
toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html
toolkit/components/url-classifier/tests/mochitest/test_classify_track.html
toolkit/components/url-classifier/tests/mochitest/test_gethash.html
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier.html
@@ -44,17 +44,18 @@ function updateError(errorCode) {
   // Abort test.
   SimpleTest.finish();
 }
 
 SpecialPowers.pushPrefEnv(
   {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"],
             ["urlclassifier.phishTable", "test-phish-simple"]]},
   function() {
-    classifierHelper.addUrlToDB(testData)
+    classifierHelper.waitForInit()
+      .then(() => { classifierHelper.addUrlToDB(testData); })
       .then(updateSuccess)
       .catch(err => {
         updateError(err);
       });
   });
 
 </script>
 
--- a/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classifier_worker.html
@@ -51,17 +51,18 @@ function updateError(errorCode) {
   // Abort test.
   SimpleTest.finish();
 };
 
 SpecialPowers.pushPrefEnv(
   {"set" : [["urlclassifier.malwareTable", "test-malware-simple,test-unwanted-simple"],
             ["urlclassifier.phishTable", "test-phish-simple"]]},
   function() {
-    classifierHelper.addUrlToDB(testData)
+    classifierHelper.waitForInit()
+      .then(() => { classifierHelper.addUrlToDB(testData); })
       .then(updateSuccess)
       .catch(err => {
         updateError(err);
       });
   });
 
 window.addEventListener("message", onmessage, false);
 
--- a/toolkit/components/url-classifier/tests/mochitest/test_classify_track.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_classify_track.html
@@ -111,34 +111,35 @@
       track.addEventListener("error", onerror)
     });
   }
 
   function cleanup() {
     SpecialPowers.clearUserPref(PREF);
   }
 
-  function addMalewareUrlToDB() {
+  function setup() {
     var testData = [
       { url: "malware.example.com/",
         db: "test-malware-simple"
       }
     ];
 
     return classifierHelper.addUrlToDB(testData)
       .catch(function(err) {
         ok(false, "Couldn't update classifier. Error code: " + err);
         // Abort test.
         SimpleTest.finish();
       });
   }
 
   function runTest() {
     Promise.resolve()
-      .then(addMalewareUrlToDB)
+      .then(classifierHelper.waitForInit)
+      .then(setup)
       .then(testValidTrack)
       .then(testBlacklistTrackSafebrowsingOff)
       .then(testBlacklistTrackSafebrowsingOn)
       .then(function() {
         SimpleTest.finish();
       }).catch(function(e) {
         ok(false, "Some test failed with error " + e);
         SimpleTest.finish();
--- a/toolkit/components/url-classifier/tests/mochitest/test_gethash.html
+++ b/toolkit/components/url-classifier/tests/mochitest/test_gethash.html
@@ -101,17 +101,17 @@ function setup404() {
   classifierHelper.allowCompletion([MALWARE_LIST, UNWANTED_LIST], NOTEXIST_URL);
 
   return Promise.all([
     addPrefixToDB(MALWARE_LIST, MALWARE_HOST),
     addPrefixToDB(UNWANTED_LIST, UNWANTED_HOST)
   ]);
 }
 
-function setupCompletion() {
+function setup() {
   classifierHelper.allowCompletion([MALWARE_LIST, UNWANTED_LIST], GETHASH_URL);
 
   return Promise.all([
     addPrefixToDB(MALWARE_LIST, MALWARE_HOST),
     addPrefixToDB(UNWANTED_LIST, UNWANTED_HOST),
     addCompletionToServer(MALWARE_LIST, MALWARE_HOST),
     addCompletionToServer(UNWANTED_LIST, UNWANTED_HOST),
   ]);
@@ -120,17 +120,18 @@ function setupCompletion() {
 // manually reset DB to make sure next test won't be affected by cache.
 function reset() {
   return classifierHelper.resetDB;
 }
 
 function runTest() {
   Promise.resolve()
     // This test resources get blocked when gethash returns successfully
-    .then(setupCompletion)
+    .then(classifierHelper.waitForInit)
+    .then(setup)
     .then(() => loadTestFrame("testFrame1"))
     .then(reset)
     // This test resources are not blocked when gethash returns an error
     .then(setup404)
     .then(() => loadTestFrame("testFrame2"))
     .then(function() {
       SimpleTest.finish();
     }).catch(function(e) {