blob: e7a9fe1c032f430e111cd665ba09f150273a2826 [file] [log] [blame]
// 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.
import {BackgroundImage, Theme, ThirdPartyThemeInfo} from 'chrome://customize-chrome-side-panel.top-chrome/customize_chrome.mojom-webui.js';
import {assertEquals, assertNotEquals} from 'chrome://webui-test/chai_assert.js';
import {TestBrowserProxy} from 'chrome://webui-test/test_browser_proxy.js';
type Constructor<T> = new (...args: any[]) => T;
type Installer<T> = (instance: T) => void;
export function installMock<T extends object>(
clazz: Constructor<T>, installer?: Installer<T>): TestBrowserProxy<T> {
installer = installer ||
(clazz as unknown as {setInstance: Installer<T>}).setInstance;
const mock = TestBrowserProxy.fromClass(clazz);
installer!(mock);
return mock;
}
export function assertStyle(element: Element, name: string, expected: string) {
const actual = window.getComputedStyle(element).getPropertyValue(name).trim();
assertEquals(expected, actual);
}
export function assertNotStyle(element: Element, name: string, not: string) {
const actual = window.getComputedStyle(element).getPropertyValue(name).trim();
assertNotEquals(not, actual);
}
/**
* Queries |selector| on |element|'s shadow root and returns the resulting
* element if there is any.
*/
export function $$<E extends Element = Element>(
element: Element, selector: string): E|null;
export function $$(element: Element, selector: string) {
return element.shadowRoot!.querySelector(selector);
}
export function createBackgroundImage(url: string): BackgroundImage {
return {
url: {url},
snapshotUrl: {url},
isUploadedImage: false,
title: '',
mainColor: undefined,
};
}
export function createThirdPartyThemeInfo(
id: string, name: string): ThirdPartyThemeInfo {
return {
id: id,
name: name,
};
}
export function createTheme(systemDarkMode = false): Theme {
return {
backgroundImage: undefined,
thirdPartyThemeInfo: undefined,
systemDarkMode,
seedColor: {value: 0xff0000ff},
backgroundColor: {value: 0xffff0000},
foregroundColor: undefined,
colorPickerIconColor: {value: 0xffff0000},
colorsManagedByPolicy: false,
};
}
export function capture(
target: HTMLElement, event: string): {received: boolean} {
const capture = {received: false};
target.addEventListener(event, () => capture.received = true);
return capture;
}