Skip to content
This repository has been archived by the owner on Aug 20, 2018. It is now read-only.

Commit

Permalink
Bug 915554 - Fix handling of the old private browsing mode for Firefo…
Browse files Browse the repository at this point in the history
…x 17.0 ESR. r=hskupin
  • Loading branch information
Andrei Eftimie authored and whimboo committed Sep 19, 2013
1 parent d86ae55 commit 2f85a34
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 7 deletions.
27 changes: 20 additions & 7 deletions mozmill/mozmill/extension/resource/modules/windows.js
Expand Up @@ -157,6 +157,14 @@ var windowCloseObserver = {
}
};

// Bug 915554
// Support for the old Private Browsing Mode (eg. ESR17)
// TODO: remove once ESR17 is no longer supported
var enterLeavePrivateBrowsingObserver = {
observe: function (aSubject, aTopic, aData) {
handleAttachEventListeners();
}
};

/**
* Attach event listeners
Expand Down Expand Up @@ -264,18 +272,23 @@ function attachEventListeners(aWindow) {
}
}

// Attach event listeners to all already open top-level windows
function handleAttachEventListeners() {
var enumerator = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator).getEnumerator("");
while (enumerator.hasMoreElements()) {
var win = enumerator.getNext();
attachEventListeners(win);
}
}

function init() {
// Activate observer for new top level windows
var observerService = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
observerService.addObserver(windowReadyObserver, "toplevel-window-ready", false);
observerService.addObserver(windowCloseObserver, "outer-window-destroyed", false);
observerService.addObserver(enterLeavePrivateBrowsingObserver, "private-browsing", false);

// Attach event listeners to all already open top-level windows
var enumerator = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator).getEnumerator("");
while (enumerator.hasMoreElements()) {
var win = enumerator.getNext();
attachEventListeners(win);
}
handleAttachEventListeners();
}
77 changes: 77 additions & 0 deletions mutt/mutt/tests/js/testController/testEnterLeavePrivateBrowsing.js
@@ -0,0 +1,77 @@
/* 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/. */

"use strict";

Cu.import("resource://gre/modules/Services.jsm");

const PREF_PB_NO_PROMPT = 'browser.privatebrowsing.dont_prompt_on_enter';

function setupModule(aModule) {
aModule.controller = mozmill.getBrowserController();

// Disable the notification when entering PB Mode
aModule.prefBranch = Services.prefs.QueryInterface(Ci.nsIPrefBranch);
aModule.prefBranch.setBoolPref(PREF_PB_NO_PROMPT, true);
}

function teardownModule(aModule) {
aModule.prefBranch.clearUserPref(PREF_PB_NO_PROMPT);
}

function test() {
privateBrowsing_start(controller);
privateBrowsing_stop(controller);
controller = mozmill.getBrowserController();
}

function privateBrowsing_start(aController) {
aController.mainMenu.click("#privateBrowsingItem");

// We have to wait until the transition has been finished
mozmill.utils.waitFor(function () {
var _pbTransitionItem = new elementslib.ID(aController.window.document, "Tools:PrivateBrowsing");
return !_pbTransitionItem.getNode().hasAttribute('disabled');
}, "Transition for Private Browsing mode has been finished.", undefined, undefined, this);
mozmill.utils.waitFor(function () {
return _pbs.privateBrowsingEnabled === true;
}, "Private Browsing state has been changed. Expected 'true'", undefined, undefined, this);
}

function privateBrowsing_stop(aController) {
// Set up an observer and a flag so we get notified when we exited PB
var finishedStateFlag = false;
var observer = {
observe: function (aSubject, aTopic, aData) {
finishedStateFlag = true;
}
}

try {
// Using this notification because the change where notifications became
// independent of non-deterministic factors (e.g garbage collection) from
// bug 804653 did not land on ESR17
Services.obs.addObserver(observer, "private-browsing-transition-complete", false);
aController.mainMenu.click("#privateBrowsingItem");
mozmill.utils.waitFor(function () {
return finishedStateFlag;
}, "Private browsing was exited");
}
finally {
Services.obs.removeObserver(observer, "private-browsing-transition-complete");
}
}

// Bug 915554
// Support for the old Private Browsing Mode (eg. ESR17)
// TODO: remove mutt test once ESR17 is no longer supported
try {
var _pbs = Cc["@mozilla.org/privatebrowsing;1"].getService(Ci.nsIPrivateBrowsingService);
}
catch (error) {
setupModule.__force_skip__ = "Bug 915554 - This test needs the old PB Mode available. " +
"ESR17 is the last supported version"
teardownModule.__force_skip__ = "Bug 915554 - This test needs the old PB Mode available " +
"ESR17 is the last supported version"
}

0 comments on commit 2f85a34

Please sign in to comment.