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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial