1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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("downloadsListBox");
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"
);
contextMenu.activateItem(goToDownloadButton);
let newTab = await tabPromise;
ok(newTab, "Go To Download Page opened a new tab");
gBrowser.removeTab(newTab);
});
|