gecko/toolkit/components/social/test/browser/browser_workerAPI.js
Gavin Sharp 354e12c7fa Bug 771980: provider must be re-usable, r=jaws
--HG--
extra : transplant_source : s%94%84%C2%7C%27%A3%B0%DB%5B%7F%40%96%A4S%21%FFcSA
2012-07-11 10:43:56 -07:00

36 lines
1.3 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
let SocialProvider = Components.utils.import("resource://gre/modules/SocialProvider.jsm", {}).SocialProvider;
function test() {
waitForExplicitFinish();
// This test creates a SocialProvider object directly - it would be nicer to
// go through the SocialService, but adding a test provider before the service
// has been initialized can be tricky.
let provider = new SocialProvider({
origin: 'http://example.com',
name: "Example Provider",
workerURL: "http://example.com/browser/toolkit/components/social/test/browser/worker_social.js"
});
ok(provider.workerAPI, "provider has a workerAPI");
is(provider.workerAPI.initialized, false, "workerAPI is not yet initialized");
let port = provider.port;
ok(port, "should be able to get a port from the provider");
port.onmessage = function onMessage(event) {
let {topic, data} = event.data;
if (topic == "test-initialization-complete") {
is(provider.workerAPI.initialized, true, "workerAPI is now initialized");
// Terminate the provider
provider.enabled = false;
finish();
}
}
port.postMessage({topic: "test-initialization"});
}