Skip to content

Commit 109931c

Browse files
Liviu RauDevtools-frontend LUCI CQ
authored andcommitted
Port application/storage_test to non-hosted
Bug: 347114248, 416404745 Change-Id: I572f24e6be556acf34158a9146a45279cca7cf0a Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6616883 Reviewed-by: Alex Rudenko <alexrudenko@chromium.org> Commit-Queue: Liviu Rau <liviurau@chromium.org>
1 parent bd85b22 commit 109931c

4 files changed

Lines changed: 43 additions & 42 deletions

File tree

test/e2e/application/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ node_ts_library("application") {
88
sources = [
99
"frame-tree_test.ts",
1010
"shared-storage_test.ts",
11-
"storage_test.ts",
1211
"window-controls_test.ts",
1312
]
1413

test/e2e/helpers/application-helpers.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import type {DevToolsPage} from '../../e2e_non_hosted/shared/frontend-helper.js'
88
import {
99
$$,
1010
click,
11-
getBrowserAndPages,
1211
getTestServerPort,
1312
waitFor,
14-
waitForFunction,
1513
} from '../../shared/helper.js';
1614
import {getBrowserAndPagesWrappers} from '../../shared/non_hosted_wrappers.js';
1715

@@ -61,14 +59,16 @@ export async function navigateToManifestInApplicationTab(testName: string) {
6159
await click(MANIFEST_SELECTOR);
6260
}
6361

64-
export async function navigateToStorage() {
62+
export async function navigateToStorage(devToolsPage = getBrowserAndPagesWrappers().devToolsPage) {
6563
const STORAGE_SELECTOR = '[aria-label="Storage"]';
66-
await click(STORAGE_SELECTOR);
67-
await waitFor('.clear-storage-button');
68-
await expectVeEvents([
69-
veClick('Panel: resources > Pane: sidebar > Tree > TreeItem: application > TreeItem: storage'),
70-
veImpressionsUnder('Panel: resources', [veImpressionForStorageOverview()]),
71-
]);
64+
await devToolsPage.click(STORAGE_SELECTOR);
65+
await devToolsPage.waitFor('.clear-storage-button');
66+
await expectVeEvents(
67+
[
68+
veClick('Panel: resources > Pane: sidebar > Tree > TreeItem: application > TreeItem: storage'),
69+
veImpressionsUnder('Panel: resources', [veImpressionForStorageOverview()]),
70+
],
71+
undefined, devToolsPage);
7272
}
7373

7474
export async function navigateToOpenedWindows() {
@@ -318,17 +318,17 @@ export async function selectCookieByName(name: string, devToolsPage = getBrowser
318318
[veClick('Panel: resources > Pane: cookies-data > TableRow > TableCell: name')], undefined, devToolsPage);
319319
}
320320

321-
export async function waitForQuotaUsage(p: (quota: number) => boolean) {
322-
const {frontend} = getBrowserAndPages();
323-
await frontend.bringToFront();
324-
await waitForFunction(async () => {
325-
const usedQuota = await getQuotaUsage();
321+
export async function waitForQuotaUsage(
322+
p: (quota: number) => boolean, devToolsPage = getBrowserAndPagesWrappers().devToolsPage) {
323+
await devToolsPage.bringToFront();
324+
await devToolsPage.waitForFunction(async () => {
325+
const usedQuota = await getQuotaUsage(devToolsPage);
326326
return p(usedQuota);
327327
});
328328
}
329329

330-
export async function getQuotaUsage() {
331-
const storageRow = await waitFor('.quota-usage-row');
330+
export async function getQuotaUsage(devToolsPage = getBrowserAndPagesWrappers().devToolsPage) {
331+
const storageRow = await devToolsPage.waitFor('.quota-usage-row');
332332
const quotaString = await storageRow.evaluate(el => el.textContent || '');
333333
const [usedQuotaText, modifier] =
334334
quotaString.replaceAll(',', '').replace(/^\D*([\d.]+)\D*(kM?)B.used.out.of\D*\d+\D*.?B.*$/, '$1 $2').split(' ');
@@ -341,8 +341,8 @@ export async function getQuotaUsage() {
341341
return usedQuota;
342342
}
343343

344-
export async function getPieChartLegendRows() {
345-
const pieChartLegend = await waitFor('.pie-chart-legend');
344+
export async function getPieChartLegendRows(devToolsPage = getBrowserAndPagesWrappers().devToolsPage) {
345+
const pieChartLegend = await devToolsPage.waitFor('.pie-chart-legend');
346346
const rows = await pieChartLegend.evaluate(legend => {
347347
const rows = [];
348348
for (const tableRow of legend.children) {

test/e2e_non_hosted/application/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ts_e2e_library("application") {
1212
"service-worker-network_test.ts",
1313
"service-worker-update_test.ts",
1414
"session-storage_test.ts",
15+
"storage_test.ts",
1516
]
1617

1718
deps = [

test/e2e/application/storage_test.ts renamed to test/e2e_non_hosted/application/storage_test.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,34 @@
44

55
import {assert} from 'chai';
66

7-
import {click, getBrowserAndPages, waitForFunction} from '../../shared/helper.js';
87
import {
98
getPieChartLegendRows,
109
getQuotaUsage,
1110
navigateToApplicationTab,
1211
navigateToStorage,
1312
waitForQuotaUsage,
14-
} from '../helpers/application-helpers.js';
13+
} from '../../e2e/helpers/application-helpers.js';
14+
import type {DevToolsPage} from '../shared/frontend-helper.js';
15+
import type {InspectedPage} from '../shared/target-helper.js';
1516

1617
// The parent suffix makes sure we wait for the Cookies item to have children before trying to click it.
1718
const CLEAR_SITE_DATA_BUTTON_SELECTOR = '#storage-view-clear-button';
1819

20+
async function navigateToAppStorage(devToolsPage: DevToolsPage, inspectedPage: InspectedPage) {
21+
await navigateToApplicationTab('storage-quota', devToolsPage, inspectedPage);
22+
await navigateToStorage(devToolsPage);
23+
}
24+
1925
describe('The Application Tab', () => {
2026
describe('contains a Storage pane', function() {
21-
// The tests in this suite are particularly slow, as they perform a lot of actions
22-
this.timeout(20000);
23-
beforeEach(async () => {
24-
await navigateToApplicationTab('storage-quota');
25-
await navigateToStorage();
26-
});
27+
// TODO (liviurau): Update navigateToApplicationTab helper to work in docked
28+
// mode and remove the setup below.
29+
setup({dockingMode: 'undocked'});
2730

28-
it('which clears storage correctly using the clear button', async () => {
29-
const {target} = getBrowserAndPages();
30-
await target.bringToFront();
31-
await target.evaluate(async () => {
31+
it('which clears storage correctly using the clear button', async ({devToolsPage, inspectedPage}) => {
32+
await navigateToAppStorage(devToolsPage, inspectedPage);
33+
await inspectedPage.bringToFront();
34+
await inspectedPage.evaluate(async () => {
3235
const array: number[] = [];
3336
for (let i = 0; i < 20000; i++) {
3437
array.push(i % 10);
@@ -41,23 +44,21 @@ describe('The Application Tab', () => {
4144
await new Promise(resolve => addIDBValue(resolve, 'Database1', 'Store1', {key: 1, value: array}, ''));
4245
});
4346

44-
await waitForQuotaUsage(quota => quota > 800);
47+
await waitForQuotaUsage(quota => quota > 800, devToolsPage);
4548

4649
// We may click too early. If the total quota exceeds 2999, some remaining
4750
// quota may show. Instead,
4851
// try to click another time, if necessary.
49-
await waitForFunction(async () => {
50-
await click(CLEAR_SITE_DATA_BUTTON_SELECTOR, {clickOptions: {delay: 250}});
51-
const quota = await getQuotaUsage();
52+
await devToolsPage.waitForFunction(async () => {
53+
await devToolsPage.click(CLEAR_SITE_DATA_BUTTON_SELECTOR, {clickOptions: {delay: 250}});
54+
const quota = await getQuotaUsage(devToolsPage);
5255
return quota === 0;
5356
});
5457
});
5558

56-
// Fails because backend does not report IndexedDb quoate after clearing site data.
57-
it.skip('[crbug.com/347114248] which reports storage correctly, including the pie chart legend', async () => {
58-
const {target} = getBrowserAndPages();
59-
60-
await target.evaluate(async () => {
59+
it('which reports storage correctly, including the pie chart legend', async ({devToolsPage, inspectedPage}) => {
60+
await navigateToAppStorage(devToolsPage, inspectedPage);
61+
await inspectedPage.evaluate(async () => {
6162
const array: number[] = [];
6263
for (let i = 0; i < 20000; i++) {
6364
array.push(i % 10);
@@ -70,9 +71,9 @@ describe('The Application Tab', () => {
7071
await new Promise(resolve => addIDBValue(resolve, 'Database1', 'Store1', {key: 1, value: array}, ''));
7172
});
7273

73-
await waitForQuotaUsage(quota => quota > 800);
74+
await waitForQuotaUsage(quota => quota > 800, devToolsPage);
7475

75-
const rows = await getPieChartLegendRows();
76+
const rows = await getPieChartLegendRows(devToolsPage);
7677
// Only assert that the legend entries are correct.
7778
assert.lengthOf(rows, 2);
7879
assert.strictEqual(rows[0][2], 'IndexedDB');

0 commit comments

Comments
 (0)