"use strict";
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const events_js_1 = require("../../conductor/events.js");
const application_helpers_js_1 = require("../helpers/application-helpers.js");
const datagrid_helpers_js_1 = require("../helpers/datagrid-helpers.js");
const SITE = 'https://localhost';
describe('The Application Tab', () => {
    it('shows Shared Storage events', async ({ devToolsPage, inspectedPage }) => {
        await (0, application_helpers_js_1.navigateToApplicationTab)('shared-storage', devToolsPage, inspectedPage);
        await (0, application_helpers_js_1.navigateToSharedStorage)(devToolsPage);
        await inspectedPage.goToResource('application/shared-storage.html');
        const dataGrid = await (0, datagrid_helpers_js_1.getDataGrid)(undefined, devToolsPage);
        const innerText = await (0, datagrid_helpers_js_1.getInnerTextOfDataGridCells)(dataGrid, 3, false, devToolsPage);
        chai_1.assert.strictEqual(innerText[0][1], 'window');
        chai_1.assert.strictEqual(innerText[0][2], 'clear');
        chai_1.assert.strictEqual(innerText[0][3], inspectedPage.domain());
        chai_1.assert.strictEqual(innerText[0][4], SITE);
        chai_1.assert.strictEqual(innerText[0][5], '{}');
        chai_1.assert.strictEqual(innerText[1][1], 'window');
        chai_1.assert.strictEqual(innerText[1][2], 'set');
        chai_1.assert.strictEqual(innerText[1][3], inspectedPage.domain());
        chai_1.assert.strictEqual(innerText[1][4], SITE);
        chai_1.assert.strictEqual(innerText[1][5], '{"key":"firstKey","value":"firstValue","ignoreIfPresent":false}');
        chai_1.assert.strictEqual(innerText[2][1], 'window');
        chai_1.assert.strictEqual(innerText[2][2], 'append');
        chai_1.assert.strictEqual(innerText[2][3], inspectedPage.domain());
        chai_1.assert.strictEqual(innerText[2][4], SITE);
        chai_1.assert.strictEqual(innerText[2][5], '{"key":"secondKey","value":"{\\"field\\":\\"complexValue\\",\\"primitive\\":2}"}');
        const rows = await (0, datagrid_helpers_js_1.getDataGridRows)(3, dataGrid, false, devToolsPage);
        await devToolsPage.clickElement(rows[rows.length - 1][0]);
        const jsonView = await devToolsPage.waitFor('.json-view');
        const jsonViewText = await jsonView.evaluate(el => el.innerText);
        const accessTimeString = jsonViewText.substring('{accessTime: '.length, jsonViewText.indexOf(', scope:'));
        chai_1.assert.strictEqual(jsonViewText, `{accessTime: ${accessTimeString}, scope: "window", method: "append",…}`);
    });
    it('shows Shared Storage metadata', async ({ devToolsPage, inspectedPage }) => {
        await (0, application_helpers_js_1.navigateToApplicationTab)('shared-storage', devToolsPage, inspectedPage);
        await (0, application_helpers_js_1.navigateToSharedStorageForTopDomain)(devToolsPage, inspectedPage);
        const fieldValues = await (0, application_helpers_js_1.getTrimmedTextContent)('devtools-report-value', devToolsPage);
        const timeString = fieldValues[0]; // Creation time is the first field for main frame
        // Origin is no longer displayed for main frame contexts.
        chai_1.assert.deepEqual(fieldValues, [timeString, '2', '130', '12']);
    });
    it('shows Shared Storage keys and values', async ({ devToolsPage, inspectedPage }) => {
        await (0, application_helpers_js_1.navigateToApplicationTab)('shared-storage', devToolsPage, inspectedPage);
        await (0, application_helpers_js_1.navigateToSharedStorageForTopDomain)(devToolsPage, inspectedPage);
        const dataGridRowValues = await (0, application_helpers_js_1.getStorageItemsData)(['key', 'value'], 2, devToolsPage);
        chai_1.assert.deepEqual(dataGridRowValues, [
            {
                key: 'firstKey',
                value: 'firstValue',
            },
            {
                key: 'secondKey',
                value: '{"field":"complexValue","primitive":2}',
            },
        ]);
        const dataGrid = await (0, datagrid_helpers_js_1.getDataGrid)(undefined, devToolsPage);
        const rows = await (0, datagrid_helpers_js_1.getDataGridRows)(3, dataGrid, false, devToolsPage);
        await devToolsPage.clickElement(rows[1][0]);
        const jsonView = await devToolsPage.waitFor('.json-view');
        const jsonViewText = await jsonView.evaluate(el => el.innerText);
        chai_1.assert.strictEqual(jsonViewText, '{key: "secondKey", value: "{"field":"complexValue","primitive":2}"}');
        (0, events_js_1.expectError)('Request CacheStorage.requestCacheNames failed. {"code":-32602,"message":"Invalid security origin"}');
    });
});
//# sourceMappingURL=shared-storage.test.js.map