mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1057596 fix manifest updating and worker reload, r=markh
This commit is contained in:
parent
3098b23dc3
commit
ac2b2f0c46
@ -249,15 +249,37 @@ var tests = {
|
||||
SocialService.registerProviderListener(function providerListener(topic, origin, providers) {
|
||||
if (topic != "provider-update")
|
||||
return;
|
||||
is(origin, addonManifest.origin, "provider updated")
|
||||
// The worker will have reloaded and the current provider instance
|
||||
// disabled, removed from the provider list. We have a reference
|
||||
// here, check it is is disabled.
|
||||
is(provider.enabled, false, "old provider instance is disabled")
|
||||
is(origin, addonManifest.origin, "provider manifest updated")
|
||||
SocialService.unregisterProviderListener(providerListener);
|
||||
Services.prefs.clearUserPref("social.whitelist");
|
||||
let provider = Social._getProviderFromOrigin(origin);
|
||||
is(provider.manifest.version, 2, "manifest version is 2");
|
||||
Social.uninstallProvider(origin, function() {
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
});
|
||||
|
||||
// Get the new provider instance, fetch the manifest via workerapi
|
||||
// and validate that data as well.
|
||||
let p = Social._getProviderFromOrigin(origin);
|
||||
is(p.manifest.version, 2, "manifest version is 2");
|
||||
let port = p.getWorkerPort();
|
||||
ok(port, "got a new port");
|
||||
port.onmessage = function (e) {
|
||||
let topic = e.data.topic;
|
||||
switch (topic) {
|
||||
case "social.manifest":
|
||||
let manifest = e.data.data;
|
||||
is(manifest.version, 2, "manifest version is 2");
|
||||
port.close();
|
||||
Social.uninstallProvider(origin, function() {
|
||||
Services.prefs.clearUserPref("social.whitelist");
|
||||
gBrowser.removeTab(tab);
|
||||
next();
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
port.postMessage({topic: "test-init"});
|
||||
port.postMessage({topic: "manifest-get"});
|
||||
|
||||
});
|
||||
|
||||
let port = provider.getWorkerPort();
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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 testPort, sidebarPort, apiPort;
|
||||
let testPort, sidebarPort, apiPort, updatingManifest=false;
|
||||
|
||||
onconnect = function(e) {
|
||||
let port = e.ports[0];
|
||||
@ -116,12 +116,21 @@ onconnect = function(e) {
|
||||
if (testPort)
|
||||
testPort.postMessage({topic:"got-share-data-message", result: event.data.result});
|
||||
break;
|
||||
case "manifest-get":
|
||||
apiPort.postMessage({topic: 'social.manifest-get'});
|
||||
break;
|
||||
case "worker.update":
|
||||
updatingManifest = true;
|
||||
apiPort.postMessage({topic: 'social.manifest-get'});
|
||||
break;
|
||||
case "social.manifest":
|
||||
event.data.data.version = 2;
|
||||
apiPort.postMessage({topic: 'social.manifest-set', data: event.data.data});
|
||||
if (updatingManifest) {
|
||||
updatingManifest = false;
|
||||
event.data.data.version = 2;
|
||||
apiPort.postMessage({topic: 'social.manifest-set', data: event.data.data});
|
||||
} else if (testPort) {
|
||||
testPort.postMessage({topic:"social.manifest", data: event.data.data});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -687,7 +687,11 @@ this.SocialService = {
|
||||
// overwrite the existing provider then notify the front end so it can
|
||||
// handle any reload that might be necessary.
|
||||
if (ActiveProviders.has(manifest.origin)) {
|
||||
let provider = new SocialProvider(manifest);
|
||||
// unload the worker prior to replacing the provider instance, also
|
||||
// ensures the workerapi instance is terminated.
|
||||
let provider = SocialServiceInternal.providers[manifest.origin];
|
||||
provider.enabled = false;
|
||||
provider = new SocialProvider(manifest);
|
||||
SocialServiceInternal.providers[provider.origin] = provider;
|
||||
// update the cache and ui, reload provider if necessary
|
||||
this.getOrderedProviderList(providers => {
|
||||
@ -756,8 +760,10 @@ function SocialProvider(input) {
|
||||
|
||||
SocialProvider.prototype = {
|
||||
reload: function() {
|
||||
this._terminate();
|
||||
this._activate();
|
||||
// calling terminate/activate does not set the enabled state whereas setting
|
||||
// enabled will call terminate/activate
|
||||
this.enabled = false;
|
||||
this.enabled = true;
|
||||
Services.obs.notifyObservers(null, "social:provider-reload", this.origin);
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user