"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 settings_helpers_js_1 = require("../helpers/settings-helpers.js");
describe('Idle Emulation on Sensors panel', () => {
    async function getState(inspectedPage) {
        return await inspectedPage.evaluate(() => {
            const state = document.getElementById('state');
            return state ? state.innerText : '';
        });
    }
    async function waitForState(state, inspectedPage) {
        await (0, helper_js_1.step)(`Waiting for state \'${state}\'`, async () => {
            await inspectedPage.page.waitForFunction((_state) => {
                const stateEl = document.getElementById('state');
                return _state === (stateEl ? stateEl.innerText : '');
            }, {}, state);
        });
    }
    it('includes UI for emulating an idle state', async ({ devToolsPage, inspectedPage }) => {
        await inspectedPage.overridePermissions(['idle-detection']);
        await (0, settings_helpers_js_1.openPanelViaMoreTools)('Sensors', devToolsPage);
        const select = await devToolsPage.waitFor('.idle-section select');
        const actual = await select.evaluate(node => node.textContent);
        const expected = [
            'No idle emulation',
            'User active, screen unlocked',
            'User active, screen locked',
            'User idle, screen unlocked',
            'User idle, screen locked',
        ].join('');
        chai_1.assert.deepEqual(actual, expected);
    });
    it('changing idle state emulation causes change of the IdleDetector state', async ({ devToolsPage, inspectedPage }) => {
        await inspectedPage.overridePermissions(['idle-detection']);
        await (0, settings_helpers_js_1.openPanelViaMoreTools)('Sensors', devToolsPage);
        await (0, helper_js_1.step)('opening idle-detector.html', async () => {
            await inspectedPage.goToResource('sensors/idle-detector.html');
        });
        const select = await (await devToolsPage.waitFor('.idle-section select')).toElement('select');
        // InitialState can be idle as well.
        const initialState = await getState(inspectedPage);
        // Emulate Idle states and verify IdleDetector updates state accordingly.
        await (0, helper_js_1.selectOption)(select, '{"isUserActive":false,"isScreenUnlocked":false}');
        await waitForState('Idle state: idle, locked.', inspectedPage);
        await (0, helper_js_1.selectOption)(select, '{"isUserActive":true,"isScreenUnlocked":false}');
        await waitForState('Idle state: active, locked.', inspectedPage);
        await (0, helper_js_1.selectOption)(select, '{"isUserActive":true,"isScreenUnlocked":true}');
        await waitForState('Idle state: active, unlocked.', inspectedPage);
        await (0, helper_js_1.selectOption)(select, '{"isUserActive":false,"isScreenUnlocked":true}');
        await waitForState('Idle state: idle, unlocked.', inspectedPage);
        // Remove Idle emulation and verify IdleDetector is in initial state.
        await (0, helper_js_1.selectOption)(select, 'none');
        await waitForState(initialState, inspectedPage);
    });
});
//# sourceMappingURL=idle.test.js.map