forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1576347 - Correct referrerInfo when saving media and add a test o…
…f "Go To Download Page" button r=Gijs Differential Revision: https://phabricator.services.mozilla.com/D43749 --HG-- extra : moz-landing-system : lando
- Loading branch information
Thomas Nguyen
committed
Aug 30, 2019
1 parent
9e00f53
commit c175f3d
Showing
6 changed files
with
130 additions
and
25 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
93 changes: 93 additions & 0 deletions
93
browser/components/downloads/test/browser/browser_go_to_download_page.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,93 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
|
||
const ReferrerInfo = Components.Constructor( | ||
"@mozilla.org/referrer-info;1", | ||
"nsIReferrerInfo", | ||
"init" | ||
); | ||
|
||
const TEST_REFERRER = "https://example.com/"; | ||
|
||
registerCleanupFunction(async function() { | ||
await task_resetState(); | ||
await PlacesUtils.history.clear(); | ||
}); | ||
|
||
async function addDownload(referrerInfo) { | ||
let startTimeMs = Date.now(); | ||
|
||
let publicList = await Downloads.getList(Downloads.PUBLIC); | ||
let downloadData = { | ||
source: { | ||
url: "http://www.example.com/test-download.txt", | ||
referrerInfo, | ||
}, | ||
target: { | ||
path: gTestTargetFile.path, | ||
}, | ||
startTime: new Date(startTimeMs++), | ||
}; | ||
let download = await Downloads.createDownload(downloadData); | ||
await publicList.add(download); | ||
await download.start(); | ||
} | ||
|
||
/** | ||
* Make sure "Go To Download Page" is enabled and works as expected. | ||
*/ | ||
add_task(async function test_go_to_download_page() { | ||
let referrerInfo = new ReferrerInfo( | ||
Ci.nsIReferrerInfo.NO_REFERRER, | ||
true, | ||
NetUtil.newURI(TEST_REFERRER) | ||
); | ||
|
||
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, TEST_REFERRER); | ||
|
||
// Wait for focus first | ||
await promiseFocus(); | ||
|
||
// Ensure that state is reset in case previous tests didn't finish. | ||
await task_resetState(); | ||
|
||
// Populate the downloads database with the data required by this test. | ||
await addDownload(referrerInfo); | ||
|
||
// Open the user interface and wait for data to be fully loaded. | ||
await task_openPanel(); | ||
|
||
let win = await openLibrary("Downloads"); | ||
registerCleanupFunction(function() { | ||
win.close(); | ||
}); | ||
|
||
let listbox = win.document.getElementById("downloadsRichListBox"); | ||
ok(listbox, "download list box present"); | ||
|
||
// Select one of the downloads. | ||
listbox.itemChildren[0].click(); | ||
|
||
let contextMenu = win.document.getElementById("downloadsContextMenu"); | ||
|
||
let popupShownPromise = BrowserTestUtils.waitForEvent( | ||
contextMenu, | ||
"popupshown" | ||
); | ||
EventUtils.synthesizeMouseAtCenter( | ||
listbox.itemChildren[0], | ||
{ type: "contextmenu", button: 2 }, | ||
win | ||
); | ||
await popupShownPromise; | ||
|
||
// Find and click "Go To Download Page" | ||
let goToDownloadButton = [...contextMenu.children].find( | ||
child => child.command == "downloadsCmd_openReferrer" | ||
); | ||
goToDownloadButton.click(); | ||
|
||
let newTab = await tabPromise; | ||
ok(newTab, "Go To Download Page opened a new tab"); | ||
gBrowser.removeTab(newTab); | ||
}); |
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