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'; |
| 6 | import {describe, it} from 'mocha'; |
| 7 | |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame^] | 8 | import {goTo} from '../../shared/helper.js'; |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 9 | import {getAllRequestNames, getSelectedRequestName, navigateToNetworkTab, selectRequestByName, togglePersistLog, waitForSelectedRequestChange, waitForSomeRequestsToAppear} from '../helpers/network-helpers.js'; |
| 10 | |
| 11 | const SIMPLE_PAGE_REQUEST_NUMBER = 10; |
| 12 | const SIMPLE_PAGE_URL = `requests.html?num=${SIMPLE_PAGE_REQUEST_NUMBER}`; |
| 13 | |
Tim van der Lippe | 547d18c | 2020-06-10 12:27:04 | [diff] [blame] | 14 | // Tests are flaky |
Patrick Brosset | 1555043 | 2020-06-10 14:46:48 | [diff] [blame] | 15 | describe('The Network Tab', async function() { |
| 16 | // The tests here tend to take time because they wait for requests to appear in the request panel. |
| 17 | this.timeout(5000); |
| 18 | |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 19 | it('displays requests', async () => { |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame^] | 20 | await navigateToNetworkTab(SIMPLE_PAGE_URL); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 21 | |
| 22 | // Wait for all the requests to be displayed + 1 to account for the page itself. |
| 23 | await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1); |
| 24 | |
| 25 | const expectedNames = [SIMPLE_PAGE_URL]; |
| 26 | for (let i = 0; i < SIMPLE_PAGE_REQUEST_NUMBER; i++) { |
| 27 | expectedNames.push(`image.svg?id=${i}`); |
| 28 | } |
| 29 | |
| 30 | const names = await getAllRequestNames(); |
| 31 | assert.deepStrictEqual(names, expectedNames, 'The right request names should appear in the list'); |
| 32 | }); |
| 33 | |
| 34 | it('can select requests', async () => { |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame^] | 35 | await navigateToNetworkTab(SIMPLE_PAGE_URL); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 36 | |
| 37 | let selected = await getSelectedRequestName(); |
| 38 | assert.isUndefined(selected, 'No request should be selected by default'); |
| 39 | |
| 40 | await selectRequestByName(SIMPLE_PAGE_URL); |
| 41 | await waitForSelectedRequestChange(selected); |
| 42 | |
| 43 | selected = await getSelectedRequestName(); |
| 44 | assert.strictEqual(selected, SIMPLE_PAGE_URL, 'Selecting the first request should work'); |
| 45 | |
| 46 | const lastRequestName = `image.svg?id=${SIMPLE_PAGE_REQUEST_NUMBER - 1}`; |
| 47 | await selectRequestByName(lastRequestName); |
| 48 | await waitForSelectedRequestChange(selected); |
| 49 | |
| 50 | selected = await getSelectedRequestName(); |
| 51 | assert.strictEqual(selected, lastRequestName, 'Selecting the last request should work'); |
| 52 | }); |
| 53 | |
| 54 | it('can persist requests', async () => { |
Patrick Brosset | 0805f4a | 2020-06-11 09:34:32 | [diff] [blame^] | 55 | await navigateToNetworkTab(SIMPLE_PAGE_URL); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 56 | |
| 57 | // Wait for all the requests to be displayed + 1 to account for the page itself, and get their names. |
| 58 | await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1); |
| 59 | const firstPageRequestNames = await getAllRequestNames(); |
| 60 | |
| 61 | await togglePersistLog(); |
| 62 | |
| 63 | // 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^] | 64 | await goTo('about:blank'); |
Patrick Brosset | fb00580 | 2020-06-03 09:40:53 | [diff] [blame] | 65 | await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1); |
| 66 | const secondPageRequestNames = await getAllRequestNames(); |
| 67 | |
| 68 | assert.deepStrictEqual(secondPageRequestNames, firstPageRequestNames, 'The requests were persisted'); |
| 69 | }); |
| 70 | }); |