mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 807217 - Disable Social in private browsing mode. r=gavin,felipe
This commit is contained in:
parent
9e68cd9d59
commit
44a98dae92
@ -271,6 +271,7 @@ _BROWSER_FILES = \
|
||||
browser_tabDrop.js \
|
||||
browser_lastAccessedTab.js \
|
||||
browser_bug734076.js \
|
||||
browser_social.js \
|
||||
browser_social_toolbar.js \
|
||||
browser_social_shareButton.js \
|
||||
browser_social_sidebar.js \
|
||||
|
92
browser/base/content/test/browser_social.js
Normal file
92
browser/base/content/test/browser_social.js
Normal file
@ -0,0 +1,92 @@
|
||||
/* 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/. */
|
||||
|
||||
// a place for miscellaneous social tests
|
||||
|
||||
|
||||
const pb = Cc["@mozilla.org/privatebrowsing;1"].
|
||||
getService(Ci.nsIPrivateBrowsingService);
|
||||
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let manifest = { // normal provider
|
||||
name: "provider 1",
|
||||
origin: "https://example.com",
|
||||
sidebarURL: "https://example.com/browser/browser/base/content/test/social_sidebar.html",
|
||||
workerURL: "https://example.com/browser/browser/base/content/test/social_worker.js",
|
||||
iconURL: "https://example.com/browser/browser/base/content/test/moz.png"
|
||||
};
|
||||
runSocialTestWithProvider(manifest, function (finishcb) {
|
||||
runSocialTests(tests, undefined, undefined, finishcb);
|
||||
});
|
||||
}
|
||||
|
||||
var tests = {
|
||||
testPrivateBrowsing: function(next) {
|
||||
let port = Social.provider.getWorkerPort();
|
||||
ok(port, "provider has a port");
|
||||
port.postMessage({topic: "test-init"});
|
||||
port.onmessage = function (e) {
|
||||
let topic = e.data.topic;
|
||||
switch (topic) {
|
||||
case "got-sidebar-message":
|
||||
ok(true, "got sidebar message");
|
||||
port.close();
|
||||
togglePrivateBrowsing(function () {
|
||||
ok(!Social.enabled, "Social shuts down during private browsing");
|
||||
togglePrivateBrowsing(function () {
|
||||
ok(Social.enabled, "Social enabled after private browsing");
|
||||
next();
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
testPrivateBrowsingSocialDisabled: function(next) {
|
||||
// test PB from the perspective of entering PB without social enabled
|
||||
// we expect social to be enabled at the start of the test, we need
|
||||
// to disable it before testing PB transitions.
|
||||
let port = Social.provider.getWorkerPort();
|
||||
ok(port, "provider has a port");
|
||||
port.postMessage({topic: "test-init"});
|
||||
port.onmessage = function (e) {
|
||||
let topic = e.data.topic;
|
||||
switch (topic) {
|
||||
case "got-sidebar-message":
|
||||
ok(true, "got sidebar message");
|
||||
port.close();
|
||||
Social.enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// wait for disable, then do some pb toggling. We expect social to remain
|
||||
// disabled through these tests
|
||||
Services.obs.addObserver(function observer(aSubject, aTopic) {
|
||||
Services.obs.removeObserver(observer, aTopic);
|
||||
ok(!Social.enabled, "Social is not enabled");
|
||||
togglePrivateBrowsing(function () {
|
||||
ok(!Social.enabled, "Social not available during private browsing");
|
||||
togglePrivateBrowsing(function () {
|
||||
ok(!Social.enabled, "Social is not enabled after private browsing");
|
||||
// social will be reenabled on start of next social test
|
||||
next();
|
||||
});
|
||||
});
|
||||
}, "social:pref-changed", false);
|
||||
}
|
||||
}
|
||||
|
||||
function togglePrivateBrowsing(aCallback) {
|
||||
Services.obs.addObserver(function observe(subject, topic, data) {
|
||||
Services.obs.removeObserver(observe, topic);
|
||||
executeSoon(aCallback);
|
||||
}, "private-browsing-transition-complete", false);
|
||||
|
||||
pb.privateBrowsingEnabled = !pb.privateBrowsingEnabled;
|
||||
}
|
@ -28,6 +28,11 @@ this.Social = {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this._addedPrivateBrowsingObserver) {
|
||||
Services.obs.addObserver(this, "private-browsing", false);
|
||||
this._addedPrivateBrowsingObserver = true;
|
||||
}
|
||||
|
||||
// Eventually this might want to retrieve a specific provider, but for now
|
||||
// just use the first available.
|
||||
SocialService.getProviderList(function (providers) {
|
||||
@ -37,6 +42,17 @@ this.Social = {
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
if (aTopic == "private-browsing") {
|
||||
if (aData == "enter") {
|
||||
this._enabledBeforePrivateBrowsing = this.enabled;
|
||||
this.enabled = false;
|
||||
} else if (aData == "exit") {
|
||||
this.enabled = this._enabledBeforePrivateBrowsing;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
get uiVisible() {
|
||||
return this.provider && this.provider.enabled;
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user