Bug 1262662 - Clear history on startup for newtab messages tests. r=marcosc, a=test-only
authorOlivier Yiptong <olivier@olivieryiptong.com>
Thu, 14 Apr 2016 07:57:22 -0700
changeset 332919 cc5d9a00a4d3e7744dfdb4d0512ac2f0e91b5e5e
parent 332918 9942206d3f9c41e6d0ffd7c34460ed71fd329a97
child 332920 fc892ee6a813feb13bbc33bad99cfd7211e7b35b
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarcosc, test-only
bugs1262662
milestone48.0a2
Bug 1262662 - Clear history on startup for newtab messages tests. r=marcosc, a=test-only MozReview-Commit-ID: C10RS4fH5FW
browser/components/newtab/tests/browser/browser_newtabmessages.js
--- a/browser/components/newtab/tests/browser/browser_newtabmessages.js
+++ b/browser/components/newtab/tests/browser/browser_newtabmessages.js
@@ -1,39 +1,42 @@
-/* globals Cu, XPCOMUtils, Preferences, is, registerCleanupFunction, NewTabWebChannel, PlacesTestUtils */
+/* globals Cu, XPCOMUtils, Preferences, is, registerCleanupFunction, NewTabWebChannel, PlacesTestUtils, Task */
 
 "use strict";
 
 Cu.import("resource://gre/modules/Preferences.jsm");
+Cu.import("resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "NewTabWebChannel",
                                   "resource:///modules/NewTabWebChannel.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "NewTabMessages",
                                   "resource:///modules/NewTabMessages.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils",
                                   "resource://testing-common/PlacesTestUtils.jsm");
 
-function setup() {
+let setup = Task.async(function*() {
   Preferences.set("browser.newtabpage.enhanced", true);
   Preferences.set("browser.newtabpage.remote.mode", "test");
   Preferences.set("browser.newtabpage.remote", true);
   NewTabMessages.init();
-}
+  yield PlacesTestUtils.clearHistory();
+});
 
-function cleanup() {
+let cleanup = Task.async(function*() {
   NewTabMessages.uninit();
   Preferences.set("browser.newtabpage.remote", false);
   Preferences.set("browser.newtabpage.remote.mode", "production");
-}
+});
 registerCleanupFunction(cleanup);
 
 /*
  * Sanity tests for pref messages
  */
 add_task(function* prefMessages_request() {
-  setup();
+  yield setup();
+
   let testURL = "https://example.com/browser/browser/components/newtab/tests/browser/newtabmessages_prefs.html";
 
   let tabOptions = {
     gBrowser,
     url: testURL
   };
 
   let prefResponseAck = new Promise(resolve => {
@@ -49,24 +52,24 @@ add_task(function* prefMessages_request(
       NewTabWebChannel.once("responseAck", () => {
         ok(true, "a change response has been received");
         resolve();
       });
     });
     Preferences.set("browser.newtabpage.enhanced", false);
     yield prefChangeAck;
   });
-  cleanup();
+  yield cleanup();
 });
 
 /*
  * Sanity tests for preview messages
  */
 add_task(function* previewMessages_request() {
-  setup();
+  yield setup();
   var oldEnabledPref = Services.prefs.getBoolPref("browser.pagethumbnails.capturing_disabled");
   Services.prefs.setBoolPref("browser.pagethumbnails.capturing_disabled", false);
 
   let testURL = "https://example.com/browser/browser/components/newtab/tests/browser/newtabmessages_preview.html";
 
   let tabOptions = {
     gBrowser,
     url: testURL
@@ -77,25 +80,25 @@ add_task(function* previewMessages_reque
       ok(true, "a request response has been received");
       resolve();
     });
   });
 
   yield BrowserTestUtils.withNewTab(tabOptions, function*() {
     yield previewResponseAck;
   });
-  cleanup();
+  yield cleanup();
   Services.prefs.setBoolPref("browser.pagethumbnails.capturing_disabled", oldEnabledPref);
 });
 
 /*
  * Sanity tests for places messages
  */
 add_task(function* placesMessages_request() {
-  setup();
+  yield setup();
   let testURL = "https://example.com/browser/browser/components/newtab/tests/browser/newtabmessages_places.html";
 
   // url prefix for test history population
   const TEST_URL = "https://mozilla.com/";
   // time when the test starts execution
   const TIME_NOW = (new Date()).getTime();
 
   // utility function to compute past timestamp
@@ -134,27 +137,27 @@ add_task(function* placesMessages_reques
   let tabOptions = {
     gBrowser,
     url: testURL
   };
 
   let placesResponseAck = new Promise(resolve => {
     NewTabWebChannel.once("numItemsAck", (_, msg) => {
       ok(true, "a request response has been received");
-      is(msg.data, visits.length + 1, "received an expect number of history items");
+      is(msg.data, visits.length + 1, "received an expected number of history items");
       resolve();
     });
   });
 
   yield BrowserTestUtils.withNewTab(tabOptions, function*() {
     yield placesResponseAck;
+    ok(true, "a change response has been received");
     let placesChangeAck = new Promise(resolve => {
       NewTabWebChannel.once("clearHistoryAck", (_, msg) => {
-        ok(true, "a change response has been received");
         is(msg.data, "clearHistory", "a clear history message has been received");
         resolve();
       });
     });
     yield PlacesTestUtils.clearHistory();
     yield placesChangeAck;
   });
-  cleanup();
+  yield cleanup();
 });