Bug 967370 - UITour: Remove duplication in browser chrome tests. r=Unfocused
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 05 Feb 2014 00:31:41 -0800
changeset 166830 cea89064bf58622c67f0125452f9aa6ba15aaa33
parent 166829 31e11855491976d0d36fd1039d947389ef815bb1
child 166831 36caecbe41620181abcc583c307696bb9bf2953d
push id4846
push usermozilla@noorenberghe.ca
push dateWed, 05 Feb 2014 08:33:10 +0000
treeherderfx-team@cea89064bf58 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs967370
milestone30.0a1
Bug 967370 - UITour: Remove duplication in browser chrome tests. r=Unfocused [Australis]
browser/modules/test/browser_UITour.js
browser/modules/test/browser_UITour2.js
browser/modules/test/browser_UITour3.js
browser/modules/test/browser_UITour_sync.js
browser/modules/test/head.js
--- a/browser/modules/test/browser_UITour.js
+++ b/browser/modules/test/browser_UITour.js
@@ -4,112 +4,46 @@
 "use strict";
 
 let gTestTab;
 let gContentAPI;
 let gContentWindow;
 
 Components.utils.import("resource:///modules/UITour.jsm");
 
-function loadTestPage(callback, host = "https://example.com/") {
-   if (gTestTab)
-    gBrowser.removeTab(gTestTab);
-
-  let url = getRootDirectory(gTestPath) + "uitour.html";
-  url = url.replace("chrome://mochitests/content/", host);
-
-  gTestTab = gBrowser.addTab(url);
-  gBrowser.selectedTab = gTestTab;
-
-  gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
-    gTestTab.linkedBrowser.removeEventListener("load", onLoad);
-
-    gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
-    gContentAPI = gContentWindow.Mozilla.UITour;
-
-    waitForFocus(callback, gContentWindow);
-  }, true);
-}
-
 function test() {
-  Services.prefs.setBoolPref("browser.uitour.enabled", true);
-  let testUri = Services.io.newURI("http://example.com", null, null);
-  Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
-
-  waitForExplicitFinish();
-
-  registerCleanupFunction(function() {
-    delete window.UITour;
-    delete window.gContentWindow;
-    delete window.gContentAPI;
-    if (gTestTab)
-      gBrowser.removeTab(gTestTab);
-    delete window.gTestTab;
-    Services.prefs.clearUserPref("browser.uitour.enabled", true);
-    Services.perms.remove("example.com", "uitour");
-  });
-
-  function done() {
-    if (gTestTab)
-      gBrowser.removeTab(gTestTab);
-    gTestTab = null;
-
-    let highlight = document.getElementById("UITourHighlightContainer");
-    is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed");
-
-    let tooltip = document.getElementById("UITourTooltip");
-    is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed");
-
-    ok(!PanelUI.panel.hasAttribute("noautohide"), "@noautohide on the menu panel should have been cleaned up");
-
-    is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed");
-
-    executeSoon(nextTest);
-  }
-
-  function nextTest() {
-    if (tests.length == 0) {
-      finish();
-      return;
-    }
-    let test = tests.shift();
-    info("Starting " + test.name);
-    loadTestPage(function() {
-      test(done);
-    });
-  }
-  nextTest();
+  UITourTest();
 }
 
 let tests = [
   function test_untrusted_host(done) {
-    loadTestPage(function() {
+    loadUITourTestPage(function() {
       let bookmarksMenu = document.getElementById("bookmarks-menu-button");
       ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed");
 
       gContentAPI.showMenu("bookmarks");
       ise(bookmarksMenu.open, false, "Bookmark menu should not open on a untrusted host");
 
       done();
     }, "http://mochi.test:8888/");
   },
   function test_unsecure_host(done) {
-    loadTestPage(function() {
+    loadUITourTestPage(function() {
       let bookmarksMenu = document.getElementById("bookmarks-menu-button");
       ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed");
 
       gContentAPI.showMenu("bookmarks");
       ise(bookmarksMenu.open, false, "Bookmark menu should not open on a unsecure host");
 
       done();
     }, "http://example.com/");
   },
   function test_unsecure_host_override(done) {
     Services.prefs.setBoolPref("browser.uitour.requireSecure", false);
-    loadTestPage(function() {
+    loadUITourTestPage(function() {
       let highlight = document.getElementById("UITourHighlight");
       is_element_hidden(highlight, "Highlight should initially be hidden");
 
       gContentAPI.showHighlight("urlbar");
       waitForElementToBeVisible(highlight, done, "Highlight should be shown on a unsecure host when override pref is set");
 
       Services.prefs.setBoolPref("browser.uitour.requireSecure", true);
     }, "http://example.com/");
--- a/browser/modules/test/browser_UITour2.js
+++ b/browser/modules/test/browser_UITour2.js
@@ -4,84 +4,18 @@
 "use strict";
 
 let gTestTab;
 let gContentAPI;
 let gContentWindow;
 
 Components.utils.import("resource:///modules/UITour.jsm");
 
-function loadTestPage(callback, host = "https://example.com/") {
-   if (gTestTab)
-    gBrowser.removeTab(gTestTab);
-
-  let url = getRootDirectory(gTestPath) + "uitour.html";
-  url = url.replace("chrome://mochitests/content/", host);
-
-  gTestTab = gBrowser.addTab(url);
-  gBrowser.selectedTab = gTestTab;
-
-  gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
-    gTestTab.linkedBrowser.removeEventListener("load", onLoad);
-
-    gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
-    gContentAPI = gContentWindow.Mozilla.UITour;
-
-    waitForFocus(callback, gContentWindow);
-  }, true);
-}
-
 function test() {
-  Services.prefs.setBoolPref("browser.uitour.enabled", true);
-  let testUri = Services.io.newURI("http://example.com", null, null);
-  Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
-
-  waitForExplicitFinish();
-
-  registerCleanupFunction(function() {
-    delete window.UITour;
-    delete window.gContentWindow;
-    delete window.gContentAPI;
-    if (gTestTab)
-      gBrowser.removeTab(gTestTab);
-    delete window.gTestTab;
-    Services.prefs.clearUserPref("browser.uitour.enabled", true);
-    Services.perms.remove("example.com", "uitour");
-  });
-
-  function done() {
-    if (gTestTab)
-      gBrowser.removeTab(gTestTab);
-    gTestTab = null;
-
-    let highlight = document.getElementById("UITourHighlightContainer");
-    is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed");
-
-    let tooltip = document.getElementById("UITourTooltip");
-    is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed");
-
-    ok(!PanelUI.panel.hasAttribute("noautohide"), "@noautohide on the menu panel should have been cleaned up");
-
-    is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed");
-
-    executeSoon(nextTest);
-  }
-
-  function nextTest() {
-    if (tests.length == 0) {
-      finish();
-      return;
-    }
-    let test = tests.shift();
-    info("Starting " + test.name);
-    loadTestPage(function() {
-      test(done);
-    });
-  }
-  nextTest();
+  UITourTest();
 }
 
 let tests = [
   function test_info_customize_auto_open_close(done) {
     let popup = document.getElementById("UITourTooltip");
     gContentAPI.showInfo("customize", "Customization", "Customize me please!");
     UITour.getTarget(window, "customize").then((customizeTarget) => {
       waitForPopupAtAnchor(popup, customizeTarget.node, function checkPanelIsOpen() {
--- a/browser/modules/test/browser_UITour3.js
+++ b/browser/modules/test/browser_UITour3.js
@@ -4,84 +4,18 @@
 "use strict";
 
 let gTestTab;
 let gContentAPI;
 let gContentWindow;
 
 Components.utils.import("resource:///modules/UITour.jsm");
 
-function loadTestPage(callback, host = "https://example.com/") {
-   if (gTestTab)
-    gBrowser.removeTab(gTestTab);
-
-  let url = getRootDirectory(gTestPath) + "uitour.html";
-  url = url.replace("chrome://mochitests/content/", host);
-
-  gTestTab = gBrowser.addTab(url);
-  gBrowser.selectedTab = gTestTab;
-
-  gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
-    gTestTab.linkedBrowser.removeEventListener("load", onLoad);
-
-    gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
-    gContentAPI = gContentWindow.Mozilla.UITour;
-
-    waitForFocus(callback, gContentWindow);
-  }, true);
-}
-
 function test() {
-  Services.prefs.setBoolPref("browser.uitour.enabled", true);
-  let testUri = Services.io.newURI("http://example.com", null, null);
-  Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
-
-  waitForExplicitFinish();
-
-  registerCleanupFunction(function() {
-    delete window.UITour;
-    delete window.gContentWindow;
-    delete window.gContentAPI;
-    if (gTestTab)
-      gBrowser.removeTab(gTestTab);
-    delete window.gTestTab;
-    Services.prefs.clearUserPref("browser.uitour.enabled", true);
-    Services.perms.remove("example.com", "uitour");
-  });
-
-  function done() {
-    if (gTestTab)
-      gBrowser.removeTab(gTestTab);
-    gTestTab = null;
-
-    let highlight = document.getElementById("UITourHighlightContainer");
-    is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed");
-
-    let tooltip = document.getElementById("UITourTooltip");
-    is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed");
-
-    ok(!PanelUI.panel.hasAttribute("noautohide"), "@noautohide on the menu panel should have been cleaned up");
-
-    is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed");
-
-    executeSoon(nextTest);
-  }
-
-  function nextTest() {
-    if (tests.length == 0) {
-      finish();
-      return;
-    }
-    let test = tests.shift();
-    info("Starting " + test.name);
-    loadTestPage(function() {
-      test(done);
-    });
-  }
-  nextTest();
+  UITourTest();
 }
 
 let tests = [
   function test_info_icon(done) {
     let popup = document.getElementById("UITourTooltip");
     let title = document.getElementById("UITourTooltipTitle");
     let desc = document.getElementById("UITourTooltipDescription");
     let icon = document.getElementById("UITourTooltipIcon");
--- a/browser/modules/test/browser_UITour_sync.js
+++ b/browser/modules/test/browser_UITour_sync.js
@@ -4,85 +4,21 @@
 "use strict";
 
 let gTestTab;
 let gContentAPI;
 let gContentWindow;
 
 Components.utils.import("resource:///modules/UITour.jsm");
 
-function loadTestPage(callback, host = "https://example.com/") {
-   if (gTestTab)
-    gBrowser.removeTab(gTestTab);
-
-  let url = getRootDirectory(gTestPath) + "uitour.html";
-  url = url.replace("chrome://mochitests/content/", host);
-
-  gTestTab = gBrowser.addTab(url);
-  gBrowser.selectedTab = gTestTab;
-
-  gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
-    gTestTab.linkedBrowser.removeEventListener("load", onLoad);
-
-    gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
-    gContentAPI = gContentWindow.Mozilla.UITour;
-
-    waitForFocus(callback, gContentWindow);
-  }, true);
-}
-
 function test() {
-  Services.prefs.setBoolPref("browser.uitour.enabled", true);
-  let testUri = Services.io.newURI("http://example.com", null, null);
-  Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
-
-  waitForExplicitFinish();
-
   registerCleanupFunction(function() {
-    delete window.UITour;
-    delete window.gContentWindow;
-    delete window.gContentAPI;
-    if (gTestTab)
-      gBrowser.removeTab(gTestTab);
-    delete window.gTestTab;
-    Services.prefs.clearUserPref("browser.uitour.enabled", true);
     Services.prefs.clearUserPref("services.sync.username");
-    Services.perms.remove("example.com", "uitour");
   });
-
-  function done() {
-    executeSoon(() => {
-      if (gTestTab)
-        gBrowser.removeTab(gTestTab);
-      gTestTab = null;
-
-      let highlight = document.getElementById("UITourHighlightContainer");
-      is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed");
-
-      let tooltip = document.getElementById("UITourTooltip");
-      is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed");
-
-      is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed");
-
-      executeSoon(nextTest);
-    });
-  }
-
-  function nextTest() {
-    if (tests.length == 0) {
-      finish();
-      return;
-    }
-    let test = tests.shift();
-    info("Starting " + test.name);
-    loadTestPage(function() {
-      test(done);
-    });
-  }
-  nextTest();
+  UITourTest();
 }
 
 let tests = [
   function test_checkSyncSetup_disabled(done) {
     function callback(result) {
       is(result.setup, false, "Sync shouldn't be setup by default");
       done();
     }
--- a/browser/modules/test/head.js
+++ b/browser/modules/test/head.js
@@ -62,8 +62,80 @@ function waitForPopupAtAnchor(popup, anc
                    },
                    "Timeout waiting for popup at anchor: " + msg);
 }
 
 function is_element_hidden(element, msg) {
   isnot(element, null, "Element should not be null, when checking visibility");
   ok(is_hidden(element), msg);
 }
+
+function loadUITourTestPage(callback, host = "https://example.com/") {
+   if (gTestTab)
+    gBrowser.removeTab(gTestTab);
+
+  let url = getRootDirectory(gTestPath) + "uitour.html";
+  url = url.replace("chrome://mochitests/content/", host);
+
+  gTestTab = gBrowser.addTab(url);
+  gBrowser.selectedTab = gTestTab;
+
+  gTestTab.linkedBrowser.addEventListener("load", function onLoad() {
+    gTestTab.linkedBrowser.removeEventListener("load", onLoad);
+
+    gContentWindow = Components.utils.waiveXrays(gTestTab.linkedBrowser.contentDocument.defaultView);
+    gContentAPI = gContentWindow.Mozilla.UITour;
+
+    waitForFocus(callback, gContentWindow);
+  }, true);
+}
+
+function UITourTest() {
+  Services.prefs.setBoolPref("browser.uitour.enabled", true);
+  let testUri = Services.io.newURI("http://example.com", null, null);
+  Services.perms.add(testUri, "uitour", Services.perms.ALLOW_ACTION);
+
+  waitForExplicitFinish();
+
+  registerCleanupFunction(function() {
+    delete window.UITour;
+    delete window.gContentWindow;
+    delete window.gContentAPI;
+    if (gTestTab)
+      gBrowser.removeTab(gTestTab);
+    delete window.gTestTab;
+    Services.prefs.clearUserPref("browser.uitour.enabled", true);
+    Services.perms.remove("example.com", "uitour");
+  });
+
+  function done() {
+    executeSoon(() => {
+      if (gTestTab)
+        gBrowser.removeTab(gTestTab);
+      gTestTab = null;
+
+      let highlight = document.getElementById("UITourHighlightContainer");
+      is_element_hidden(highlight, "Highlight should be closed/hidden after UITour tab is closed");
+
+      let tooltip = document.getElementById("UITourTooltip");
+      is_element_hidden(tooltip, "Tooltip should be closed/hidden after UITour tab is closed");
+
+      ok(!PanelUI.panel.hasAttribute("noautohide"), "@noautohide on the menu panel should have been cleaned up");
+
+      is(UITour.pinnedTabs.get(window), null, "Any pinned tab should be closed after UITour tab is closed");
+
+      executeSoon(nextTest);
+    });
+  }
+
+  function nextTest() {
+    if (tests.length == 0) {
+      finish();
+      return;
+    }
+    let test = tests.shift();
+    info("Starting " + test.name);
+    loadUITourTestPage(function() {
+      test(done);
+    });
+  }
+  nextTest();
+}