michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This test makes sure that the Clear Recent History menu item and command michael@0: // is disabled inside the private browsing mode. michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: function checkDisableOption(aPrivateMode, aWindow, aCallback) { michael@0: executeSoon(function() { michael@0: let crhCommand = aWindow.document.getElementById("Tools:Sanitize"); michael@0: ok(crhCommand, "The clear recent history command should exist"); michael@0: michael@0: is(PrivateBrowsingUtils.isWindowPrivate(aWindow), aPrivateMode, michael@0: "PrivateBrowsingUtils should report the correct per-window private browsing status"); michael@0: is(crhCommand.hasAttribute("disabled"), aPrivateMode, michael@0: "Clear Recent History command should be disabled according to the private browsing mode"); michael@0: michael@0: executeSoon(aCallback); michael@0: }); michael@0: }; michael@0: michael@0: let windowsToClose = []; michael@0: let testURI = "http://mochi.test:8888/"; michael@0: michael@0: function testOnWindow(aIsPrivate, aCallback) { michael@0: whenNewWindowLoaded({private: aIsPrivate}, function(aWin) { michael@0: windowsToClose.push(aWin); michael@0: aWin.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: if (aWin.content.location.href != testURI) { michael@0: aWin.gBrowser.loadURI(testURI); michael@0: return; michael@0: } michael@0: aWin.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: executeSoon(function() aCallback(aWin)); michael@0: }, true); michael@0: michael@0: aWin.gBrowser.loadURI(testURI); michael@0: }); michael@0: }; michael@0: michael@0: registerCleanupFunction(function() { michael@0: windowsToClose.forEach(function(aWin) { michael@0: aWin.close(); michael@0: }); michael@0: }); michael@0: michael@0: testOnWindow(true, function(aWin) { michael@0: info("Test on private window"); michael@0: checkDisableOption(true, aWin, function() { michael@0: testOnWindow(false, function(aPrivWin) { michael@0: info("Test on public window"); michael@0: checkDisableOption(false, aPrivWin, finish); michael@0: }); michael@0: }); michael@0: }); michael@0: }