Debugging patch for bug 857427

--HG--
extra : rebase_source : 74ceaa5d816577b1f995fb18f88e5e465a66d337
This commit is contained in:
Ehsan Akhgari 2014-03-14 14:00:29 -04:00
parent fab513daed
commit 52139bdf6d

View File

@ -13,29 +13,37 @@ let NetUtil = tempScope.NetUtil;
// the first by checking that cookies set by the first response are not sent // the first by checking that cookies set by the first response are not sent
// during the second request. // during the second request.
function triggerSave(aWindow, aCallback) { function triggerSave(aWindow, aCallback) {
info("started triggerSave");
var fileName; var fileName;
let testBrowser = aWindow.gBrowser.selectedBrowser; let testBrowser = aWindow.gBrowser.selectedBrowser;
// This page sets a cookie if and only if a cookie does not exist yet // This page sets a cookie if and only if a cookie does not exist yet
let testURI = "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517-2.html"; let testURI = "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517-2.html";
testBrowser.loadURI(testURI); testBrowser.loadURI(testURI);
testBrowser.addEventListener("pageshow", function pageShown(event) { testBrowser.addEventListener("pageshow", function pageShown(event) {
info("got pageshow with " + event.target.location);
if (event.target.location != testURI) { if (event.target.location != testURI) {
info("try again!");
testBrowser.loadURI(testURI); testBrowser.loadURI(testURI);
return; return;
} }
info("found our page!");
testBrowser.removeEventListener("pageshow", pageShown, false); testBrowser.removeEventListener("pageshow", pageShown, false);
executeSoon(function () { executeSoon(function () {
info("register to handle popupshown");
aWindow.document.addEventListener("popupshown", function(e) contextMenuOpened(aWindow, e), false); aWindow.document.addEventListener("popupshown", function(e) contextMenuOpened(aWindow, e), false);
var link = testBrowser.contentDocument.getElementById("fff"); var link = testBrowser.contentDocument.getElementById("fff");
info("link: " + link);
EventUtils.synthesizeMouseAtCenter(link, EventUtils.synthesizeMouseAtCenter(link,
{ type: "contextmenu", button: 2 }, { type: "contextmenu", button: 2 },
testBrowser.contentWindow); testBrowser.contentWindow);
info("right clicked!");
}); });
}, false); }, false);
function contextMenuOpened(aWindow, event) { function contextMenuOpened(aWindow, event) {
info("contextMenuOpened");
event.currentTarget.removeEventListener("popupshown", contextMenuOpened, false); event.currentTarget.removeEventListener("popupshown", contextMenuOpened, false);
// Create the folder the link will be saved into. // Create the folder the link will be saved into.
@ -44,25 +52,32 @@ function triggerSave(aWindow, aCallback) {
MockFilePicker.displayDirectory = destDir; MockFilePicker.displayDirectory = destDir;
MockFilePicker.showCallback = function(fp) { MockFilePicker.showCallback = function(fp) {
info("showCallback");
fileName = fp.defaultString; fileName = fp.defaultString;
info("fileName: " + fileName);
destFile.append (fileName); destFile.append (fileName);
MockFilePicker.returnFiles = [destFile]; MockFilePicker.returnFiles = [destFile];
MockFilePicker.filterIndex = 1; // kSaveAsType_URL MockFilePicker.filterIndex = 1; // kSaveAsType_URL
info("done showCallback");
}; };
mockTransferCallback = function(downloadSuccess) { mockTransferCallback = function(downloadSuccess) {
info("mockTransferCallback");
onTransferComplete(aWindow, downloadSuccess, destDir); onTransferComplete(aWindow, downloadSuccess, destDir);
destDir.remove(true); destDir.remove(true);
ok(!destDir.exists(), "Destination dir should be removed"); ok(!destDir.exists(), "Destination dir should be removed");
ok(!destFile.exists(), "Destination file should be removed"); ok(!destFile.exists(), "Destination file should be removed");
mockTransferCallback = function(){}; mockTransferCallback = function(){};
info("done mockTransferCallback");
} }
// Select "Save Link As" option from context menu // Select "Save Link As" option from context menu
var saveLinkCommand = aWindow.document.getElementById("context-savelink"); var saveLinkCommand = aWindow.document.getElementById("context-savelink");
info("saveLinkCommand: " + saveLinkCommand);
saveLinkCommand.doCommand(); saveLinkCommand.doCommand();
event.target.hidePopup(); event.target.hidePopup();
info("popup hidden");
} }
function onTransferComplete(aWindow, downloadSuccess, destDir) { function onTransferComplete(aWindow, downloadSuccess, destDir) {
@ -74,20 +89,26 @@ function triggerSave(aWindow, aCallback) {
} }
function test() { function test() {
info("Start the test");
waitForExplicitFinish(); waitForExplicitFinish();
var windowsToClose = []; var windowsToClose = [];
var gNumSet = 0; var gNumSet = 0;
function testOnWindow(options, callback) { function testOnWindow(options, callback) {
info("testOnWindow(" + options + ")");
var win = OpenBrowserWindow(options); var win = OpenBrowserWindow(options);
info("got " + win);
whenDelayedStartupFinished(win, () => callback(win)); whenDelayedStartupFinished(win, () => callback(win));
} }
function whenDelayedStartupFinished(aWindow, aCallback) { function whenDelayedStartupFinished(aWindow, aCallback) {
info("whenDelayedStartupFinished");
Services.obs.addObserver(function observer(aSubject, aTopic) { Services.obs.addObserver(function observer(aSubject, aTopic) {
info("whenDelayedStartupFinished, got topic: " + aTopic + ", got subject: " + aSubject + ", waiting for " + aWindow);
if (aWindow == aSubject) { if (aWindow == aSubject) {
Services.obs.removeObserver(observer, aTopic); Services.obs.removeObserver(observer, aTopic);
executeSoon(aCallback); executeSoon(aCallback);
info("whenDelayedStartupFinished found our window");
} }
}, "browser-delayed-startup-finished", false); }, "browser-delayed-startup-finished", false);
} }
@ -95,6 +116,7 @@ function test() {
mockTransferRegisterer.register(); mockTransferRegisterer.register();
registerCleanupFunction(function () { registerCleanupFunction(function () {
info("Running the cleanup code");
mockTransferRegisterer.unregister(); mockTransferRegisterer.unregister();
MockFilePicker.cleanup(); MockFilePicker.cleanup();
windowsToClose.forEach(function(win) { windowsToClose.forEach(function(win) {
@ -102,9 +124,11 @@ function test() {
}); });
Services.obs.removeObserver(observer, "http-on-modify-request"); Services.obs.removeObserver(observer, "http-on-modify-request");
Services.obs.removeObserver(observer, "http-on-examine-response"); Services.obs.removeObserver(observer, "http-on-examine-response");
info("Finished running the cleanup code");
}); });
function observer(subject, topic, state) { function observer(subject, topic, state) {
info("observer called with " + topic);
if (topic == "http-on-modify-request") { if (topic == "http-on-modify-request") {
onModifyRequest(subject); onModifyRequest(subject);
} else if (topic == "http-on-examine-response") { } else if (topic == "http-on-examine-response") {
@ -114,7 +138,9 @@ function test() {
function onExamineResponse(subject) { function onExamineResponse(subject) {
let channel = subject.QueryInterface(Ci.nsIHttpChannel); let channel = subject.QueryInterface(Ci.nsIHttpChannel);
info("onExamineResponse with " + channel.URI.spec);
if (channel.URI.spec != "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517.sjs") { if (channel.URI.spec != "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517.sjs") {
info("returning");
return; return;
} }
try { try {
@ -123,21 +149,32 @@ function test() {
// header with foopy=1 when there are no cookies for that domain. // header with foopy=1 when there are no cookies for that domain.
is(cookies, "foopy=1", "Cookie should be foopy=1"); is(cookies, "foopy=1", "Cookie should be foopy=1");
gNumSet += 1; gNumSet += 1;
} catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) { } info("gNumSet = " + gNumSet);
} catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) {
info("onExamineResponse caught NOTAVAIL" + ex);
} catch (ex) {
info("ionExamineResponse caught " + ex);
}
} }
function onModifyRequest(subject) { function onModifyRequest(subject) {
let channel = subject.QueryInterface(Ci.nsIHttpChannel); let channel = subject.QueryInterface(Ci.nsIHttpChannel);
info("onModifyRequest with " + channel.URI.spec);
if (channel.URI.spec != "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517.sjs") { if (channel.URI.spec != "http://mochi.test:8888/browser/browser/base/content/test/general/bug792517.sjs") {
return; return;
} }
try { try {
let cookies = channel.getRequestHeader("cookie"); let cookies = channel.getRequestHeader("cookie");
info("cookies: " + cookies);
// From browser/base/content/test/general/bug792715.sjs, we should never send a // From browser/base/content/test/general/bug792715.sjs, we should never send a
// cookie because we are making only 2 requests: one in public mode, and // cookie because we are making only 2 requests: one in public mode, and
// one in private mode. // one in private mode.
throw "We should never send a cookie in this test"; throw "We should never send a cookie in this test";
} catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) { } } catch (ex if ex.result == Cr.NS_ERROR_NOT_AVAILABLE) {
info("onModifyRequest caught NOTAVAIL" + ex);
} catch (ex) {
info("ionModifyRequest caught " + ex);
}
} }
Services.obs.addObserver(observer, "http-on-modify-request", false); Services.obs.addObserver(observer, "http-on-modify-request", false);
@ -169,7 +206,10 @@ function createTemporarySaveDirectory() {
.getService(Ci.nsIProperties) .getService(Ci.nsIProperties)
.get("TmpD", Ci.nsIFile); .get("TmpD", Ci.nsIFile);
saveDir.append("testsavedir"); saveDir.append("testsavedir");
if (!saveDir.exists()) if (!saveDir.exists()) {
info("create testsavedir!");
saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755); saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
}
info("return from createTempSaveDir: " + saveDir.path);
return saveDir; return saveDir;
} }