|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that the eula is shown correctly for search results |
|
6 |
|
7 var gManagerWindow; |
|
8 var gCategoryUtilities; |
|
9 |
|
10 var gApp = document.getElementById("bundle_brand").getString("brandShortName"); |
|
11 var gSearchCount = 0; |
|
12 |
|
13 function test() { |
|
14 requestLongerTimeout(2); |
|
15 waitForExplicitFinish(); |
|
16 |
|
17 // Turn on searching for this test |
|
18 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15); |
|
19 Services.prefs.setCharPref("extensions.getAddons.search.url", TESTROOT + "browser_eula.xml"); |
|
20 |
|
21 open_manager(null, function(aWindow) { |
|
22 gManagerWindow = aWindow; |
|
23 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
24 run_next_test(); |
|
25 }); |
|
26 } |
|
27 |
|
28 function end_test() { |
|
29 close_manager(gManagerWindow, finish); |
|
30 } |
|
31 |
|
32 function get_node(parent, anonid) { |
|
33 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); |
|
34 } |
|
35 |
|
36 function installSearchResult(aCallback) { |
|
37 var searchBox = gManagerWindow.document.getElementById("header-search"); |
|
38 // Search for something different each time |
|
39 searchBox.value = "foo" + gSearchCount; |
|
40 gSearchCount++; |
|
41 |
|
42 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
|
43 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
|
44 |
|
45 wait_for_view_load(gManagerWindow, function() { |
|
46 let remote = gManagerWindow.document.getElementById("search-filter-remote") |
|
47 EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow); |
|
48 |
|
49 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
|
50 ok(!!item, "Should see the search result in the list"); |
|
51 |
|
52 let status = get_node(item, "install-status"); |
|
53 EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow); |
|
54 |
|
55 item.mInstall.addListener({ |
|
56 onInstallEnded: function() { |
|
57 executeSoon(aCallback); |
|
58 } |
|
59 }); |
|
60 }); |
|
61 } |
|
62 |
|
63 // Install an add-on through the search page, accept the EULA and then undo it |
|
64 add_test(function() { |
|
65 // Accept the EULA when it appears |
|
66 let sawEULA = false; |
|
67 wait_for_window_open(function(aWindow) { |
|
68 sawEULA = true; |
|
69 is(aWindow.location.href, "chrome://mozapps/content/extensions/eula.xul", "Window opened should be correct"); |
|
70 is(aWindow.document.getElementById("eula").value, "This is the EULA for this add-on", "EULA should be correct"); |
|
71 |
|
72 aWindow.document.documentElement.acceptDialog(); |
|
73 }); |
|
74 |
|
75 installSearchResult(function() { |
|
76 ok(sawEULA, "Should have seen the EULA"); |
|
77 |
|
78 AddonManager.getAllInstalls(function(aInstalls) { |
|
79 is(aInstalls.length, 1, "Should be one pending install"); |
|
80 aInstalls[0].cancel(); |
|
81 |
|
82 run_next_test(); |
|
83 }); |
|
84 }); |
|
85 }); |