From deea787c2efbb9c89caec8d9efc023ffafe75613 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Sat, 10 Feb 2018 04:00:58 -0500 Subject: Import Tycho's Add-on Manager --- .../extensions/test/browser/browser_eula.js | 85 ++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 toolkit/mozapps/extensions/test/browser/browser_eula.js (limited to 'toolkit/mozapps/extensions/test/browser/browser_eula.js') diff --git a/toolkit/mozapps/extensions/test/browser/browser_eula.js b/toolkit/mozapps/extensions/test/browser/browser_eula.js new file mode 100644 index 000000000..befe9f1f2 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_eula.js @@ -0,0 +1,85 @@ +/* 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, 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(); + }); + }); +}); -- cgit v1.2.3