Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 1 | // 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 | |
| 5 | import {assert} from 'chai'; |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 6 | |
Jack Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 7 | import {$textContent, goTo, reloadDevTools, typeText, waitFor} from '../../shared/helper.js'; |
Peter Marshall | 467b0b1 | 2020-08-17 07:08:59 | [diff] [blame] | 8 | import {describe, it} from '../../shared/mocha-extensions.js'; |
Jack Franklin | e839c0c | 2022-05-03 08:47:44 | [diff] [blame^] | 9 | import { |
| 10 | getAllRequestNames, |
| 11 | getSelectedRequestName, |
| 12 | navigateToNetworkTab, |
| 13 | selectRequestByName, |
| 14 | setCacheDisabled, |
| 15 | setPersistLog, |
| 16 | waitForSelectedRequestChange, |
| 17 | waitForSomeRequestsToAppear, |
| 18 | } from '../helpers/network-helpers.js'; |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 19 | |
| 20 | const SIMPLE_PAGE_REQUEST_NUMBER = 10; |
| 21 | const SIMPLE_PAGE_URL = `requests.html?num=${SIMPLE_PAGE_REQUEST_NUMBER}`; |
| 22 | |
Jack Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 23 | async function getCategoryXHRFilter() { |
| 24 | const filters = await waitFor('.filter-bitset-filter'); |
Kriti Sapra | 274ace4 | 2021-04-26 14:53:51 | [diff] [blame] | 25 | const categoryXHRFilter = await $textContent('Fetch/XHR', filters); |
Jack Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 26 | if (!categoryXHRFilter) { |
| 27 | assert.fail('Could not find category XHR filter to click.'); |
| 28 | } |
| 29 | return categoryXHRFilter; |
| 30 | } |
| 31 | |
Danil Somsikov | 721956a | 2021-07-07 08:17:27 | [diff] [blame] | 32 | async 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 Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 41 | describe('The Network Tab', async function() { |
Patrick Brosset | 1555043 | 2020-06-10 14:46:48 | [diff] [blame] | 42 | // The tests here tend to take time because they wait for requests to appear in the request panel. |
| 43 | this.timeout(5000); |
| 44 | |
Sigurd Schneider | 6d53f1f | 2021-07-27 11:06:26 | [diff] [blame] | 45 | beforeEach(async () => { |
| 46 | await navigateToNetworkTab('empty.html'); |
| 47 | await setCacheDisabled(true); |
| 48 | await setPersistLog(false); |
| 49 | }); |
| 50 | |
Jack Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 51 | // Flakey test |
| 52 | it.skip('[crbug.com/1093287] displays requests', async () => { |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame] | 53 | await navigateToNetworkTab(SIMPLE_PAGE_URL); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 54 | |
| 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 Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 67 | // Flakey test |
| 68 | it.skip('[crbug.com/1093287] can select requests', async () => { |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame] | 69 | await navigateToNetworkTab(SIMPLE_PAGE_URL); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 70 | |
| 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 Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 88 | // Flakey test |
| 89 | it.skip('[crbug.com/1093287] can persist requests', async () => { |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame] | 90 | await navigateToNetworkTab(SIMPLE_PAGE_URL); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 91 | |
| 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 Schneider | 6d53f1f | 2021-07-27 11:06:26 | [diff] [blame] | 96 | await setPersistLog(true); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 97 | |
| 98 | // Navigate to a new page, and wait for the same requests to still be there. |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame] | 99 | await goTo('about:blank'); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 100 | await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1); |
| 101 | const secondPageRequestNames = await getAllRequestNames(); |
| 102 | |
| 103 | assert.deepStrictEqual(secondPageRequestNames, firstPageRequestNames, 'The requests were persisted'); |
| 104 | }); |
Jack Franklin | ec06441 | 2020-12-08 13:02:24 | [diff] [blame] | 105 | |
| 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 Somsikov | 721956a | 2021-07-07 08:17:27 | [diff] [blame] | 123 | |
| 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 Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 136 | }); |