[go: nahoru, domu]

blob: a6cd2cfd95eb878edc57b05e4ba0fbaabba2366f [file] [log] [blame]
Kim-Anh Tranc9ec4be2020-11-17 06:15:321// 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';
6
Randolfcc892542023-01-27 23:44:077import {$, $$, click, getBrowserAndPages, goToResource, step, waitFor, waitForFunction} from '../../shared/helper.js';
Kim-Anh Tranc9ec4be2020-11-17 06:15:328import {describe, it} from '../../shared/mocha-extensions.js';
9import {checkIfTabExistsInDrawer, DRAWER_PANEL_SELECTOR} from '../helpers/cross-tool-helper.js';
Jack Frankline839c0c2022-05-03 08:47:4410import {
11 addBreakpointForLine,
12 inspectMemory,
13 openSourceCodeEditorForFile,
Kim-Anh Tran812629f2022-11-21 12:29:4914 PAUSE_INDICATOR_SELECTOR,
Jack Frankline839c0c2022-05-03 08:47:4415 reloadPageAndWaitForSourceFile,
16 RESUME_BUTTON,
Kim-Anh Tran812629f2022-11-21 12:29:4917 retrieveTopCallFrameWithoutResuming,
Jack Frankline839c0c2022-05-03 08:47:4418} from '../helpers/sources-helpers.js';
Kim-Anh Tranc9ec4be2020-11-17 06:15:3219
20const LINEAR_MEMORY_INSPECTOR_TAB_SELECTOR = '#tab-linear-memory-inspector';
21const LINEAR_MEMORY_INSPECTOR_TABBED_PANE_SELECTOR = DRAWER_PANEL_SELECTOR + ' .tabbed-pane';
Eric Leese1890f382021-01-20 20:06:2722const LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR = '.tabbed-pane-header-tab';
23const LINEAR_MEMORY_INSPECTOR_TAB_TITLE_SELECTOR = '.tabbed-pane-header-tab-title';
Kim-Anh Tranc9ec4be2020-11-17 06:15:3224
25describe('Scope View', async () => {
Philip Pfaffee3e5b762021-02-05 13:58:0126 it('opens linear memory inspector', async () => {
Kim-Anh Tranc9ec4be2020-11-17 06:15:3227 const {frontend, target} = getBrowserAndPages();
Al Muthanna Athaminae31dbc12021-03-03 12:16:4928 const breakpointLine = '0x039';
29 const fileName = 'memory.wasm';
Kim-Anh Tranc9ec4be2020-11-17 06:15:3230
31 await step('navigate to a page and open the Sources tab', async () => {
32 await openSourceCodeEditorForFile('memory.wasm', 'wasm/memory.html');
33 });
34
35 await step(`add a breakpoint to line No.${breakpointLine}`, async () => {
36 await addBreakpointForLine(frontend, breakpointLine);
37 });
38
39 await step('reload the page', async () => {
Philip Pfaffe4dd9e8c2022-08-09 10:13:1240 await reloadPageAndWaitForSourceFile(target, fileName);
Kim-Anh Tranc9ec4be2020-11-17 06:15:3241 });
42
Benedikt Meurer80399af2021-01-08 06:25:5943 await step('expand the module scope', async () => {
44 await click('[aria-label="Module"]');
Philip Pfaffee3e5b762021-02-05 13:58:0145 await waitFor('[aria-label="Module"][aria-expanded="true"]');
Benedikt Meurer80399af2021-01-08 06:25:5946 });
47
Kim-Anh Tranc9ec4be2020-11-17 06:15:3248 await step('open linear memory inspector from context menu', async () => {
Kim-Anh Trandfd21e72021-04-07 10:03:4449 await waitFor('[data-object-property-name-for-test="memories"][aria-expanded="true"]');
Eric Leese1890f382021-01-20 20:06:2750 await inspectMemory('$imports.memory');
Kim-Anh Tranc9ec4be2020-11-17 06:15:3251 });
52
53 await step('check that linear memory inspector drawer is open', async () => {
54 const drawerIsOpen = await checkIfTabExistsInDrawer(LINEAR_MEMORY_INSPECTOR_TAB_SELECTOR);
55 assert.isTrue(drawerIsOpen);
56 });
57
58 await step('check that opened linear memory inspector has correct title', async () => {
59 const lmiTabbedPane = await waitFor(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_SELECTOR);
Simon Zünd03345372021-03-12 12:05:5360 const titleElement = await waitFor(LINEAR_MEMORY_INSPECTOR_TAB_TITLE_SELECTOR, lmiTabbedPane);
Kim-Anh Tranc9ec4be2020-11-17 06:15:3261 assert.isNotNull(titleElement);
Randolfcc892542023-01-27 23:44:0762 const title = await frontend.evaluate(x => (x as HTMLElement).innerText, titleElement);
Kim-Anh Tranc9ec4be2020-11-17 06:15:3263
Philip Pfaffee3e5b762021-02-05 13:58:0164 assert.strictEqual(title, 'Memory(100)');
Kim-Anh Tranc9ec4be2020-11-17 06:15:3265 });
66 });
Eric Leese1890f382021-01-20 20:06:2767
Kim-Anh Tran812629f2022-11-21 12:29:4968 it('opens one linear memory inspector per ArrayBuffer', async () => {
Eric Leese1890f382021-01-20 20:06:2769 const {frontend} = getBrowserAndPages();
70
71 await step('navigate to a page', async () => {
Kim-Anh Tran56b0b872022-04-25 10:11:4772 await goToResource('sources/memory-workers.rawresponse');
Eric Leese1890f382021-01-20 20:06:2773 });
74
75 await step('wait for debugging to start', async () => {
76 await waitFor(RESUME_BUTTON);
77 });
78
79 await step('open linear memory inspector from context menu', async () => {
80 await inspectMemory('sharedMem');
81 });
82
83 await step('check that linear memory inspector drawer is open', async () => {
84 const drawerIsOpen = await checkIfTabExistsInDrawer(LINEAR_MEMORY_INSPECTOR_TAB_SELECTOR);
85 assert.isTrue(drawerIsOpen);
86 });
87
88 const lmiTabbedPane = await waitFor(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_SELECTOR);
89 await step('check that opened linear memory inspector has correct title', async () => {
Simon Zünd03345372021-03-12 12:05:5390 const titleElement = await waitFor(LINEAR_MEMORY_INSPECTOR_TAB_TITLE_SELECTOR, lmiTabbedPane);
Eric Leese1890f382021-01-20 20:06:2791 assert.isNotNull(titleElement);
Randolfcc892542023-01-27 23:44:0792 const title = await frontend.evaluate(x => (x as HTMLElement).innerText, titleElement);
Eric Leese1890f382021-01-20 20:06:2793
Kim-Anh Tran56b0b872022-04-25 10:11:4794 assert.strictEqual(title, 'SharedArrayBuffer(16)');
Eric Leese1890f382021-01-20 20:06:2795 });
96
97 // Save this as we will select it multiple times
98 const sharedBufferTab = await $(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR, lmiTabbedPane);
99 if (!sharedBufferTab) {
100 // Throw here to satisfy TypeScript
101 throw new Error('Failed to get tab');
102 }
103
104 await step('open other buffer', async () => {
105 await inspectMemory('memory2');
106 // Wait until two tabs are open
107 await waitFor(
Randolfcc892542023-01-27 23:44:07108 `${LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR} + ${LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR}`,
Eric Leese1890f382021-01-20 20:06:27109 lmiTabbedPane);
110 // Shared buffer tab no longer active
Randolfcc892542023-01-27 23:44:07111 await waitForFunction(() => {
112 return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'false');
113 });
Eric Leese1890f382021-01-20 20:06:27114 });
115
116 await step('open first buffer again by way of its typed array', async () => {
117 await inspectMemory('sharedArray');
118 // Shared buffer should be selected again
Randolfcc892542023-01-27 23:44:07119 await waitForFunction(() => {
120 return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'true');
121 });
Eric Leese1890f382021-01-20 20:06:27122 // There should only be two tabs
Alex Rudenkoe92fe9d2023-01-30 13:12:23123 await waitForFunction(async () => {
124 const tabs = await $$(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR, lmiTabbedPane);
125 return tabs.length === 2;
126 });
Eric Leese1890f382021-01-20 20:06:27127 });
128
Kim-Anh Tran812629f2022-11-21 12:29:49129 await step('resume and pause in other worker (hitting a debugger statement)', async () => {
130 // Continue execution in this worker.
131 await click(RESUME_BUTTON);
132
133 // Wait until we pause in the other worker.
134 await waitFor(PAUSE_INDICATOR_SELECTOR);
135 const scriptLocation = await retrieveTopCallFrameWithoutResuming();
Charles Vazacbfbdafa2024-01-18 16:22:50136 assert.deepEqual(scriptLocation, 'memory-worker1.rawresponse:10');
Eric Leese1890f382021-01-20 20:06:27137 });
138
139 await step('open other buffer in other worker', async () => {
140 await inspectMemory('memory1');
141 // Shared buffer tab no longer active
Randolfcc892542023-01-27 23:44:07142 await waitForFunction(() => {
143 return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'false');
144 });
Eric Leese1890f382021-01-20 20:06:27145 // Now there are three tabs
Alex Rudenkoe92fe9d2023-01-30 13:12:23146 await waitForFunction(async () => {
147 const tabs = await $$(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR, lmiTabbedPane);
148 return tabs.length === 3;
149 });
Eric Leese1890f382021-01-20 20:06:27150 });
151
152 await step('open shared buffer in other worker', async () => {
153 await inspectMemory('sharedArr');
154 // Shared buffer tab active again
Randolfcc892542023-01-27 23:44:07155 await waitForFunction(() => {
156 return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'true');
157 });
Eric Leese1890f382021-01-20 20:06:27158 // Still three tabs
Alex Rudenkoe92fe9d2023-01-30 13:12:23159 await waitForFunction(async () => {
160 const tabs = await $$(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR, lmiTabbedPane);
161 return tabs.length === 3;
162 });
Eric Leese1890f382021-01-20 20:06:27163 });
164 });
Kim-Anh Tranc9ec4be2020-11-17 06:15:32165});