Bug 605499: Tests for showing EULA for extension installs. r=Unfocused, a=tests
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 22 Oct 2010 10:33:03 -0700
changeset 56367 28675757affa258fc2396153d2cf67f7e865ec35
parent 56366 9b7e1b761cb7e23e8ff46708cbd37031f149de51
child 56368 824f0cefa25d1460a7c8b4c63de015b8733ab359
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersUnfocused, tests
bugs605499
milestone2.0b8pre
Bug 605499: Tests for showing EULA for extension installs. r=Unfocused, a=tests
toolkit/mozapps/extensions/test/browser/Makefile.in
toolkit/mozapps/extensions/test/browser/browser_bug557956.js
toolkit/mozapps/extensions/test/browser/browser_bug581076.js
toolkit/mozapps/extensions/test/browser/browser_bug596336.js
toolkit/mozapps/extensions/test/browser/browser_eula.js
toolkit/mozapps/extensions/test/browser/browser_eula.xml
toolkit/mozapps/extensions/test/browser/browser_install.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/test/browser/Makefile.in
+++ b/toolkit/mozapps/extensions/test/browser/Makefile.in
@@ -79,16 +79,18 @@ include $(DEPTH)/config/autoconf.mk
   browser_install.js \
   browser_install.rdf \
   browser_install.xml \
   browser_install1_3.xpi \
   browser_installssl.js \
   browser_recentupdates.js \
   browser_manualupdates.js \
   browser_globalwarnings.js \
+  browser_eula.js \
+  browser_eula.xml \
   redirect.sjs \
   releaseNotes.xhtml \
   $(NULL)
 
 # Disabled browser_bug586574.js due to bug 596174
 
 include $(topsrcdir)/config/rules.mk
 
