"use strict";
// Copyright 2020 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 helper_js_1 = require("../../shared/helper.js");
const console_helpers_js_1 = require("../helpers/console-helpers.js");
describe('The Console Tab', () => {
    it('interacts with the global scope correctly', async ({ devToolsPage }) => {
        await (0, helper_js_1.step)('navigate to the Console tab', async () => {
            await devToolsPage.click(console_helpers_js_1.CONSOLE_TAB_SELECTOR);
            await (0, console_helpers_js_1.focusConsolePrompt)(devToolsPage);
        });
        await (0, helper_js_1.step)('enter code that implicitly creates global properties', async () => {
            await devToolsPage.pasteText(`
        var foo = 'fooValue';
        var bar = {
          a: 'b',
        };
      `);
            await devToolsPage.pressKey('Enter');
            // Wait for the console to be usable again.
            await devToolsPage.waitForFunction(async () => {
                return (await devToolsPage.$$('.console-user-command-result')).length === 1;
            });
        });
        await (0, helper_js_1.step)('enter code that references the created bindings', async () => {
            // TODO: it should actually wait for rendering to finish.
            await devToolsPage.drainTaskQueue();
            await devToolsPage.pasteText('foo;');
            await devToolsPage.pressKey('Enter');
            // Wait for the console to be usable again.
            await devToolsPage.waitForFunction(async () => {
                return (await devToolsPage.$$('.console-user-command-result')).length === 2;
            });
            // TODO: it should actually wait for rendering to finish.
            await devToolsPage.drainTaskQueue();
            await devToolsPage.pasteText('bar;');
            await devToolsPage.pressKey('Enter');
        });
        await (0, helper_js_1.step)('check that the expected output is logged', async () => {
            // TODO: it should actually wait for rendering to finish.
            await devToolsPage.drainTaskQueue();
            const messages = await (0, console_helpers_js_1.getCurrentConsoleMessages)(false, undefined, undefined, devToolsPage);
            chai_1.assert.deepEqual(messages, [
                'undefined',
                '\'fooValue\'',
                '{a: \'b\'}',
            ]);
        });
    });
});
//# sourceMappingURL=console-eval-global.test.js.map