From 1d7e5ee8306d76b02740f10fbffc3cfc520886a3 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Sun, 2 Dec 2012 23:22:45 -0500 Subject: [PATCH 1/2] Follow-up to bug 810180 - Reset the homepage to about:blank when opening new windows in the test; r=jdm DONTBUILD because this is NPOTB in global PB builds --- .../search/test/browser_private_search_perwindowpb.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/browser/components/search/test/browser_private_search_perwindowpb.js b/browser/components/search/test/browser_private_search_perwindowpb.js index f7656c73abd..2dc911bd3ac 100644 --- a/browser/components/search/test/browser_private_search_perwindowpb.js +++ b/browser/components/search/test/browser_private_search_perwindowpb.js @@ -3,6 +3,10 @@ // whether there is an autocomplete entry for the private search. function test() { + // Don't use about:home as the homepage for new windows + Services.prefs.setIntPref("browser.startup.page", 0); + registerCleanupFunction(function() Services.prefs.clearUserPref("browser.startup.page")); + waitForExplicitFinish(); let engineURL = From 0417fce7083615b5b4559f39c9f90b938381d391 Mon Sep 17 00:00:00 2001 From: "Mario Alvarado [:marioalv]" Date: Mon, 3 Dec 2012 01:36:43 -0600 Subject: [PATCH 2/2] Bug 806707 - Port browser_save_private_link.js to the new per-window PB APIs; r=ehsan DONTBUILD since this is NPOTB in global PB builds --HG-- rename : browser/base/content/test/browser_save_private_link.js => browser/base/content/test/browser_save_private_link_perwindowpb.js --- browser/base/content/test/Makefile.in | 3 +- .../browser_save_private_link_perwindowpb.js | 129 ++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 browser/base/content/test/browser_save_private_link_perwindowpb.js diff --git a/browser/base/content/test/Makefile.in b/browser/base/content/test/Makefile.in index e52c1a25901..aa364881905 100644 --- a/browser/base/content/test/Makefile.in +++ b/browser/base/content/test/Makefile.in @@ -200,7 +200,6 @@ _BROWSER_FILES = \ bug564387.html \ bug564387_video1.ogv \ bug564387_video1.ogv^headers^ \ - browser_save_private_link.js \ bug792517.html \ bug792517-2.html \ bug792517.sjs \ @@ -315,12 +314,14 @@ _BROWSER_FILES += \ browser_bug767836_perwindowpb.js \ browser_private_browsing_window.js \ browser_save_link-perwindowpb.js \ + browser_save_private_link_perwindowpb.js \ $(NULL) else _BROWSER_FILES += \ browser_bug763468.js \ browser_bug767836.js \ browser_save_link.js \ + browser_save_private_link.js \ $(NULL) endif diff --git a/browser/base/content/test/browser_save_private_link_perwindowpb.js b/browser/base/content/test/browser_save_private_link_perwindowpb.js new file mode 100644 index 00000000000..fe461bb11fa --- /dev/null +++ b/browser/base/content/test/browser_save_private_link_perwindowpb.js @@ -0,0 +1,129 @@ +/* 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/. */ +function test() { + // initialization + waitForExplicitFinish(); + let windowsToClose = []; + let testURI = "http://mochi.test:8888/browser/browser/base/content/test/bug792517.html"; + let fileName; + let MockFilePicker = SpecialPowers.MockFilePicker; + let cache = Cc["@mozilla.org/network/cache-service;1"] + .getService(Ci.nsICacheService); + + function checkDiskCacheFor(filename) { + let visitor = { + visitDevice: function(deviceID, deviceInfo) { + if (deviceID == "disk") + info(deviceID + " device contains " + deviceInfo.entryCount + " entries"); + return deviceID == "disk"; + }, + + visitEntry: function(deviceID, entryInfo) { + info(entryInfo.key); + is(entryInfo.key.contains(filename), false, "web content present in disk cache"); + } + }; + cache.visitEntries(visitor); + } + + function contextMenuOpened(aWindow, event) { + cache.evictEntries(Ci.nsICache.STORE_ANYWHERE); + + event.currentTarget.removeEventListener("popupshown", contextMenuOpened); + + // Create the folder the image will be saved into. + var destDir = createTemporarySaveDirectory(); + var destFile = destDir.clone(); + + MockFilePicker.displayDirectory = destDir; + MockFilePicker.showCallback = function(fp) { + fileName = fp.defaultString; + destFile.append (fileName); + MockFilePicker.returnFiles = [destFile]; + MockFilePicker.filterIndex = 1; // kSaveAsType_URL + }; + + mockTransferCallback = onTransferComplete; + mockTransferRegisterer.register(); + + registerCleanupFunction(function () { + mockTransferRegisterer.unregister(); + MockFilePicker.cleanup(); + destDir.remove(true); + }); + + // Select "Save Image As" option from context menu + var saveVideoCommand = aWindow.document.getElementById("context-saveimage"); + saveVideoCommand.doCommand(); + + event.target.hidePopup(); + } + + function onTransferComplete(downloadSuccess) { + ok(downloadSuccess, "Image file should have been downloaded successfully"); + + // Give the request a chance to finish and create a cache entry + executeSoon(function() { + checkDiskCacheFor(fileName); + finish(); + }); + } + + function createTemporarySaveDirectory() { + var saveDir = Cc["@mozilla.org/file/directory_service;1"] + .getService(Ci.nsIProperties) + .get("TmpD", Ci.nsIFile); + saveDir.append("testsavedir"); + if (!saveDir.exists()) + saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755); + return saveDir; + } + + function doTest(aIsPrivateMode, aWindow, aCallback) { + aWindow.gBrowser.addEventListener("pageshow", function pageShown(event) { + if (event.target.location == "about:blank") + return; + aWindow.gBrowser.removeEventListener("pageshow", pageShown); + + executeSoon(function () { + aWindow.document.addEventListener("popupshown", + function(e) contextMenuOpened(aWindow, e), false); + var img = aWindow.gBrowser.selectedBrowser.contentDocument.getElementById("img"); + EventUtils.synthesizeMouseAtCenter(img, + { type: "contextmenu", button: 2 }, + aWindow.gBrowser.contentWindow); + }); + }); + + aWindow.gBrowser.selectedBrowser.loadURI(testURI); + } + + function testOnWindow(aOptions, aCallback) { + whenNewWindowLoaded(aOptions, function(aWin) { + windowsToClose.push(aWin); + // execute should only be called when need, like when you are opening + // web pages on the test. If calling executeSoon() is not necesary, then + // call whenNewWindowLoaded() instead of testOnWindow() on your test. + executeSoon(function() aCallback(aWin)); + }); + }; + + // this function is called after calling finish() on the test. + registerCleanupFunction(function() { + windowsToClose.forEach(function(aWin) { + aWin.close(); + }); + }); + + MockFilePicker.init(); + // then test when on private mode + testOnWindow({private: true}, function(aWin) { + doTest(true, aWin, finish); + }); +} + +Cc["@mozilla.org/moz/jssubscript-loader;1"] + .getService(Ci.mozIJSSubScriptLoader) + .loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockTransfer.js", + this);