--- a/toolkit/mozapps/extensions/test/browser/browser_bug557956.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug557956.js
@@ -27,17 +27,24 @@ function test() {
   waitForExplicitFinish();
 
   run_next_test();
 }
 
 function end_test() {
   Services.prefs.clearUserPref("extensions.update.url");
 
-  finish();
+  // Test generates a lot of available installs so just cancel them all
+  AddonManager.getAllInstalls(function(aInstalls) {
+    aInstalls.forEach(function(aInstall) {
+      aInstall.cancel();
+    });
+
+    finish();
+  });
 }
 
 function install_test_addons(aCallback) {
   var installs = [];
 
   // Use a blank update URL
   Services.prefs.setCharPref("extensions.update.url", TESTROOT + "missing.rdf");
 
--- a/toolkit/mozapps/extensions/test/browser/browser_bug581076.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug581076.js
@@ -23,17 +23,25 @@ function test() {
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
     run_next_test();
   });
 }
 
 function end_test() {
   Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
-  close_manager(gManagerWindow, finish);
+
+  // Test generates a lot of available installs so just cancel them all
+  AddonManager.getAllInstalls(function(aInstalls) {
+    aInstalls.forEach(function(aInstall) {
+      aInstall.cancel();
+    });
+
+    close_manager(gManagerWindow, finish);
+  });
 }
 
 function search(aRemoteSearch, aCallback) {
   var searchBox = gManagerWindow.document.getElementById("header-search");
   searchBox.value = SEARCH_QUERY;
 
   EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
   EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
--- a/toolkit/mozapps/extensions/test/browser/browser_bug596336.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug596336.js
@@ -14,18 +14,22 @@ function test() {
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
     gCategoryUtilities = new CategoryUtilities(gManagerWindow);
     run_next_test();
   });
 }
 
 function end_test() {
-  close_manager(gManagerWindow, function() {
-    finish();
+  // Test generates an available installs so just cancel it
+  AddonManager.getAllInstalls(function(aInstalls) {
+    is(aInstalls.length, 1, "Should be one available install");
+    aInstalls[0].cancel();
+
+    close_manager(gManagerWindow, finish);
   });
 }
 
 function get_list_item_count() {
   return get_test_items_in_list(gManagerWindow).length;
 }
 
 function get_node(parent, anonid) {
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_eula.js
@@ -0,0 +1,89 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Tests that the eula is shown correctly for search results
+
+var gManagerWindow;
+var gCategoryUtilities;
+
+var gApp = document.getElementById("bundle_brand").getString("brandShortName");
+var gSearchCount = 0;
+
+function test() {
+  requestLongerTimeout(2);
+  waitForExplicitFinish();
+
+  // Turn on searching for this test
+  Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
+  Services.prefs.setCharPref("extensions.getAddons.search.url", TESTROOT + "browser_eula.xml");
+
+  open_manager(null, function(aWindow) {
+    gManagerWindow = aWindow;
+    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
+    run_next_test();
+  });
+}
+
+function end_test() {
+  close_manager(gManagerWindow, function() {
+    Services.prefs.clearUserPref("extensions.getAddons.search.url");
+
+    finish();
+  });
+}
+
+function get_node(parent, anonid) {
+  return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
+}
+
+function installSearchResult(aCallback) {
+  var searchBox = gManagerWindow.document.getElementById("header-search");
+  // Search for something different each time
+  searchBox.value = "foo" + gSearchCount;
+  gSearchCount++;
+
+  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
+  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
+
+  wait_for_view_load(gManagerWindow, function() {
+    let remote = gManagerWindow.document.getElementById("search-filter-remote")
+    EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow);
+
+    let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
+    ok(!!item, "Should see the search result in the list");
+
+    let status = get_node(item, "install-status");
+    EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow);
+
+    item.mInstall.addListener({
+      onInstallEnded: function() {
+        executeSoon(aCallback);
+      }
+    });
+  });
+}
+
+// Install an add-on through the search page, accept the EULA and then undo it
+add_test(function() {
+  // Accept the EULA when it appears
+  let sawEULA = false;
+  wait_for_window_open(function(aWindow) {
+    sawEULA = true;
+    is(aWindow.location.href, "chrome://mozapps/content/extensions/eula.xul", "Window opened should be correct");
+    is(aWindow.document.getElementById("eula").value, "This is the EULA for this add-on", "EULA should be correct");
+
+    aWindow.document.documentElement.acceptDialog();
+  });
+
+  installSearchResult(function() {
+    ok(sawEULA, "Should have seen the EULA");
+
+    AddonManager.getAllInstalls(function(aInstalls) {
+      is(aInstalls.length, 1, "Should be one pending install");
+      aInstalls[0].cancel();
+
+      run_next_test();
+    });
+  });
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/browser/browser_eula.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<searchresults total_results="1">
+  <addon>
+    <name>Install Tests</name>
+    <type id='1'>Extension</type>
+    <guid>addon1@tests.mozilla.org</guid>
+    <version>1.0</version>
+    <authors>
+      <author>
+        <name>Test Creator</name>
+        <link>http://example.com/creator.html</link>
+      </author>
+    </authors>
+    <status id='4'>Public</status>
+    <summary>Test add-on</summary>
+    <description>Test add-on</description>
+    <eula>This is the EULA for this add-on</eula>
+    <compatible_applications>
+      <application>
+        <name>Firefox</name>
+        <appID>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</appID>
+        <min_version>0</min_version>
+        <max_version>*</max_version>
+      </application>
+      <application>
+        <name>SeaMonkey</name>
+        <appID>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</appID>
+        <min_version>0</min_version>
+        <max_version>*</max_version>
+      </application>
+    </compatible_applications>
+    <compatible_os>ALL</compatible_os>
+    <install size="2">http://example.com/browser/toolkit/mozapps/extensions/test/browser/addons/browser_install1_2.xpi</install>
+  </addon>
+</searchresults>
--- a/toolkit/mozapps/extensions/test/browser/browser_install.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_install.js
@@ -29,18 +29,18 @@ function test() {
 
 function end_test() {
   close_manager(gManagerWindow, function() {
     Services.prefs.clearUserPref("extensions.getAddons.search.url");
     Services.prefs.clearUserPref("extensions.checkUpdateSecurity");
 
     AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
       aAddon.uninstall();
+      finish();
     });
-    finish();
   });
 }
 
 function get_node(parent, anonid) {
   return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
 }
 
 function installAddon(aCallback) {
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -36,16 +36,28 @@ Services.prefs.setBoolPref(PREF_LOGGING_
 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 0);
 registerCleanupFunction(function() {
   Services.prefs.clearUserPref(PREF_LOGGING_ENABLED);
   try {
     Services.prefs.clearUserPref(PREF_SEARCH_MAXRESULTS);
   }
   catch (e) {
   }
+
+  // We can for now know that getAllInstalls actually calls its callback before
+  // it returns so this will complete before the next test start.
+  AddonManager.getAllInstalls(function(aInstalls) {
+    aInstalls.forEach(function(aInstall) {
+      if (aInstall instanceof MockInstall)
+        return;
+
+      ok(false, "Should not have seen an install of " + aInstall.sourceURI.spec + " in state " + aInstall.state);
+      aInstall.cancel();
+    });
+  });
 });
 
 function add_test(test) {
   gPendingTests.push(test);
 }
 
 function run_next_test() {
   if (gTestsRun > 0)
@@ -227,16 +239,39 @@ function restart_manager(aManagerWindow,
     return;
   }
 
   close_manager(aManagerWindow, function() {
     open_manager(aView, aCallback, aLoadCallback);
   });
 }
 
+function wait_for_window_open(aCallback) {
+  Services.wm.addListener({
+    onOpenWindow: function(aWindow) {
+      Services.wm.removeListener(this);
+
+      let domwindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIDOMWindowInternal);
+      domwindow.addEventListener("load", function() {
+        domwindow.removeEventListener("load", arguments.callee, false);
+        executeSoon(function() {
+          aCallback(domwindow);
+        });
+      }, false);
+    },
+
+    onCloseWindow: function(aWindow) {
+    },
+
+    onWindowTitleChange: function(aWindow, aTitle) {
+    }
+  });
+}
+
 function is_hidden(aElement) {
   var style = aElement.ownerDocument.defaultView.getComputedStyle(aElement, "");
   if (style.display == "none")
     return true;
   if (style.visibility != "visible")
     return true;
 
   // Hiding a parent element will hide all its children