blob: 4b4010de1fe148fb88f40072af0a7a8747bc41bf [file] [log] [blame]
Patrick Brossetfb005802020-06-03 09:40:531// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
Patrick Brossetfb005802020-06-03 09:40:536
Jack Franklinec064412020-12-08 13:02:247import {$textContent, goTo, reloadDevTools, typeText, waitFor} from '../../shared/helper.js';
Peter Marshall467b0b12020-08-17 07:08:598import {describe, it} from '../../shared/mocha-extensions.js';
Jack Frankline839c0c2022-05-03 08:47:449import {
10 getAllRequestNames,
11 getSelectedRequestName,
12 navigateToNetworkTab,
13 selectRequestByName,
14 setCacheDisabled,
15 setPersistLog,
16 waitForSelectedRequestChange,
17 waitForSomeRequestsToAppear,
18} from '../helpers/network-helpers.js';
Patrick Brossetfb005802020-06-03 09:40:5319
20const SIMPLE_PAGE_REQUEST_NUMBER = 10;
21const SIMPLE_PAGE_URL = `requests.html?num=${SIMPLE_PAGE_REQUEST_NUMBER}`;
22
Jack Franklinec064412020-12-08 13:02:2423async function getCategoryXHRFilter() {
24 const filters = await waitFor('.filter-bitset-filter');
Kriti Sapra274ace42021-04-26 14:53:5125 const categoryXHRFilter = await $textContent('Fetch/XHR', filters);
Jack Franklinec064412020-12-08 13:02:2426 if (!categoryXHRFilter) {
27 assert.fail('Could not find category XHR filter to click.');
28 }
29 return categoryXHRFilter;
30}
31
Danil Somsikov721956a2021-07-07 08:17:2732async function getThirdPartyFilter() {
33 const filters = await waitFor('.filter-bar');
34 const thirdPartyFilter = await $textContent('3rd-party requests', filters);
35 if (!thirdPartyFilter) {
36 assert.fail('Could not find category third-party filter to click.');
37 }
38 return thirdPartyFilter;
39}
40
Jack Franklinec064412020-12-08 13:02:2441describe('The Network Tab', async function() {
Patrick Brosset15550432020-06-10 14:46:4842 // The tests here tend to take time because they wait for requests to appear in the request panel.
43 this.timeout(5000);
44
Sigurd Schneider6d53f1f2021-07-27 11:06:2645 beforeEach(async () => {
46 await navigateToNetworkTab('empty.html');
47 await setCacheDisabled(true);
48 await setPersistLog(false);
49 });
50
Jack Franklinec064412020-12-08 13:02:2451 // Flakey test
52 it.skip('[crbug.com/1093287] displays requests', async () => {
Patrick Brosset0805f4a2020-06-11 09:34:3253 await navigateToNetworkTab(SIMPLE_PAGE_URL);
Patrick Brossetfb005802020-06-03 09:40:5354
55 // Wait for all the requests to be displayed + 1 to account for the page itself.
56 await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1);
57
58 const expectedNames = [SIMPLE_PAGE_URL];
59 for (let i = 0; i < SIMPLE_PAGE_REQUEST_NUMBER; i++) {
60 expectedNames.push(`image.svg?id=${i}`);
61 }
62
63 const names = await getAllRequestNames();
64 assert.deepStrictEqual(names, expectedNames, 'The right request names should appear in the list');
65 });
66
Jack Franklinec064412020-12-08 13:02:2467 // Flakey test
68 it.skip('[crbug.com/1093287] can select requests', async () => {
Patrick Brosset0805f4a2020-06-11 09:34:3269 await navigateToNetworkTab(SIMPLE_PAGE_URL);
Patrick Brossetfb005802020-06-03 09:40:5370
71 let selected = await getSelectedRequestName();
72 assert.isUndefined(selected, 'No request should be selected by default');
73
74 await selectRequestByName(SIMPLE_PAGE_URL);
75 await waitForSelectedRequestChange(selected);
76
77 selected = await getSelectedRequestName();
78 assert.strictEqual(selected, SIMPLE_PAGE_URL, 'Selecting the first request should work');
79
80 const lastRequestName = `image.svg?id=${SIMPLE_PAGE_REQUEST_NUMBER - 1}`;
81 await selectRequestByName(lastRequestName);
82 await waitForSelectedRequestChange(selected);
83
84 selected = await getSelectedRequestName();
85 assert.strictEqual(selected, lastRequestName, 'Selecting the last request should work');
86 });
87
Jack Franklinec064412020-12-08 13:02:2488 // Flakey test
89 it.skip('[crbug.com/1093287] can persist requests', async () => {
Patrick Brosset0805f4a2020-06-11 09:34:3290 await navigateToNetworkTab(SIMPLE_PAGE_URL);
Patrick Brossetfb005802020-06-03 09:40:5391
92 // Wait for all the requests to be displayed + 1 to account for the page itself, and get their names.
93 await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1);
94 const firstPageRequestNames = await getAllRequestNames();
95
Sigurd Schneider6d53f1f2021-07-27 11:06:2696 await setPersistLog(true);
Patrick Brossetfb005802020-06-03 09:40:5397
98 // Navigate to a new page, and wait for the same requests to still be there.
Patrick Brosset0805f4a2020-06-11 09:34:3299 await goTo('about:blank');
Patrick Brossetfb005802020-06-03 09:40:53100 await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1);
101 const secondPageRequestNames = await getAllRequestNames();
102
103 assert.deepStrictEqual(secondPageRequestNames, firstPageRequestNames, 'The requests were persisted');
104 });
Jack Franklinec064412020-12-08 13:02:24105
106 it('persists filters across a reload', async () => {
107 await navigateToNetworkTab(SIMPLE_PAGE_URL);
108 let filterInput = await waitFor('.filter-input-field.text-prompt');
109 filterInput.focus();
110 await typeText('foo');
111 let categoryXHRFilter = await getCategoryXHRFilter();
112 await categoryXHRFilter.click();
113
114 await reloadDevTools({selectedPanel: {name: 'network'}});
115 filterInput = await waitFor('.filter-input-field.text-prompt');
116 const filterText = await filterInput.evaluate(x => (x as HTMLElement).innerText);
117 assert.strictEqual(filterText, 'foo');
118
119 categoryXHRFilter = await getCategoryXHRFilter();
120 const xhrHasSelectedClass = await categoryXHRFilter.evaluate(x => x.classList.contains('selected'));
121 assert.isTrue(xhrHasSelectedClass);
122 });
Danil Somsikov721956a2021-07-07 08:17:27123
124 it('can show only third-party requests', async () => {
125 await navigateToNetworkTab('third-party-resources.html');
126 await waitForSomeRequestsToAppear(3);
127
128 let names = await getAllRequestNames();
129 /* assert.deepStrictEqual(names, [], 'The right request names should appear in the list'); */
130 const thirdPartyFilter = await getThirdPartyFilter();
131 await thirdPartyFilter.click();
132
133 names = await getAllRequestNames();
134 assert.deepStrictEqual(names, ['external_image.svg'], 'The right request names should appear in the list');
135 });
Patrick Brossetfb005802020-06-03 09:40:53136});