Wed, 31 Dec 2014 06:09:35 +0100
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 the dialog open by the Options button for addons that provide a |
michael@0 | 6 | // custom chrome-like protocol for optionsURL. |
michael@0 | 7 | |
michael@0 | 8 | let CustomChromeProtocol = { |
michael@0 | 9 | scheme: "khrome", |
michael@0 | 10 | defaultPort: -1, |
michael@0 | 11 | protocolFlags: Ci.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD | |
michael@0 | 12 | Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE | |
michael@0 | 13 | Ci.nsIProtocolHandler.URI_NORELATIVE | |
michael@0 | 14 | Ci.nsIProtocolHandler.URI_NOAUTH, |
michael@0 | 15 | |
michael@0 | 16 | newURI: function CCP_newURI(aSpec, aOriginCharset, aBaseUri) { |
michael@0 | 17 | let uri = Cc["@mozilla.org/network/simple-uri;1"]. |
michael@0 | 18 | createInstance(Ci.nsIURI); |
michael@0 | 19 | uri.spec = aSpec; |
michael@0 | 20 | return uri; |
michael@0 | 21 | }, |
michael@0 | 22 | |
michael@0 | 23 | newChannel: function CCP_newChannel(aURI) { |
michael@0 | 24 | let url = "chrome:" + aURI.path; |
michael@0 | 25 | let ch = NetUtil.newChannel(url); |
michael@0 | 26 | ch.originalURI = aURI; |
michael@0 | 27 | return ch; |
michael@0 | 28 | }, |
michael@0 | 29 | |
michael@0 | 30 | allowPort: function CCP_allowPort(aPort, aScheme) { |
michael@0 | 31 | return false; |
michael@0 | 32 | }, |
michael@0 | 33 | |
michael@0 | 34 | QueryInterface: XPCOMUtils.generateQI([ |
michael@0 | 35 | Ci.nsIProtocolHandler |
michael@0 | 36 | ]), |
michael@0 | 37 | |
michael@0 | 38 | classID: Components.ID("{399cb2d1-05dd-4363-896f-63b78e008cf8}"), |
michael@0 | 39 | |
michael@0 | 40 | factory: { |
michael@0 | 41 | registrar: Components.manager.QueryInterface(Ci.nsIComponentRegistrar), |
michael@0 | 42 | |
michael@0 | 43 | register: function CCP_register() { |
michael@0 | 44 | this.registrar.registerFactory( |
michael@0 | 45 | CustomChromeProtocol.classID, |
michael@0 | 46 | "CustomChromeProtocol", |
michael@0 | 47 | "@mozilla.org/network/protocol;1?name=khrome", |
michael@0 | 48 | this |
michael@0 | 49 | ); |
michael@0 | 50 | }, |
michael@0 | 51 | |
michael@0 | 52 | unregister: function CCP_register() { |
michael@0 | 53 | this.registrar.unregisterFactory(CustomChromeProtocol.classID, this); |
michael@0 | 54 | }, |
michael@0 | 55 | |
michael@0 | 56 | // nsIFactory |
michael@0 | 57 | createInstance: function BNPH_createInstance(aOuter, aIID) { |
michael@0 | 58 | if (aOuter) { |
michael@0 | 59 | throw Components.Exception("Class does not allow aggregation", |
michael@0 | 60 | Components.results.NS_ERROR_NO_AGGREGATION); |
michael@0 | 61 | } |
michael@0 | 62 | return CustomChromeProtocol.QueryInterface(aIID); |
michael@0 | 63 | }, |
michael@0 | 64 | |
michael@0 | 65 | lockFactory: function BNPH_lockFactory(aLock) { |
michael@0 | 66 | throw Components.Exception("Function lockFactory is not implemented", |
michael@0 | 67 | Components.results.NS_ERROR_NOT_IMPLEMENTED); |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | QueryInterface: XPCOMUtils.generateQI([ |
michael@0 | 71 | Ci.nsIFactory |
michael@0 | 72 | ]) |
michael@0 | 73 | } |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function test() { |
michael@0 | 77 | waitForExplicitFinish(); |
michael@0 | 78 | requestLongerTimeout(2); |
michael@0 | 79 | |
michael@0 | 80 | info("Registering custom chrome-like protocol."); |
michael@0 | 81 | CustomChromeProtocol.factory.register(); |
michael@0 | 82 | registerCleanupFunction(function () CustomChromeProtocol.factory.unregister()); |
michael@0 | 83 | |
michael@0 | 84 | const ADDONS_LIST = [ |
michael@0 | 85 | { id: "test1@tests.mozilla.org", |
michael@0 | 86 | name: "Test add-on 1", |
michael@0 | 87 | optionsURL: CHROMEROOT + "addon_prefs.xul" }, |
michael@0 | 88 | { id: "test2@tests.mozilla.org", |
michael@0 | 89 | name: "Test add-on 2", |
michael@0 | 90 | optionsURL: (CHROMEROOT + "addon_prefs.xul").replace("chrome:", "khrome:") }, |
michael@0 | 91 | ]; |
michael@0 | 92 | |
michael@0 | 93 | var gProvider = new MockProvider(); |
michael@0 | 94 | gProvider.createAddons(ADDONS_LIST); |
michael@0 | 95 | |
michael@0 | 96 | open_manager("addons://list/extension", function(aManager) { |
michael@0 | 97 | let addonList = aManager.document.getElementById("addon-list"); |
michael@0 | 98 | let currentAddon; |
michael@0 | 99 | let instantApply = Services.prefs.getBoolPref("browser.preferences.instantApply"); |
michael@0 | 100 | |
michael@0 | 101 | function getAddonByName(aName) { |
michael@0 | 102 | for (let addonItem of addonList.childNodes) { |
michael@0 | 103 | if (addonItem.hasAttribute("name") && |
michael@0 | 104 | addonItem.getAttribute("name") == aName) |
michael@0 | 105 | return addonItem; |
michael@0 | 106 | } |
michael@0 | 107 | return null; |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function observer(aSubject, aTopic, aData) { |
michael@0 | 111 | switch (aTopic) { |
michael@0 | 112 | case "domwindowclosed": |
michael@0 | 113 | // Give the preference window a chance to finish closing before |
michael@0 | 114 | // closing the add-ons manager. |
michael@0 | 115 | waitForFocus(function () { |
michael@0 | 116 | test_next_addon(); |
michael@0 | 117 | }); |
michael@0 | 118 | break; |
michael@0 | 119 | case "domwindowopened": |
michael@0 | 120 | let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); |
michael@0 | 121 | waitForFocus(function () { |
michael@0 | 122 | // If the openDialog privileges are wrong a new browser window |
michael@0 | 123 | // will open, let the test proceed (and fail) rather than timeout. |
michael@0 | 124 | if (win.location != currentAddon.optionsURL && |
michael@0 | 125 | win.location != "chrome://browser/content/browser.xul") |
michael@0 | 126 | return; |
michael@0 | 127 | |
michael@0 | 128 | is(win.location, currentAddon.optionsURL, |
michael@0 | 129 | "The correct addon pref window should have opened"); |
michael@0 | 130 | |
michael@0 | 131 | let chromeFlags = win.QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 132 | getInterface(Ci.nsIWebNavigation). |
michael@0 | 133 | QueryInterface(Ci.nsIDocShellTreeItem).treeOwner. |
michael@0 | 134 | QueryInterface(Ci.nsIInterfaceRequestor). |
michael@0 | 135 | getInterface(Ci.nsIXULWindow).chromeFlags; |
michael@0 | 136 | ok(chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_CHROME && |
michael@0 | 137 | (instantApply || chromeFlags & Ci.nsIWebBrowserChrome.CHROME_OPENAS_DIALOG), |
michael@0 | 138 | "Window was open as a chrome dialog."); |
michael@0 | 139 | |
michael@0 | 140 | win.close(); |
michael@0 | 141 | }, win); |
michael@0 | 142 | break; |
michael@0 | 143 | } |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | function test_next_addon() { |
michael@0 | 147 | currentAddon = ADDONS_LIST.shift(); |
michael@0 | 148 | if (!currentAddon) { |
michael@0 | 149 | Services.ww.unregisterNotification(observer); |
michael@0 | 150 | close_manager(aManager, finish); |
michael@0 | 151 | return; |
michael@0 | 152 | } |
michael@0 | 153 | |
michael@0 | 154 | info("Testing " + currentAddon.name); |
michael@0 | 155 | let addonItem = getAddonByName(currentAddon.name, addonList); |
michael@0 | 156 | let optionsBtn = |
michael@0 | 157 | aManager.document.getAnonymousElementByAttribute(addonItem, "anonid", |
michael@0 | 158 | "preferences-btn"); |
michael@0 | 159 | is(optionsBtn.hidden, false, "Prefs button should be visible.") |
michael@0 | 160 | |
michael@0 | 161 | addonList.ensureElementIsVisible(addonItem); |
michael@0 | 162 | EventUtils.synthesizeMouseAtCenter(optionsBtn, { }, aManager); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | Services.ww.registerNotification(observer); |
michael@0 | 166 | test_next_addon(); |
michael@0 | 167 | }); |
michael@0 | 168 | |
michael@0 | 169 | } |