toolkit/mozapps/extensions/test/browser/browser_eula.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_eula.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +// Tests that the eula is shown correctly for search results
     1.9 +
    1.10 +var gManagerWindow;
    1.11 +var gCategoryUtilities;
    1.12 +
    1.13 +var gApp = document.getElementById("bundle_brand").getString("brandShortName");
    1.14 +var gSearchCount = 0;
    1.15 +
    1.16 +function test() {
    1.17 +  requestLongerTimeout(2);
    1.18 +  waitForExplicitFinish();
    1.19 +
    1.20 +  // Turn on searching for this test
    1.21 +  Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
    1.22 +  Services.prefs.setCharPref("extensions.getAddons.search.url", TESTROOT + "browser_eula.xml");
    1.23 +
    1.24 +  open_manager(null, function(aWindow) {
    1.25 +    gManagerWindow = aWindow;
    1.26 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    1.27 +    run_next_test();
    1.28 +  });
    1.29 +}
    1.30 +
    1.31 +function end_test() {
    1.32 +  close_manager(gManagerWindow, finish);
    1.33 +}
    1.34 +
    1.35 +function get_node(parent, anonid) {
    1.36 +  return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
    1.37 +}
    1.38 +
    1.39 +function installSearchResult(aCallback) {
    1.40 +  var searchBox = gManagerWindow.document.getElementById("header-search");
    1.41 +  // Search for something different each time
    1.42 +  searchBox.value = "foo" + gSearchCount;
    1.43 +  gSearchCount++;
    1.44 +
    1.45 +  EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
    1.46 +  EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
    1.47 +
    1.48 +  wait_for_view_load(gManagerWindow, function() {
    1.49 +    let remote = gManagerWindow.document.getElementById("search-filter-remote")
    1.50 +    EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow);
    1.51 +
    1.52 +    let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
    1.53 +    ok(!!item, "Should see the search result in the list");
    1.54 +
    1.55 +    let status = get_node(item, "install-status");
    1.56 +    EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow);
    1.57 +
    1.58 +    item.mInstall.addListener({
    1.59 +      onInstallEnded: function() {
    1.60 +        executeSoon(aCallback);
    1.61 +      }
    1.62 +    });
    1.63 +  });
    1.64 +}
    1.65 +
    1.66 +// Install an add-on through the search page, accept the EULA and then undo it
    1.67 +add_test(function() {
    1.68 +  // Accept the EULA when it appears
    1.69 +  let sawEULA = false;
    1.70 +  wait_for_window_open(function(aWindow) {
    1.71 +    sawEULA = true;
    1.72 +    is(aWindow.location.href, "chrome://mozapps/content/extensions/eula.xul", "Window opened should be correct");
    1.73 +    is(aWindow.document.getElementById("eula").value, "This is the EULA for this add-on", "EULA should be correct");
    1.74 +
    1.75 +    aWindow.document.documentElement.acceptDialog();
    1.76 +  });
    1.77 +
    1.78 +  installSearchResult(function() {
    1.79 +    ok(sawEULA, "Should have seen the EULA");
    1.80 +
    1.81 +    AddonManager.getAllInstalls(function(aInstalls) {
    1.82 +      is(aInstalls.length, 1, "Should be one pending install");
    1.83 +      aInstalls[0].cancel();
    1.84 +
    1.85 +      run_next_test();
    1.86 +    });
    1.87 +  });
    1.88 +});

mercurial