Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [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 | |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 7 | import {$, $$, click, getBrowserAndPages, goToResource, step, waitFor, waitForFunction} from '../../shared/helper.js'; |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 8 | import {describe, it} from '../../shared/mocha-extensions.js'; |
| 9 | import {checkIfTabExistsInDrawer, DRAWER_PANEL_SELECTOR} from '../helpers/cross-tool-helper.js'; |
Jack Franklin | e839c0c | 2022-05-03 08:47:44 | [diff] [blame] | 10 | import { |
| 11 | addBreakpointForLine, |
| 12 | inspectMemory, |
| 13 | openSourceCodeEditorForFile, |
Kim-Anh Tran | 812629f | 2022-11-21 12:29:49 | [diff] [blame] | 14 | PAUSE_INDICATOR_SELECTOR, |
Jack Franklin | e839c0c | 2022-05-03 08:47:44 | [diff] [blame] | 15 | reloadPageAndWaitForSourceFile, |
| 16 | RESUME_BUTTON, |
Kim-Anh Tran | 812629f | 2022-11-21 12:29:49 | [diff] [blame] | 17 | retrieveTopCallFrameWithoutResuming, |
Jack Franklin | e839c0c | 2022-05-03 08:47:44 | [diff] [blame] | 18 | } from '../helpers/sources-helpers.js'; |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 19 | |
| 20 | const LINEAR_MEMORY_INSPECTOR_TAB_SELECTOR = '#tab-linear-memory-inspector'; |
| 21 | const LINEAR_MEMORY_INSPECTOR_TABBED_PANE_SELECTOR = DRAWER_PANEL_SELECTOR + ' .tabbed-pane'; |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 22 | const LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR = '.tabbed-pane-header-tab'; |
| 23 | const LINEAR_MEMORY_INSPECTOR_TAB_TITLE_SELECTOR = '.tabbed-pane-header-tab-title'; |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 24 | |
| 25 | describe('Scope View', async () => { |
Philip Pfaffe | e3e5b76 | 2021-02-05 13:58:01 | [diff] [blame] | 26 | it('opens linear memory inspector', async () => { |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 27 | const {frontend, target} = getBrowserAndPages(); |
Al Muthanna Athamina | e31dbc1 | 2021-03-03 12:16:49 | [diff] [blame] | 28 | const breakpointLine = '0x039'; |
| 29 | const fileName = 'memory.wasm'; |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 30 | |
| 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 Pfaffe | 4dd9e8c | 2022-08-09 10:13:12 | [diff] [blame] | 40 | await reloadPageAndWaitForSourceFile(target, fileName); |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 41 | }); |
| 42 | |
Benedikt Meurer | 80399af | 2021-01-08 06:25:59 | [diff] [blame] | 43 | await step('expand the module scope', async () => { |
| 44 | await click('[aria-label="Module"]'); |
Philip Pfaffe | e3e5b76 | 2021-02-05 13:58:01 | [diff] [blame] | 45 | await waitFor('[aria-label="Module"][aria-expanded="true"]'); |
Benedikt Meurer | 80399af | 2021-01-08 06:25:59 | [diff] [blame] | 46 | }); |
| 47 | |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 48 | await step('open linear memory inspector from context menu', async () => { |
Kim-Anh Tran | dfd21e7 | 2021-04-07 10:03:44 | [diff] [blame] | 49 | await waitFor('[data-object-property-name-for-test="memories"][aria-expanded="true"]'); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 50 | await inspectMemory('$imports.memory'); |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 51 | }); |
| 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ünd | 0334537 | 2021-03-12 12:05:53 | [diff] [blame] | 60 | const titleElement = await waitFor(LINEAR_MEMORY_INSPECTOR_TAB_TITLE_SELECTOR, lmiTabbedPane); |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 61 | assert.isNotNull(titleElement); |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 62 | const title = await frontend.evaluate(x => (x as HTMLElement).innerText, titleElement); |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 63 | |
Philip Pfaffe | e3e5b76 | 2021-02-05 13:58:01 | [diff] [blame] | 64 | assert.strictEqual(title, 'Memory(100)'); |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 65 | }); |
| 66 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 67 | |
Kim-Anh Tran | 812629f | 2022-11-21 12:29:49 | [diff] [blame] | 68 | it('opens one linear memory inspector per ArrayBuffer', async () => { |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 69 | const {frontend} = getBrowserAndPages(); |
| 70 | |
| 71 | await step('navigate to a page', async () => { |
Kim-Anh Tran | 56b0b87 | 2022-04-25 10:11:47 | [diff] [blame] | 72 | await goToResource('sources/memory-workers.rawresponse'); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 73 | }); |
| 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ünd | 0334537 | 2021-03-12 12:05:53 | [diff] [blame] | 90 | const titleElement = await waitFor(LINEAR_MEMORY_INSPECTOR_TAB_TITLE_SELECTOR, lmiTabbedPane); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 91 | assert.isNotNull(titleElement); |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 92 | const title = await frontend.evaluate(x => (x as HTMLElement).innerText, titleElement); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 93 | |
Kim-Anh Tran | 56b0b87 | 2022-04-25 10:11:47 | [diff] [blame] | 94 | assert.strictEqual(title, 'SharedArrayBuffer(16)'); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 95 | }); |
| 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( |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 108 | `${LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR} + ${LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR}`, |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 109 | lmiTabbedPane); |
| 110 | // Shared buffer tab no longer active |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 111 | await waitForFunction(() => { |
| 112 | return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'false'); |
| 113 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 114 | }); |
| 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 |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 119 | await waitForFunction(() => { |
| 120 | return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'true'); |
| 121 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 122 | // There should only be two tabs |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 123 | await waitForFunction(async () => { |
| 124 | const tabs = await $$(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR, lmiTabbedPane); |
| 125 | return tabs.length === 2; |
| 126 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 127 | }); |
| 128 | |
Kim-Anh Tran | 812629f | 2022-11-21 12:29:49 | [diff] [blame] | 129 | 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 Vazac | bfbdafa | 2024-01-18 16:22:50 | [diff] [blame^] | 136 | assert.deepEqual(scriptLocation, 'memory-worker1.rawresponse:10'); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 137 | }); |
| 138 | |
| 139 | await step('open other buffer in other worker', async () => { |
| 140 | await inspectMemory('memory1'); |
| 141 | // Shared buffer tab no longer active |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 142 | await waitForFunction(() => { |
| 143 | return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'false'); |
| 144 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 145 | // Now there are three tabs |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 146 | await waitForFunction(async () => { |
| 147 | const tabs = await $$(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR, lmiTabbedPane); |
| 148 | return tabs.length === 3; |
| 149 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 150 | }); |
| 151 | |
| 152 | await step('open shared buffer in other worker', async () => { |
| 153 | await inspectMemory('sharedArr'); |
| 154 | // Shared buffer tab active again |
Randolf | cc89254 | 2023-01-27 23:44:07 | [diff] [blame] | 155 | await waitForFunction(() => { |
| 156 | return sharedBufferTab.evaluate(e => e.getAttribute('aria-selected') === 'true'); |
| 157 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 158 | // Still three tabs |
Alex Rudenko | e92fe9d | 2023-01-30 13:12:23 | [diff] [blame] | 159 | await waitForFunction(async () => { |
| 160 | const tabs = await $$(LINEAR_MEMORY_INSPECTOR_TABBED_PANE_TAB_SELECTOR, lmiTabbedPane); |
| 161 | return tabs.length === 3; |
| 162 | }); |
Eric Leese | 1890f38 | 2021-01-20 20:06:27 | [diff] [blame] | 163 | }); |
| 164 | }); |
Kim-Anh Tran | c9ec4be | 2020-11-17 06:15:32 | [diff] [blame] | 165 | }); |