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
|
"use strict";
/**
* Test if the value of total data transferred is displayed correctly in the Status Bar
* Test for Bug 1481002
*/
add_task(async () => {
// Clear cache, so we see expected number of cached requests.
Services.cache2.clear();
// Disable rcwn to make cache behavior deterministic.
await pushPref("network.http.rcwn.enabled", false);
const {
getFormattedSize,
} = require("resource://devtools/client/netmonitor/src/utils/format-utils.js");
const { tab, monitor } = await initNetMonitor(STATUS_CODES_URL, {
enableCache: true,
requestCount: 1,
});
info("Starting test... ");
const { document, store, windowRequire } = monitor.panelWin;
const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
const { getDisplayedRequestsSummary } = windowRequire(
"devtools/client/netmonitor/src/selectors/index"
);
const { L10N } = windowRequire("devtools/client/netmonitor/src/utils/l10n");
store.dispatch(Actions.batchEnable(false));
info("Performing requests...");
await performRequestsAndWait();
let cachedItemsInUI = 0;
for (const requestItem of document.querySelectorAll(".request-list-item")) {
const requestTransferStatus = requestItem.querySelector(
".requests-list-transferred"
).textContent;
if (requestTransferStatus === "cached") {
cachedItemsInUI++;
}
}
is(cachedItemsInUI, 1, "Number of cached requests displayed is correct");
const state = store.getState();
const totalRequestsCount = state.requests.requests.length;
const requestsSummary = getDisplayedRequestsSummary(state);
info(`Current requests: ${requestsSummary.count} of ${totalRequestsCount}.`);
const valueTransfer = document.querySelector(
".requests-list-network-summary-transfer"
).textContent;
info("Current summary transfer: " + valueTransfer);
const expectedTransfer = L10N.getFormatStrWithNumbers(
"networkMenu.summary.transferred",
getFormattedSize(requestsSummary.contentSize),
getFormattedSize(requestsSummary.transferredSize)
);
is(
valueTransfer,
expectedTransfer,
"The current summary transfer is correct."
);
await teardown(monitor);
async function performRequestsAndWait() {
const wait = waitForNetworkEvents(monitor, 2);
await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
content.wrappedJSObject.performOneCachedRequest();
});
await wait;
}
});
|