1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_tabsettings.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 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 various aspects of the details view 1.9 + 1.10 +var gManagerWindow; 1.11 +var gCategoryUtilities; 1.12 +var gProvider; 1.13 + 1.14 +function test() { 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + gProvider = new MockProvider(); 1.18 + 1.19 + gProvider.createAddons([{ 1.20 + id: "tabsettings@tests.mozilla.org", 1.21 + name: "Tab Settings", 1.22 + version: "1", 1.23 + optionsURL: CHROMEROOT + "addon_prefs.xul", 1.24 + optionsType: AddonManager.OPTIONS_TYPE_TAB 1.25 + }]); 1.26 + 1.27 + open_manager("addons://list/extension", function(aWindow) { 1.28 + gManagerWindow = aWindow; 1.29 + gCategoryUtilities = new CategoryUtilities(gManagerWindow); 1.30 + 1.31 + run_next_test(); 1.32 + }); 1.33 +} 1.34 + 1.35 +function end_test() { 1.36 + close_manager(gManagerWindow, function() { 1.37 + finish(); 1.38 + }); 1.39 +} 1.40 + 1.41 +add_test(function() { 1.42 + var addon = get_addon_element(gManagerWindow, "tabsettings@tests.mozilla.org"); 1.43 + is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_TAB, "Options should be inline type"); 1.44 + addon.parentNode.ensureElementIsVisible(addon); 1.45 + 1.46 + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); 1.47 + is_element_visible(button, "Preferences button should be visible"); 1.48 + 1.49 + if (gUseInContentUI) { 1.50 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.51 + 1.52 + var browser = gBrowser.selectedTab.linkedBrowser; 1.53 + browser.addEventListener("DOMContentLoaded", function() { 1.54 + browser.removeEventListener("DOMContentLoaded", arguments.callee, false); 1.55 + is(browser.currentURI.spec, addon.mAddon.optionsURL, "New tab should have loaded the options URL"); 1.56 + browser.contentWindow.close(); 1.57 + run_next_test(); 1.58 + }, false); 1.59 + return; 1.60 + } 1.61 + 1.62 + let instantApply = Services.prefs.getBoolPref("browser.preferences.instantApply"); 1.63 + 1.64 + function observer(aSubject, aTopic, aData) { 1.65 + switch (aTopic) { 1.66 + case "domwindowclosed": 1.67 + // Give the preference window a chance to finish closing before 1.68 + // closing the add-ons manager. 1.69 + waitForFocus(function () { 1.70 + Services.ww.unregisterNotification(observer); 1.71 + run_next_test(); 1.72 + }); 1.73 + break; 1.74 + case "domwindowopened": 1.75 + let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); 1.76 + waitForFocus(function () { 1.77 + // If the openDialog privileges are wrong a new browser window 1.78 + // will open, let the test proceed (and fail) rather than timeout. 1.79 + if (win.location != addon.mAddon.optionsURL && 1.80 + win.location != "chrome://browser/content/browser.xul") 1.81 + return; 1.82 + 1.83 + is(win.location, addon.mAddon.optionsURL, 1.84 + "The correct addon pref window should have opened"); 1.85 + 1.86 + let chromeFlags = win.QueryInterface(Ci.nsIInterfaceRequestor). 1.87 + getInterface(Ci.nsIWebNavigation). 1.88 + QueryInterface(Ci.nsIDocShellTreeItem).treeOwner. 1.89 + QueryInterface(Ci.nsIInterfaceRequestor). 1.90 + getInterface(Ci.nsIXULWindow).chromeFlags; 1.91 + ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME && 1.92 + (instantApply || chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG), 1.93 + "Window was open as a chrome dialog."); 1.94 + 1.95 + win.close(); 1.96 + }, win); 1.97 + break; 1.98 + } 1.99 + } 1.100 + 1.101 + Services.ww.registerNotification(observer); 1.102 + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); 1.103 +});