michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let provider; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let manifest = { michael@0: origin: 'http://example.com', michael@0: name: "Example Provider", michael@0: workerURL: "http://example.com/browser/toolkit/components/social/test/browser/worker_social.js" michael@0: }; michael@0: michael@0: SocialService.addProvider(manifest, function (p) { michael@0: provider = p; michael@0: runTests(tests, undefined, undefined, function () { michael@0: SocialService.removeProvider(p.origin, function() { michael@0: ok(!provider.enabled, "removing an enabled provider should have disabled the provider"); michael@0: let port = provider.getWorkerPort(); michael@0: ok(!port, "should not be able to get a port after removing the provider"); michael@0: provider = null; michael@0: finish(); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: let tests = { michael@0: testSingleProvider: function(next) { michael@0: ok(provider.enabled, "provider is initially enabled"); michael@0: let port = provider.getWorkerPort(); michael@0: ok(port, "should be able to get a port from enabled provider"); michael@0: port.close(); michael@0: ok(provider.workerAPI, "should be able to get a workerAPI from enabled provider"); michael@0: michael@0: provider.enabled = false; michael@0: michael@0: ok(!provider.enabled, "provider is now disabled"); michael@0: port = provider.getWorkerPort(); michael@0: ok(!port, "shouldn't be able to get a port from disabled provider"); michael@0: ok(!provider.workerAPI, "shouldn't be able to get a workerAPI from disabled provider"); michael@0: michael@0: provider.enabled = true; michael@0: michael@0: ok(provider.enabled, "provider is re-enabled"); michael@0: let port = provider.getWorkerPort(); michael@0: ok(port, "should be able to get a port from re-enabled provider"); michael@0: port.close(); michael@0: ok(provider.workerAPI, "should be able to get a workerAPI from re-enabled provider"); michael@0: next(); michael@0: }, michael@0: testTwoProviders: function(next) { michael@0: // add another provider, test both workers michael@0: let manifest = { michael@0: origin: 'http://test2.example.com', michael@0: name: "Example Provider 2", michael@0: workerURL: "http://test2.example.com/browser/toolkit/components/social/test/browser/worker_social.js" michael@0: }; michael@0: SocialService.addProvider(manifest, function (provider2) { michael@0: ok(provider.enabled, "provider is initially enabled"); michael@0: ok(provider2.enabled, "provider2 is initially enabled"); michael@0: let port = provider.getWorkerPort(); michael@0: let port2 = provider2.getWorkerPort(); michael@0: ok(port, "have port for provider"); michael@0: ok(port2, "have port for provider2"); michael@0: port.onmessage = function(e) { michael@0: if (e.data.topic == "test-initialization-complete") { michael@0: ok(true, "first provider initialized"); michael@0: port2.postMessage({topic: "test-initialization"}); michael@0: } michael@0: } michael@0: port2.onmessage = function(e) { michael@0: if (e.data.topic == "test-initialization-complete") { michael@0: ok(true, "second provider initialized"); michael@0: SocialService.removeProvider(provider2.origin, function() { michael@0: next(); michael@0: }); michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-initialization"}); michael@0: }); michael@0: } michael@0: }