"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 settings_helpers_js_1 = require("../helpers/settings-helpers.js");
const helpers_js_1 = require("./helpers.js");
async function assertValidationFails(inputElement, value, devToolsPage) {
    await inputElement.type(value.toString());
    chai_1.assert.strictEqual(await (0, helpers_js_1.getInputFieldValue)(inputElement), value.toString());
    await devToolsPage.tabForward();
    chai_1.assert.isTrue(await inputElement.evaluate(element => element.matches(':invalid')));
    // Clean up so that this function can be called again.
    const resetButton = await devToolsPage.waitFor('.orientation-reset-button');
    await resetButton.click();
    await devToolsPage.waitForNone(':invalid');
}
describe('Orientation emulation on Sensors panel', () => {
    it('presets correct default values on Custom orientation selected', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openPanelViaMoreTools)('Sensors', devToolsPage);
        await (0, helpers_js_1.setCustomOrientation)(devToolsPage);
        const actualOrientations = await (0, helpers_js_1.getOrientationValues)(devToolsPage);
        const expectedOrientations = [0, 90, 0];
        chai_1.assert.deepEqual(actualOrientations, expectedOrientations);
    });
    it('highlights values outside the allowed ranges', async ({ devToolsPage }) => {
        await (0, settings_helpers_js_1.openPanelViaMoreTools)('Sensors', devToolsPage);
        await (0, helpers_js_1.setCustomOrientation)(devToolsPage);
        const [alpha, beta, gamma] = await (0, helpers_js_1.getOrientationInputs)(devToolsPage);
        // Alpha must be in the range [0, 360).
        await assertValidationFails(alpha, -0.1, devToolsPage);
        await assertValidationFails(alpha, 360, devToolsPage);
        // Beta must be in the range [-180, 180).
        await assertValidationFails(beta, -180.1, devToolsPage);
        await assertValidationFails(beta, 180, devToolsPage);
        // Gamma must be in the range [-90, 90).
        await assertValidationFails(gamma, -90.1, devToolsPage);
        await assertValidationFails(gamma, 90, devToolsPage);
    });
});
//# sourceMappingURL=orientation.test.js.map