Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | // a place for miscellaneous social tests |
michael@0 | 6 | |
michael@0 | 7 | let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; |
michael@0 | 8 | |
michael@0 | 9 | const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; |
michael@0 | 10 | let blocklistURL = "http://example.com/browser/browser/base/content/test/social/blocklist.xml"; |
michael@0 | 11 | |
michael@0 | 12 | let manifest = { // normal provider |
michael@0 | 13 | name: "provider ok", |
michael@0 | 14 | origin: "https://example.com", |
michael@0 | 15 | sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", |
michael@0 | 16 | workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 17 | iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" |
michael@0 | 18 | }; |
michael@0 | 19 | let manifest_bad = { // normal provider |
michael@0 | 20 | name: "provider blocked", |
michael@0 | 21 | origin: "https://test1.example.com", |
michael@0 | 22 | sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html", |
michael@0 | 23 | workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 24 | iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png" |
michael@0 | 25 | }; |
michael@0 | 26 | |
michael@0 | 27 | function test() { |
michael@0 | 28 | waitForExplicitFinish(); |
michael@0 | 29 | // turn on logging for nsBlocklistService.js |
michael@0 | 30 | Services.prefs.setBoolPref("extensions.logging.enabled", true); |
michael@0 | 31 | registerCleanupFunction(function () { |
michael@0 | 32 | Services.prefs.clearUserPref("extensions.logging.enabled"); |
michael@0 | 33 | }); |
michael@0 | 34 | |
michael@0 | 35 | runSocialTests(tests, undefined, undefined, function () { |
michael@0 | 36 | resetBlocklist(finish); //restore to original pref |
michael@0 | 37 | }); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | var tests = { |
michael@0 | 41 | testSimpleBlocklist: function(next) { |
michael@0 | 42 | // this really just tests adding and clearing our blocklist for later tests |
michael@0 | 43 | setAndUpdateBlocklist(blocklistURL, function() { |
michael@0 | 44 | ok(Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocking 'blocked'"); |
michael@0 | 45 | ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest)), "not blocking 'good'"); |
michael@0 | 46 | resetBlocklist(function() { |
michael@0 | 47 | ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocklist cleared"); |
michael@0 | 48 | next(); |
michael@0 | 49 | }); |
michael@0 | 50 | }); |
michael@0 | 51 | }, |
michael@0 | 52 | testAddingNonBlockedProvider: function(next) { |
michael@0 | 53 | function finishTest(isgood) { |
michael@0 | 54 | ok(isgood, "adding non-blocked provider ok"); |
michael@0 | 55 | Services.prefs.clearUserPref("social.manifest.good"); |
michael@0 | 56 | resetBlocklist(next); |
michael@0 | 57 | } |
michael@0 | 58 | setManifestPref("social.manifest.good", manifest); |
michael@0 | 59 | setAndUpdateBlocklist(blocklistURL, function() { |
michael@0 | 60 | try { |
michael@0 | 61 | SocialService.addProvider(manifest, function(provider) { |
michael@0 | 62 | try { |
michael@0 | 63 | SocialService.removeProvider(provider.origin, function() { |
michael@0 | 64 | ok(true, "added and removed provider"); |
michael@0 | 65 | finishTest(true); |
michael@0 | 66 | }); |
michael@0 | 67 | } catch(e) { |
michael@0 | 68 | ok(false, "SocialService.removeProvider threw exception: " + e); |
michael@0 | 69 | finishTest(false); |
michael@0 | 70 | } |
michael@0 | 71 | }); |
michael@0 | 72 | } catch(e) { |
michael@0 | 73 | ok(false, "SocialService.addProvider threw exception: " + e); |
michael@0 | 74 | finishTest(false); |
michael@0 | 75 | } |
michael@0 | 76 | }); |
michael@0 | 77 | }, |
michael@0 | 78 | testAddingBlockedProvider: function(next) { |
michael@0 | 79 | function finishTest(good) { |
michael@0 | 80 | ok(good, "Unable to add blocklisted provider"); |
michael@0 | 81 | Services.prefs.clearUserPref("social.manifest.blocked"); |
michael@0 | 82 | resetBlocklist(next); |
michael@0 | 83 | } |
michael@0 | 84 | setManifestPref("social.manifest.blocked", manifest_bad); |
michael@0 | 85 | setAndUpdateBlocklist(blocklistURL, function() { |
michael@0 | 86 | try { |
michael@0 | 87 | SocialService.addProvider(manifest_bad, function(provider) { |
michael@0 | 88 | SocialService.removeProvider(provider.origin, function() { |
michael@0 | 89 | ok(false, "SocialService.addProvider should throw blocklist exception"); |
michael@0 | 90 | finishTest(false); |
michael@0 | 91 | }); |
michael@0 | 92 | }); |
michael@0 | 93 | } catch(e) { |
michael@0 | 94 | ok(true, "SocialService.addProvider should throw blocklist exception: " + e); |
michael@0 | 95 | finishTest(true); |
michael@0 | 96 | } |
michael@0 | 97 | }); |
michael@0 | 98 | }, |
michael@0 | 99 | testInstallingBlockedProvider: function(next) { |
michael@0 | 100 | function finishTest(good) { |
michael@0 | 101 | ok(good, "Unable to add blocklisted provider"); |
michael@0 | 102 | Services.prefs.clearUserPref("social.whitelist"); |
michael@0 | 103 | resetBlocklist(next); |
michael@0 | 104 | } |
michael@0 | 105 | let activationURL = manifest_bad.origin + "/browser/browser/base/content/test/social/social_activate.html" |
michael@0 | 106 | addTab(activationURL, function(tab) { |
michael@0 | 107 | let doc = tab.linkedBrowser.contentDocument; |
michael@0 | 108 | let installFrom = doc.nodePrincipal.origin; |
michael@0 | 109 | // whitelist to avoid the 3rd party install dialog, we only want to test |
michael@0 | 110 | // the blocklist inside installProvider. |
michael@0 | 111 | Services.prefs.setCharPref("social.whitelist", installFrom); |
michael@0 | 112 | setAndUpdateBlocklist(blocklistURL, function() { |
michael@0 | 113 | try { |
michael@0 | 114 | // expecting an exception when attempting to install a hard blocked |
michael@0 | 115 | // provider |
michael@0 | 116 | Social.installProvider(doc, manifest_bad, function(addonManifest) { |
michael@0 | 117 | gBrowser.removeTab(tab); |
michael@0 | 118 | finishTest(false); |
michael@0 | 119 | }); |
michael@0 | 120 | } catch(e) { |
michael@0 | 121 | gBrowser.removeTab(tab); |
michael@0 | 122 | finishTest(true); |
michael@0 | 123 | } |
michael@0 | 124 | }); |
michael@0 | 125 | }); |
michael@0 | 126 | }, |
michael@0 | 127 | testBlockingExistingProvider: function(next) { |
michael@0 | 128 | let listener = { |
michael@0 | 129 | _window: null, |
michael@0 | 130 | onOpenWindow: function(aXULWindow) { |
michael@0 | 131 | Services.wm.removeListener(this); |
michael@0 | 132 | this._window = aXULWindow; |
michael@0 | 133 | let domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 134 | .getInterface(Ci.nsIDOMWindow); |
michael@0 | 135 | |
michael@0 | 136 | domwindow.addEventListener("load", function _load() { |
michael@0 | 137 | domwindow.removeEventListener("load", _load, false); |
michael@0 | 138 | |
michael@0 | 139 | domwindow.addEventListener("unload", function _unload() { |
michael@0 | 140 | domwindow.removeEventListener("unload", _unload, false); |
michael@0 | 141 | info("blocklist window was closed"); |
michael@0 | 142 | Services.wm.removeListener(listener); |
michael@0 | 143 | next(); |
michael@0 | 144 | }, false); |
michael@0 | 145 | |
michael@0 | 146 | is(domwindow.document.location.href, URI_EXTENSION_BLOCKLIST_DIALOG, "dialog opened and focused"); |
michael@0 | 147 | // wait until after load to cancel so the dialog has initalized. we |
michael@0 | 148 | // don't want to accept here since that restarts the browser. |
michael@0 | 149 | executeSoon(() => { |
michael@0 | 150 | let cancelButton = domwindow.document.documentElement.getButton("cancel"); |
michael@0 | 151 | info("***** hit the cancel button\n"); |
michael@0 | 152 | cancelButton.doCommand(); |
michael@0 | 153 | }); |
michael@0 | 154 | }, false); |
michael@0 | 155 | }, |
michael@0 | 156 | onCloseWindow: function(aXULWindow) { }, |
michael@0 | 157 | onWindowTitleChange: function(aXULWindow, aNewTitle) { } |
michael@0 | 158 | }; |
michael@0 | 159 | |
michael@0 | 160 | Services.wm.addListener(listener); |
michael@0 | 161 | |
michael@0 | 162 | setManifestPref("social.manifest.blocked", manifest_bad); |
michael@0 | 163 | try { |
michael@0 | 164 | SocialService.addProvider(manifest_bad, function(provider) { |
michael@0 | 165 | // the act of blocking should cause a 'provider-disabled' notification |
michael@0 | 166 | // from SocialService. |
michael@0 | 167 | SocialService.registerProviderListener(function providerListener(topic, origin, providers) { |
michael@0 | 168 | if (topic != "provider-disabled") |
michael@0 | 169 | return; |
michael@0 | 170 | SocialService.unregisterProviderListener(providerListener); |
michael@0 | 171 | is(origin, provider.origin, "provider disabled"); |
michael@0 | 172 | SocialService.getProvider(provider.origin, function(p) { |
michael@0 | 173 | ok(p == null, "blocklisted provider disabled"); |
michael@0 | 174 | Services.prefs.clearUserPref("social.manifest.blocked"); |
michael@0 | 175 | resetBlocklist(); |
michael@0 | 176 | }); |
michael@0 | 177 | }); |
michael@0 | 178 | // no callback - the act of updating should cause the listener above |
michael@0 | 179 | // to fire. |
michael@0 | 180 | setAndUpdateBlocklist(blocklistURL); |
michael@0 | 181 | }); |
michael@0 | 182 | } catch(e) { |
michael@0 | 183 | ok(false, "unable to add provider " + e); |
michael@0 | 184 | next(); |
michael@0 | 185 | } |
michael@0 | 186 | } |
michael@0 | 187 | } |