blob: b5b46d0b0f0ba4f50e9030d082b73dc7bd4241f3 [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';
6import {describe, it} from 'mocha';
7
Patrick Brosset0805f4a2020-06-11 09:34:328import {goTo} from '../../shared/helper.js';
Patrick Brossetfb005802020-06-03 09:40:539import {getAllRequestNames, getSelectedRequestName, navigateToNetworkTab, selectRequestByName, togglePersistLog, waitForSelectedRequestChange, waitForSomeRequestsToAppear} from '../helpers/network-helpers.js';
10
11const SIMPLE_PAGE_REQUEST_NUMBER = 10;
12const SIMPLE_PAGE_URL = `requests.html?num=${SIMPLE_PAGE_REQUEST_NUMBER}`;
13
Tim van der Lippe547d18c2020-06-10 12:27:0414// Tests are flaky
Patrick Brosset15550432020-06-10 14:46:4815describe('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 Brossetfb005802020-06-03 09:40:5319 it('displays requests', async () => {
Patrick Brosset0805f4a2020-06-11 09:34:3220 await navigateToNetworkTab(SIMPLE_PAGE_URL);
Patrick Brossetfb005802020-06-03 09:40:5321
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 Brosset0805f4a2020-06-11 09:34:3235 await navigateToNetworkTab(SIMPLE_PAGE_URL);
Patrick Brossetfb005802020-06-03 09:40:5336
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 Brosset0805f4a2020-06-11 09:34:3255 await navigateToNetworkTab(SIMPLE_PAGE_URL);
Patrick Brossetfb005802020-06-03 09:40:5356
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 Brosset0805f4a2020-06-11 09:34:3264 await goTo('about:blank');
Patrick Brossetfb005802020-06-03 09:40:5365 await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1);
66 const secondPageRequestNames = await getAllRequestNames();
67
68 assert.deepStrictEqual(secondPageRequestNames, firstPageRequestNames, 'The requests were persisted');
69 });
70});