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 | /* 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 | let provider; |
michael@0 | 6 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | waitForExplicitFinish(); |
michael@0 | 9 | |
michael@0 | 10 | let manifest = { |
michael@0 | 11 | origin: 'http://example.com', |
michael@0 | 12 | name: "Example Provider", |
michael@0 | 13 | workerURL: "http://example.com/browser/toolkit/components/social/test/browser/worker_social.js" |
michael@0 | 14 | }; |
michael@0 | 15 | |
michael@0 | 16 | SocialService.addProvider(manifest, function (p) { |
michael@0 | 17 | provider = p; |
michael@0 | 18 | runTests(tests, undefined, undefined, function () { |
michael@0 | 19 | SocialService.removeProvider(p.origin, function() { |
michael@0 | 20 | ok(!provider.enabled, "removing an enabled provider should have disabled the provider"); |
michael@0 | 21 | let port = provider.getWorkerPort(); |
michael@0 | 22 | ok(!port, "should not be able to get a port after removing the provider"); |
michael@0 | 23 | provider = null; |
michael@0 | 24 | finish(); |
michael@0 | 25 | }); |
michael@0 | 26 | }); |
michael@0 | 27 | }); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | let tests = { |
michael@0 | 31 | testSingleProvider: function(next) { |
michael@0 | 32 | ok(provider.enabled, "provider is initially enabled"); |
michael@0 | 33 | let port = provider.getWorkerPort(); |
michael@0 | 34 | ok(port, "should be able to get a port from enabled provider"); |
michael@0 | 35 | port.close(); |
michael@0 | 36 | ok(provider.workerAPI, "should be able to get a workerAPI from enabled provider"); |
michael@0 | 37 | |
michael@0 | 38 | provider.enabled = false; |
michael@0 | 39 | |
michael@0 | 40 | ok(!provider.enabled, "provider is now disabled"); |
michael@0 | 41 | port = provider.getWorkerPort(); |
michael@0 | 42 | ok(!port, "shouldn't be able to get a port from disabled provider"); |
michael@0 | 43 | ok(!provider.workerAPI, "shouldn't be able to get a workerAPI from disabled provider"); |
michael@0 | 44 | |
michael@0 | 45 | provider.enabled = true; |
michael@0 | 46 | |
michael@0 | 47 | ok(provider.enabled, "provider is re-enabled"); |
michael@0 | 48 | let port = provider.getWorkerPort(); |
michael@0 | 49 | ok(port, "should be able to get a port from re-enabled provider"); |
michael@0 | 50 | port.close(); |
michael@0 | 51 | ok(provider.workerAPI, "should be able to get a workerAPI from re-enabled provider"); |
michael@0 | 52 | next(); |
michael@0 | 53 | }, |
michael@0 | 54 | testTwoProviders: function(next) { |
michael@0 | 55 | // add another provider, test both workers |
michael@0 | 56 | let manifest = { |
michael@0 | 57 | origin: 'http://test2.example.com', |
michael@0 | 58 | name: "Example Provider 2", |
michael@0 | 59 | workerURL: "http://test2.example.com/browser/toolkit/components/social/test/browser/worker_social.js" |
michael@0 | 60 | }; |
michael@0 | 61 | SocialService.addProvider(manifest, function (provider2) { |
michael@0 | 62 | ok(provider.enabled, "provider is initially enabled"); |
michael@0 | 63 | ok(provider2.enabled, "provider2 is initially enabled"); |
michael@0 | 64 | let port = provider.getWorkerPort(); |
michael@0 | 65 | let port2 = provider2.getWorkerPort(); |
michael@0 | 66 | ok(port, "have port for provider"); |
michael@0 | 67 | ok(port2, "have port for provider2"); |
michael@0 | 68 | port.onmessage = function(e) { |
michael@0 | 69 | if (e.data.topic == "test-initialization-complete") { |
michael@0 | 70 | ok(true, "first provider initialized"); |
michael@0 | 71 | port2.postMessage({topic: "test-initialization"}); |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | port2.onmessage = function(e) { |
michael@0 | 75 | if (e.data.topic == "test-initialization-complete") { |
michael@0 | 76 | ok(true, "second provider initialized"); |
michael@0 | 77 | SocialService.removeProvider(provider2.origin, function() { |
michael@0 | 78 | next(); |
michael@0 | 79 | }); |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | port.postMessage({topic: "test-initialization"}); |
michael@0 | 83 | }); |
michael@0 | 84 | } |
michael@0 | 85 | } |