|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests various aspects of the details view |
|
6 |
|
7 var gManagerWindow; |
|
8 var gCategoryUtilities; |
|
9 var gProvider; |
|
10 |
|
11 function test() { |
|
12 waitForExplicitFinish(); |
|
13 |
|
14 gProvider = new MockProvider(); |
|
15 |
|
16 gProvider.createAddons([{ |
|
17 id: "tabsettings@tests.mozilla.org", |
|
18 name: "Tab Settings", |
|
19 version: "1", |
|
20 optionsURL: CHROMEROOT + "addon_prefs.xul", |
|
21 optionsType: AddonManager.OPTIONS_TYPE_TAB |
|
22 }]); |
|
23 |
|
24 open_manager("addons://list/extension", function(aWindow) { |
|
25 gManagerWindow = aWindow; |
|
26 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
27 |
|
28 run_next_test(); |
|
29 }); |
|
30 } |
|
31 |
|
32 function end_test() { |
|
33 close_manager(gManagerWindow, function() { |
|
34 finish(); |
|
35 }); |
|
36 } |
|
37 |
|
38 add_test(function() { |
|
39 var addon = get_addon_element(gManagerWindow, "tabsettings@tests.mozilla.org"); |
|
40 is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_TAB, "Options should be inline type"); |
|
41 addon.parentNode.ensureElementIsVisible(addon); |
|
42 |
|
43 var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); |
|
44 is_element_visible(button, "Preferences button should be visible"); |
|
45 |
|
46 if (gUseInContentUI) { |
|
47 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); |
|
48 |
|
49 var browser = gBrowser.selectedTab.linkedBrowser; |
|
50 browser.addEventListener("DOMContentLoaded", function() { |
|
51 browser.removeEventListener("DOMContentLoaded", arguments.callee, false); |
|
52 is(browser.currentURI.spec, addon.mAddon.optionsURL, "New tab should have loaded the options URL"); |
|
53 browser.contentWindow.close(); |
|
54 run_next_test(); |
|
55 }, false); |
|
56 return; |
|
57 } |
|
58 |
|
59 let instantApply = Services.prefs.getBoolPref("browser.preferences.instantApply"); |
|
60 |
|
61 function observer(aSubject, aTopic, aData) { |
|
62 switch (aTopic) { |
|
63 case "domwindowclosed": |
|
64 // Give the preference window a chance to finish closing before |
|
65 // closing the add-ons manager. |
|
66 waitForFocus(function () { |
|
67 Services.ww.unregisterNotification(observer); |
|
68 run_next_test(); |
|
69 }); |
|
70 break; |
|
71 case "domwindowopened": |
|
72 let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); |
|
73 waitForFocus(function () { |
|
74 // If the openDialog privileges are wrong a new browser window |
|
75 // will open, let the test proceed (and fail) rather than timeout. |
|
76 if (win.location != addon.mAddon.optionsURL && |
|
77 win.location != "chrome://browser/content/browser.xul") |
|
78 return; |
|
79 |
|
80 is(win.location, addon.mAddon.optionsURL, |
|
81 "The correct addon pref window should have opened"); |
|
82 |
|
83 let chromeFlags = win.QueryInterface(Ci.nsIInterfaceRequestor). |
|
84 getInterface(Ci.nsIWebNavigation). |
|
85 QueryInterface(Ci.nsIDocShellTreeItem).treeOwner. |
|
86 QueryInterface(Ci.nsIInterfaceRequestor). |
|
87 getInterface(Ci.nsIXULWindow).chromeFlags; |
|
88 ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME && |
|
89 (instantApply || chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG), |
|
90 "Window was open as a chrome dialog."); |
|
91 |
|
92 win.close(); |
|
93 }, win); |
|
94 break; |
|
95 } |
|
96 } |
|
97 |
|
98 Services.ww.registerNotification(observer); |
|
99 EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); |
|
100 }); |