"use strict";
// Copyright 2023 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 recorder_helpers_js_1 = require("../helpers/recorder-helpers.js");
describe('Recorder', function () {
    if (this.timeout() !== 0) {
        this.timeout(40000);
    }
    describe('Export', () => {
        /** Mock the extension integration part and provide a test impl using RecorderPluginManager. **/
        async function createExtension(devToolsPage, inspectedPage) {
            await devToolsPage.evaluate(`
        (async function () {
          const Extensions = await import('./models/extensions/extensions.js');
          const manager = Extensions.RecorderPluginManager.RecorderPluginManager.instance();
          manager.addPlugin({
            getName() {
              return 'TestExtension';
            },
            getMediaType() {
              return 'text/javascript';
            },
            stringify() {
              return Promise.resolve('stringified');
            },
            getCapabilities() {
              return ['export'];
            }
          })
        })();
      `);
            await (0, recorder_helpers_js_1.enableAndOpenRecorderPanel)('recorder/recorder.html', devToolsPage, inspectedPage);
            await (0, recorder_helpers_js_1.createAndStartRecording)('Test', undefined, devToolsPage);
            await (0, recorder_helpers_js_1.record)(devToolsPage, inspectedPage);
            await (0, recorder_helpers_js_1.stopRecording)(devToolsPage);
        }
        const tests = [
            ['JSON', 'Test.json', '"type": "click"'],
            ['@puppeteer/replay', 'Test.js', '\'@puppeteer/replay\''],
            ['Puppeteer', 'Test.js', '\'puppeteer\''],
            ['Puppeteer (including Lighthouse analysis)', 'Test.js', '\'puppeteer\''],
            ['TestExtension', 'Test.js', 'stringified'],
        ];
        for (const [button, filename, expectedSubstring] of tests) {
            it(`should ${button.toLowerCase()}`, async ({ inspectedPage, devToolsPage }) => {
                await createExtension(devToolsPage, inspectedPage);
                const exportButton = await devToolsPage.waitForAria('Export recording');
                await exportButton.click();
                const exportMenuItem = await devToolsPage.waitForAria(button);
                await devToolsPage.evaluate(`
          window.showSaveFilePicker = (opts) => {
            window.__suggestedFilename = opts.suggestedName;
            return {
              async createWritable() {
                let data = '';
                return {
                  write(part) {
                    data += part;
                  },
                  close() {
                    window.__writtenFile = data;
                  }
                }
              }
            };
          }
        `);
                await exportMenuItem.click();
                const suggestedName = await devToolsPage.waitForFunction(async () => {
                    return await devToolsPage.evaluate('window.__suggestedFilename');
                });
                const content = (await devToolsPage.evaluate('window.__writtenFile'));
                chai_1.assert.strictEqual(suggestedName, filename);
                chai_1.assert.isTrue(content.includes(expectedSubstring));
            });
        }
    });
});
//# sourceMappingURL=export.test.js.map