Bug 788100 - Remove social.initialize-response message. r=jaws

This commit is contained in:
Mark Hammond 2012-09-12 12:48:38 +10:00
parent 78b3d11180
commit 8fddaf0512
5 changed files with 15 additions and 49 deletions

View File

@ -29,10 +29,12 @@ var tests = {
function triggerIconPanel() { function triggerIconPanel() {
let statusIcons = document.getElementById("social-status-iconbox"); let statusIcons = document.getElementById("social-status-iconbox");
ok(!statusIcons.firstChild.hidden, "status icon is visible"); waitForCondition(function() statusIcons.firstChild && !statusIcons.firstChild.hidden,
// Click the button to trigger its contentPanel function() {
let panel = document.getElementById("social-notification-panel"); // Click the button to trigger its contentPanel
EventUtils.synthesizeMouseAtCenter(statusIcons.firstChild, {}); let panel = document.getElementById("social-notification-panel");
EventUtils.synthesizeMouseAtCenter(statusIcons.firstChild, {});
}, "Status icon didn't become non-hidden");
} }
let port = Social.provider.getWorkerPort(); let port = Social.provider.getWorkerPort();
@ -40,6 +42,10 @@ var tests = {
port.onmessage = function (e) { port.onmessage = function (e) {
let topic = e.data.topic; let topic = e.data.topic;
switch (topic) { switch (topic) {
case "test-init-done":
iconsReady = true;
checkNext();
break;
case "got-panel-message": case "got-panel-message":
ok(true, "got panel message"); ok(true, "got panel message");
// Check the panel isn't in our history. // Check the panel isn't in our history.
@ -67,24 +73,5 @@ var tests = {
} }
} }
port.postMessage({topic: "test-init"}); port.postMessage({topic: "test-init"});
// Our worker sets up ambient notification at the same time as it responds to
// the workerAPI initialization. If it's already initialized, we can
// immediately check the icons, otherwise wait for initialization by
// observing the topic sent out by the social service.
if (Social.provider.workerAPI.initialized) {
iconsReady = true;
checkNext();
} else {
Services.obs.addObserver(function obs() {
Services.obs.removeObserver(obs, "social:ambient-notification-changed");
// Let the other observers (like the one that updates the UI) run before
// checking the icons.
executeSoon(function () {
iconsReady = true;
checkNext();
});
}, "social:ambient-notification-changed", false);
}
} }
} }

View File

@ -11,6 +11,7 @@ onconnect = function(e) {
switch (topic) { switch (topic) {
case "test-init": case "test-init":
testPort = port; testPort = port;
port.postMessage({topic: "test-init-done"});
break; break;
case "sidebar-message": case "sidebar-message":
sidebarPort = port; sidebarPort = port;
@ -69,7 +70,6 @@ onconnect = function(e) {
case "social.initialize": case "social.initialize":
// This is the workerAPI port, respond and set up a notification icon. // This is the workerAPI port, respond and set up a notification icon.
apiPort = port; apiPort = port;
port.postMessage({topic: "social.initialize-response"});
let profile = { let profile = {
portrait: "https://example.com/portrait.jpg", portrait: "https://example.com/portrait.jpg",
userName: "trickster", userName: "trickster",

View File

@ -23,8 +23,6 @@ function WorkerAPI(provider, port) {
this._port = port; this._port = port;
this._port.onmessage = this._handleMessage.bind(this); this._port.onmessage = this._handleMessage.bind(this);
this.initialized = false;
// Send an "intro" message so the worker knows this is the port // Send an "intro" message so the worker knows this is the port
// used for the api. // used for the api.
// later we might even include an API version - version 0 for now! // later we might even include an API version - version 0 for now!
@ -54,9 +52,6 @@ WorkerAPI.prototype = {
}, },
handlers: { handlers: {
"social.initialize-response": function (data) {
this.initialized = true;
},
"social.user-profile": function (data) { "social.user-profile": function (data) {
this._provider.updateUserProfile(data); this._provider.updateUserProfile(data);
}, },

View File

@ -24,24 +24,6 @@ function test() {
} }
let tests = { let tests = {
testInitializeWorker: function(next) {
ok(provider.workerAPI, "provider has a workerAPI");
is(provider.workerAPI.initialized, false, "workerAPI is not yet initialized");
let port = provider.getWorkerPort();
ok(port, "should be able to get a port from the provider");
port.onmessage = function onMessage(event) {
let topic = event.data.topic;
if (topic == "test-initialization-complete") {
is(provider.workerAPI.initialized, true, "workerAPI is now initialized");
port.close();
next();
}
}
port.postMessage({topic: "test-initialization"});
},
testProfile: function(next) { testProfile: function(next) {
let expect = { let expect = {
portrait: "https://example.com/portrait.jpg", portrait: "https://example.com/portrait.jpg",
@ -58,12 +40,15 @@ let tests = {
is(profile.displayName, expect.displayName, "displayName is set"); is(profile.displayName, expect.displayName, "displayName is set");
is(profile.profileURL, expect.profileURL, "profileURL is set"); is(profile.profileURL, expect.profileURL, "profileURL is set");
// see below - if not for bug 788368 we could close this earlier.
port.close();
next(); next();
} }
Services.obs.addObserver(ob, "social:profile-changed", false); Services.obs.addObserver(ob, "social:profile-changed", false);
let port = provider.getWorkerPort(); let port = provider.getWorkerPort();
port.postMessage({topic: "test-profile", data: expect}); port.postMessage({topic: "test-profile", data: expect});
port.close(); // theoretically we should be able to close the port here, but bug 788368
// means that if we do, the worker never sees the test-profile message.
}, },
testAmbientNotification: function(next) { testAmbientNotification: function(next) {

View File

@ -17,7 +17,6 @@ onconnect = function(e) {
switch (topic) { switch (topic) {
case "social.initialize": case "social.initialize":
apiPort = port; apiPort = port;
apiPort.postMessage({topic: "social.initialize-response"});
break; break;
case "test-initialization": case "test-initialization":
testerPort = port; testerPort = port;