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
94
95
96
97
98
99
|
/* 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/. */
const { NavigationManager } = ChromeUtils.importESModule(
"chrome://remote/content/shared/NavigationManager.sys.mjs"
);
const { TabManager } = ChromeUtils.importESModule(
"chrome://remote/content/shared/TabManager.sys.mjs"
);
const TEST_URL = "https://example.com/document-builder.sjs?html=test1";
const TEST_URL_CLOSED_PORT = "http://127.0.0.1:36325/";
const TEST_URL_WRONG_URI = "https://www.wronguri.wronguri/";
add_task(async function testClosedPort() {
const events = [];
const onEvent = (name, data) => events.push({ name, data });
const navigationManager = new NavigationManager();
navigationManager.on("navigation-started", onEvent);
navigationManager.on("navigation-stopped", onEvent);
const tab = addTab(gBrowser, TEST_URL);
const browser = tab.linkedBrowser;
await BrowserTestUtils.browserLoaded(browser);
const navigableId = TabManager.getIdForBrowser(browser);
navigationManager.startMonitoring();
is(
navigationManager.getNavigationForBrowsingContext(browser.browsingContext),
null,
"No navigation recorded yet"
);
is(events.length, 0, "No event recorded");
await loadURL(browser, TEST_URL_CLOSED_PORT, { maybeErrorPage: true });
const firstNavigation = navigationManager.getNavigationForBrowsingContext(
browser.browsingContext
);
assertNavigation(firstNavigation, TEST_URL_CLOSED_PORT);
is(events.length, 2, "Two events recorded");
assertNavigationEvents(
events,
TEST_URL_CLOSED_PORT,
firstNavigation.navigationId,
navigableId
);
navigationManager.off("navigation-started", onEvent);
navigationManager.off("navigation-stopped", onEvent);
navigationManager.stopMonitoring();
});
add_task(async function testWrongURI() {
const events = [];
const onEvent = (name, data) => events.push({ name, data });
const navigationManager = new NavigationManager();
navigationManager.on("navigation-started", onEvent);
navigationManager.on("navigation-stopped", onEvent);
const tab = addTab(gBrowser, TEST_URL);
const browser = tab.linkedBrowser;
await BrowserTestUtils.browserLoaded(browser);
const navigableId = TabManager.getIdForBrowser(browser);
navigationManager.startMonitoring();
is(
navigationManager.getNavigationForBrowsingContext(browser.browsingContext),
null,
"No navigation recorded yet"
);
is(events.length, 0, "No event recorded");
await loadURL(browser, TEST_URL_WRONG_URI, { maybeErrorPage: true });
const firstNavigation = navigationManager.getNavigationForBrowsingContext(
browser.browsingContext
);
assertNavigation(firstNavigation, TEST_URL_WRONG_URI);
is(events.length, 2, "Two events recorded");
assertNavigationEvents(
events,
TEST_URL_WRONG_URI,
firstNavigation.navigationId,
navigableId
);
navigationManager.off("navigation-started", onEvent);
navigationManager.off("navigation-stopped", onEvent);
navigationManager.stopMonitoring();
});
|