blob: c8460cef09fcd22bafb658abfdc1354f7cdb73a6 [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
8import {getBrowserAndPages} from '../../shared/helper.js';
9import {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
14describe('The Network Tab', async () => {
15 it('displays requests', async () => {
16 const {target} = getBrowserAndPages();
17 await navigateToNetworkTab(target, SIMPLE_PAGE_URL);
18
19 // Wait for all the requests to be displayed + 1 to account for the page itself.
20 await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1);
21
22 const expectedNames = [SIMPLE_PAGE_URL];
23 for (let i = 0; i < SIMPLE_PAGE_REQUEST_NUMBER; i++) {
24 expectedNames.push(`image.svg?id=${i}`);
25 }
26
27 const names = await getAllRequestNames();
28 assert.deepStrictEqual(names, expectedNames, 'The right request names should appear in the list');
29 });
30
31 it('can select requests', async () => {
32 const {target} = getBrowserAndPages();
33 await navigateToNetworkTab(target, SIMPLE_PAGE_URL);
34
35 let selected = await getSelectedRequestName();
36 assert.isUndefined(selected, 'No request should be selected by default');
37
38 await selectRequestByName(SIMPLE_PAGE_URL);
39 await waitForSelectedRequestChange(selected);
40
41 selected = await getSelectedRequestName();
42 assert.strictEqual(selected, SIMPLE_PAGE_URL, 'Selecting the first request should work');
43
44 const lastRequestName = `image.svg?id=${SIMPLE_PAGE_REQUEST_NUMBER - 1}`;
45 await selectRequestByName(lastRequestName);
46 await waitForSelectedRequestChange(selected);
47
48 selected = await getSelectedRequestName();
49 assert.strictEqual(selected, lastRequestName, 'Selecting the last request should work');
50 });
51
52 it('can persist requests', async () => {
53 const {target} = getBrowserAndPages();
54 await navigateToNetworkTab(target, SIMPLE_PAGE_URL);
55
56 // Wait for all the requests to be displayed + 1 to account for the page itself, and get their names.
57 await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1);
58 const firstPageRequestNames = await getAllRequestNames();
59
60 await togglePersistLog();
61
62 // Navigate to a new page, and wait for the same requests to still be there.
63 await target.goto('about:blank');
64 await waitForSomeRequestsToAppear(SIMPLE_PAGE_REQUEST_NUMBER + 1);
65 const secondPageRequestNames = await getAllRequestNames();
66
67 assert.deepStrictEqual(secondPageRequestNames, firstPageRequestNames, 'The requests were persisted');
68 });
69});