-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1406253 - Part 3: use currentRequstFinalURI in context menu and a…
…dd a test case. r=dao If the image request gets redirect on loading, HTMLImageElement.currentURI (which corresponds to nsIImageLoadingContent.currentURI) would return the original URI before redirect, making "Save Image" in the context menu use incorrect URI and filename. Use currentRequestFinalURI instead to get redirected URI. MozReview-Commit-ID: Bd7Q36sH93b --HG-- extra : rebase_source : b88ccf98bc2a41aac007d79060424eaa2c2aca88
- Loading branch information
1 parent
9a66d99
commit ef3c08c
Showing
7 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
toolkit/content/tests/browser/browser_default_image_filename_redirect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* TestCase for bug 1406253 | ||
* <https://bugzilla.mozilla.org/show_bug.cgi?id=1406253> | ||
* | ||
* Load firebird.png, redirect it to doggy.png, and verify the filename is | ||
* doggy.png in file picker dialog. | ||
*/ | ||
|
||
let {WebRequest} = Cu.import("resource://gre/modules/WebRequest.jsm", {}); | ||
let MockFilePicker = SpecialPowers.MockFilePicker; | ||
MockFilePicker.init(window); | ||
add_task(async function() { | ||
const URL_FIREBIRD = "http://mochi.test:8888/browser/toolkit/content/tests/browser/firebird.png"; | ||
const URL_DOGGY = "http://mochi.test:8888/browser/toolkit/content/tests/browser/doggy.png"; | ||
function redirect(requestDetails) { | ||
info("Redirecting: " + requestDetails.url); | ||
return { | ||
redirectUrl: URL_DOGGY | ||
}; | ||
} | ||
WebRequest.onBeforeRequest.addListener(redirect, | ||
{urls: new MatchPatternSet(["http://*/*firebird.png"])}, | ||
["blocking"] | ||
); | ||
|
||
await BrowserTestUtils.withNewTab(URL_FIREBIRD, | ||
async function(browser) { | ||
|
||
// Click image to show context menu. | ||
let popupShownPromise = BrowserTestUtils.waitForEvent(document, "popupshown"); | ||
await BrowserTestUtils.synthesizeMouseAtCenter("img", | ||
{ type: "contextmenu", button: 2 }, | ||
browser); | ||
await popupShownPromise; | ||
|
||
// Prepare mock file picker. | ||
let showFilePickerPromise = new Promise(resolve => { | ||
MockFilePicker.showCallback = fp => resolve(fp.defaultString); | ||
}); | ||
registerCleanupFunction(function() { | ||
MockFilePicker.cleanup(); | ||
}); | ||
|
||
// Select "Save Image As" option from context menu | ||
var saveImageAsCommand = document.getElementById("context-saveimage"); | ||
saveImageAsCommand.doCommand(); | ||
|
||
let filename = await showFilePickerPromise; | ||
is(filename, "doggy.png", "Verify image filename."); | ||
|
||
// Close context menu. | ||
let contextMenu = document.getElementById("contentAreaContextMenu"); | ||
let popupHiddenPromise = BrowserTestUtils.waitForEvent(contextMenu, "popuphidden"); | ||
contextMenu.hidePopup(); | ||
await popupHiddenPromise; | ||
}); | ||
|
||
WebRequest.onBeforeRequest.removeListener(redirect); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.