Skip to content

Commit

Permalink
ProfilePicker/Signin: Migrate tests files to TypeScript, part3.
Browse files Browse the repository at this point in the history
Migrating all remaining files and removing allowJs from
tsconfig_base.json.

Fixed: 1266780
Change-Id: I5f0c41c9334570be886ee475fdf5dbb4444d1234
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3267951
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: Alex Ilin <alexilin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#939887}
  • Loading branch information
freshp86 authored and Chromium LUCI CQ committed Nov 9, 2021
1 parent 0fd556a commit bf01a67
Show file tree
Hide file tree
Showing 20 changed files with 345 additions and 323 deletions.
Expand Up @@ -10,6 +10,7 @@ import './signin_shared_css.js';
import './signin_vars_css.js';
import './strings.m.js';

import {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {WebUIListenerMixin} from 'chrome://resources/js/web_ui_listener_mixin.js';
import {afterNextRender, html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
Expand All @@ -18,6 +19,13 @@ import {DiceWebSigninInterceptBrowserProxy, DiceWebSigninInterceptBrowserProxyIm

const DiceWebSigninInterceptAppElementBase = WebUIListenerMixin(PolymerElement);

export interface DiceWebSigninInterceptAppElement {
$: {
cancelButton: CrButtonElement,
acceptButton: CrButtonElement,
};
}

export class DiceWebSigninInterceptAppElement extends
DiceWebSigninInterceptAppElementBase {
static get is() {
Expand Down Expand Up @@ -105,5 +113,11 @@ export class DiceWebSigninInterceptAppElement extends
}
}

declare global {
interface HTMLElementTagNameMap {
'dice-web-signin-intercept-app': DiceWebSigninInterceptAppElement;
}
}

customElements.define(
DiceWebSigninInterceptAppElement.is, DiceWebSigninInterceptAppElement);
Expand Up @@ -10,6 +10,7 @@ import './strings.m.js';
import './signin_shared_css.js';
import './signin_vars_css.js';

import {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {WebUIListenerMixin} from 'chrome://resources/js/web_ui_listener_mixin.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
Expand All @@ -30,6 +31,13 @@ document.addEventListener('DOMContentLoaded', () => {
document.body.style.width = 'auto';
});

export interface EnterpriseProfileWelcomeAppElement {
$: {
cancelButton: CrButtonElement,
proceedButton: CrButtonElement,
};
}

const EnterpriseProfileWelcomeAppElementBase =
WebUIListenerMixin(PolymerElement);

Expand Down Expand Up @@ -120,5 +128,11 @@ export class EnterpriseProfileWelcomeAppElement extends
}
}

declare global {
interface HTMLElementTagNameMap {
'enterprise-profile-welcome-app': EnterpriseProfileWelcomeAppElement;
}
}

customElements.define(
EnterpriseProfileWelcomeAppElement.is, EnterpriseProfileWelcomeAppElement);
Expand Up @@ -17,7 +17,9 @@ export type ProfileState = {
userName: string,
isManaged: boolean,
avatarIcon: string,
// <if expr="lacros">
isPrimaryLacrosProfile: boolean,
// </if>
};

/**
Expand Down
Expand Up @@ -18,7 +18,7 @@ import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/poly

import {ManageProfilesBrowserProxy, ManageProfilesBrowserProxyImpl, ProfileState} from './manage_profiles_browser_proxy.js';

interface ProfileCardElement {
export interface ProfileCardElement {
$: {
gaiaName: HTMLElement,
gaiaNameTooltip: PaperTooltipElement,
Expand All @@ -29,7 +29,7 @@ interface ProfileCardElement {

const ProfileCardElementBase = I18nMixin(PolymerElement);

class ProfileCardElement extends ProfileCardElementBase {
export class ProfileCardElement extends ProfileCardElementBase {
static get is() {
return 'profile-card';
}
Expand Down
Expand Up @@ -114,5 +114,11 @@ export class AccountSelectionLacrosElement extends
}
}

declare global {
interface HTMLElementTagNameMap {
'account-selection-lacros': AccountSelectionLacrosElement;
}
}

customElements.define(
AccountSelectionLacrosElement.is, AccountSelectionLacrosElement);
Expand Up @@ -7,6 +7,7 @@ import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.m.js';
import 'chrome://resources/cr_elements/shared_vars_css.m.js';
import './shared_css.js';

import {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {focusWithoutInk} from 'chrome://resources/js/cr/ui/focus_without_ink.m.js';
import {I18nMixin} from 'chrome://resources/js/i18n_mixin.js';
Expand All @@ -22,8 +23,11 @@ import {navigateTo, navigateToPreviousRoute, navigateToStep, ProfileCreationStep

export interface ProfileTypeChoiceElement {
$: {
backButton: HTMLElement,
notNowButton: HTMLElement,
backButton: CrButtonElement,
// <if expr="not lacros">
notNowButton: CrButtonElement,
// </if>
signInButton: CrButtonElement,
};
}

Expand Down
Expand Up @@ -2,9 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

export {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
export {ensureLazyLoaded} from './ensure_lazy_loaded.js';
export {AutogeneratedThemeColorInfo, ManageProfilesBrowserProxy, ManageProfilesBrowserProxyImpl, ProfileState, UserThemeChoice} from './manage_profiles_browser_proxy.js';
export {navigateTo, navigateToStep, NavigationMixin, ProfileCreationSteps, Routes} from './navigation_mixin.js';

// <if expr="lacros">
export {UnassignedAccount} from './manage_profiles_browser_proxy.js';
// </if>

export {navigateTo, navigateToStep, NavigationMixin, NavigationMixinInterface, ProfileCreationSteps, Routes} from './navigation_mixin.js';
export {ProfileCardElement} from './profile_card.js';
export {ProfileCardMenuElement, Statistics, StatisticsResult} from './profile_card_menu.js';
export {ProfilePickerAppElement} from './profile_picker_app.js';
export {ProfilePickerMainViewElement} from './profile_picker_main_view.js';
Expand Up @@ -189,7 +189,7 @@ <h3>$i18n{mainViewSubtitle}</h3>
<iron-icon icon="profiles:account-circle"></iron-icon>
<div>$i18n{browseAsGuestButton}</div>
</cr-button>
<cr-checkbox checked="{{askOnStartup_}}"
<cr-checkbox id="askOnStartup" checked="{{askOnStartup_}}"
on-change="onAskOnStartupChangedByUser_" hidden$="[[hideAskOnStartup_]]">
$i18n{askOnStartupCheckboxText}
</cr-checkbox>
Expand Down
Expand Up @@ -13,6 +13,7 @@ import './profile_card.js';
import './profile_picker_shared_css.js';
import './strings.m.js';

import {CrCheckboxElement} from 'chrome://resources/cr_elements/cr_checkbox/cr_checkbox.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {WebUIListenerMixin} from 'chrome://resources/js/web_ui_listener_mixin.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
Expand All @@ -24,9 +25,11 @@ import {isAskOnStartupAllowed, isGuestModeEnabled, isProfileCreationAllowed} fro
export interface ProfilePickerMainViewElement {
$: {
addProfile: HTMLElement,
askOnStartup: CrCheckboxElement,
'product-logo': HTMLElement,
browseAsGuestButton: HTMLElement,
profilesContainer: HTMLElement,
wrapper: HTMLElement,
};
}

Expand Down
Expand Up @@ -25,7 +25,7 @@ type AccountInfo = {

const SyncConfirmationAppElementBase = WebUIListenerMixin(PolymerElement);

class SyncConfirmationAppElement extends SyncConfirmationAppElementBase {
export class SyncConfirmationAppElement extends SyncConfirmationAppElementBase {
static get is() {
return 'sync-confirmation-app';
}
Expand Down Expand Up @@ -142,5 +142,11 @@ class SyncConfirmationAppElement extends SyncConfirmationAppElementBase {
}
}

declare global {
interface HTMLElementTagNameMap {
'sync-confirmation-app': SyncConfirmationAppElement;
}
}

customElements.define(
SyncConfirmationAppElement.is, SyncConfirmationAppElement);
18 changes: 10 additions & 8 deletions chrome/test/data/webui/signin/BUILD.gn
Expand Up @@ -11,33 +11,35 @@ assert(!is_chromeos_ash)

# Test files that contain // <if expr> and therefore require preprocessing.
preprocessed_files = [
"local_profile_customization_focus_test.ts",
"profile_card_menu_test.ts",
"profile_picker_app_test.js",
"profile_picker_app_test.ts",
"profile_picker_main_view_test.ts",
"test_manage_profiles_browser_proxy.ts",
]

# Test files that do not require preprocessing. If adding // <if expr> to any
# file below, move it to the list above.
non_preprocessed_files = [
"account_selection_lacros_test.js",
"dice_web_signin_intercept_test.js",
"enterprise_profile_welcome_test.js",
"local_profile_customization_focus_test.ts",
"local_profile_customization_interactive_ui_test.js",
"dice_web_signin_intercept_test.ts",
"enterprise_profile_welcome_test.ts",
"local_profile_customization_test.ts",
"profile_customization_test.ts",
"profile_picker_main_view_test.js",
"profile_switch_test.ts",
"profile_type_choice_test.ts",
"signin_reauth_test.ts",
"sync_confirmation_test.js",
"sync_confirmation_test.ts",
"test_dice_web_signin_intercept_browser_proxy.ts",
"test_enterprise_profile_welcome_browser_proxy.ts",
"test_profile_customization_browser_proxy.ts",
"test_signin_reauth_browser_proxy.ts",
"test_sync_confirmation_browser_proxy.ts",
]

if (is_chromeos_lacros) {
non_preprocessed_files += [ "account_selection_lacros_test.ts" ]
}

preprocessed_folder = "$target_gen_dir/preprocessed"

preprocess_if_expr("preprocess") {
Expand Down
Expand Up @@ -5,36 +5,29 @@
import 'chrome://profile-picker/lazy_load.js';

import {AccountSelectionLacrosElement} from 'chrome://profile-picker/lazy_load.js';
import {ensureLazyLoaded, ManageProfilesBrowserProxyImpl} from 'chrome://profile-picker/profile_picker.js';
import {ensureLazyLoaded, ManageProfilesBrowserProxyImpl, UnassignedAccount} from 'chrome://profile-picker/profile_picker.js';
import {webUIListenerCallback} from 'chrome://resources/js/cr.m.js';
import {assertEquals, assertTrue} from 'chrome://webui-test/chai_assert.js';
import {flushTasks, isChildVisible, waitBeforeNextRender} from 'chrome://webui-test/test_util.js';

import {assertTrue} from '../chai_assert.js';
import {flushTasks, isChildVisible, waitBeforeNextRender} from '../test_util.js';
import {TestManageProfilesBrowserProxy} from './test_manage_profiles_browser_proxy.js';

suite('ProfileTypeChoiceTest', function() {
/** @type {!AccountSelectionLacrosElement} */
let testElement;

/** @type {!TestManageProfilesBrowserProxy} */
let browserProxy;
let testElement: AccountSelectionLacrosElement;
let browserProxy: TestManageProfilesBrowserProxy;

/**
* @param {number} n Indicates the desired number of accounts.
* @return {!Array<!UnassignedAccounts>} Array of accounts.
* @param n Indicates the desired number of accounts.
*/
function generateAccountsList(n) {
return Array(n).fill(null).map((x, i) => ({
function generateAccountsList(n: number): UnassignedAccount[] {
return Array(n).fill(null).map((_x, i) => ({
gaiaId: `gaia-id-${i}`,
name: `name-${i}`,
email: `email-${i}`,
}));
}

/**
* @param {string} gaiaId
*/
async function verifyLoadSignInProfileCreationFlowCalled(gaiaId) {
async function verifyLoadSignInProfileCreationFlowCalled(gaiaId: string) {
const args = await browserProxy.whenCalled('loadSignInProfileCreationFlow');
assertEquals(args[1], gaiaId);
browserProxy.resetResolver('loadSignInProfileCreationFlow');
Expand All @@ -45,8 +38,7 @@ suite('ProfileTypeChoiceTest', function() {
ManageProfilesBrowserProxyImpl.setInstance(browserProxy);

document.body.innerHTML = '';
testElement = /** @type {!AccountSelectionLacrosElement} */ (
document.createElement('account-selection-lacros'));
testElement = document.createElement('account-selection-lacros');
testElement.profileThemeInfo = browserProxy.profileThemeInfo;
document.body.append(testElement);

Expand All @@ -66,30 +58,33 @@ suite('ProfileTypeChoiceTest', function() {
test('accountButtons', async function() {
// There are no accounts initially, only "Use another account".
flushTasks();
let buttons = testElement.shadowRoot.querySelectorAll('.account-button');
let buttons = testElement.shadowRoot!.querySelectorAll<HTMLElement>(
'.account-button');
assertTrue(!!buttons);
assertEquals(buttons.length, 1);
// Add some accounts.
webUIListenerCallback(
'unassigned-accounts-changed', generateAccountsList(3));
flushTasks();
buttons = testElement.shadowRoot.querySelectorAll('.account-button');
buttons = testElement.shadowRoot!.querySelectorAll<HTMLElement>(
'.account-button');
assertTrue(!!buttons);
assertEquals(buttons.length, 4);
// Update the accounts again.
webUIListenerCallback(
'unassigned-accounts-changed', generateAccountsList(2));
flushTasks();
buttons = testElement.shadowRoot.querySelectorAll('.account-button');
buttons = testElement.shadowRoot!.querySelectorAll<HTMLElement>(
'.account-button');
assertTrue(!!buttons);
assertEquals(buttons.length, 3);
// Click account buttons.
buttons[0].click();
buttons[0]!.click();
await verifyLoadSignInProfileCreationFlowCalled('gaia-id-0');
buttons[1].click();
buttons[1]!.click();
await verifyLoadSignInProfileCreationFlowCalled('gaia-id-1');
// Click "Use another account".
buttons[2].click();
buttons[2]!.click();
await verifyLoadSignInProfileCreationFlowCalled('');
});
});

0 comments on commit bf01a67

Please sign in to comment.