Skip to content

Commit

Permalink
CrOS Settings: Add browser tests for reset card
Browse files Browse the repository at this point in the history
Create dedicated browser test for the reset card element when the
OsSettingsRevampWayfinding feature flag is both enabled and disabled.
These tests are extracted from the old Reset page browser tests.

Bug: b/293937513
Test: browser_tests --gtest_filter="OSSettings*Reset*"
Change-Id: I56f9685572cf3edaf1a1a6fc9babf64765358425
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4781292
Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Wes Okuhara <wesokuhara@google.com>
Cr-Commit-Position: refs/heads/main@{#1185398}
  • Loading branch information
Wes Okuhara authored and Chromium LUCI CQ committed Aug 18, 2023
1 parent 2bb7516 commit b730fd9
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 217 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/resources/ash/settings/lazy_load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ export {MediaDevicesProxy} from './os_privacy_page/media_devices_proxy.js';
export {PrivacyHubBrowserProxy, PrivacyHubBrowserProxyImpl} from './os_privacy_page/privacy_hub_browser_proxy.js';
export {SettingsPrivacyHubSubpage} from './os_privacy_page/privacy_hub_subpage.js';
export {SettingsSmartPrivacySubpage} from './os_privacy_page/smart_privacy_subpage.js';
export {OsSettingsPowerwashDialogElement} from './os_reset_page/os_powerwash_dialog.js';
export {OsResetBrowserProxyImpl} from './os_reset_page/os_reset_browser_proxy.js';
export {SettingsResetCardElement} from './os_reset_page/reset_card.js';
export {GoogleAssistantBrowserProxy, GoogleAssistantBrowserProxyImpl} from './os_search_page/google_assistant_browser_proxy.js';
export {ConsentStatus, DspHotwordState, SettingsGoogleAssistantSubpageElement} from './os_search_page/google_assistant_subpage.js';
export {SettingsSearchSubpageElement} from './os_search_page/search_subpage.js';
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import './os_powerwash_dialog_esim_item.js';

import {LifetimeBrowserProxy, LifetimeBrowserProxyImpl} from '/shared/settings/lifetime_browser_proxy.js';
import {OncMojo} from 'chrome://resources/ash/common/network/onc_mojo.js';
import {CrButtonElement} from 'chrome://resources/cr_elements/cr_button/cr_button.js';
import {CrDialogElement} from 'chrome://resources/cr_elements/cr_dialog/cr_dialog.js';
import {ESimProfileRemote} from 'chrome://resources/mojo/chromeos/ash/services/cellular_setup/public/mojom/esim_manager.mojom-webui.js';
import {NetworkType} from 'chrome://resources/mojo/chromeos/services/network_config/public/mojom/network_types.mojom-webui.js';
Expand All @@ -28,13 +29,14 @@ import {Router, routes} from '../router.js';
import {getTemplate} from './os_powerwash_dialog.html.js';
import {OsResetBrowserProxy, OsResetBrowserProxyImpl} from './os_reset_browser_proxy.js';

interface OsSettingsPowerwashDialogElement {
export interface OsSettingsPowerwashDialogElement {
$: {
cancel: CrButtonElement,
dialog: CrDialogElement,
};
}

class OsSettingsPowerwashDialogElement extends PolymerElement {
export class OsSettingsPowerwashDialogElement extends PolymerElement {
static get is() {
return 'os-settings-powerwash-dialog';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {Route, routes} from '../router.js';

import {getTemplate} from './reset_card.html.js';

interface SettingsResetCardElement {
export interface SettingsResetCardElement {
$: {
powerwashButton: CrButtonElement,
};
Expand All @@ -34,7 +34,7 @@ interface SettingsResetCardElement {
const SettingsResetCardElementBase =
DeepLinkingMixin(RouteObserverMixin(PolymerElement));

class SettingsResetCardElement extends SettingsResetCardElementBase {
export class SettingsResetCardElement extends SettingsResetCardElementBase {
static get is() {
return 'settings-reset-card' as const;
}
Expand Down
2 changes: 2 additions & 0 deletions chrome/test/data/webui/settings/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ build_webui_tests("build") {
"os_privacy_page/test_peripheral_data_access_browser_proxy.ts",
"os_privacy_page/test_privacy_hub_browser_proxy.ts",

"os_reset_page/reset_card_test.ts",

"os_search_page/google_assistant_subpage_test.ts",
"os_search_page/os_search_page_test.ts",
"os_search_page/search_and_assistant_card_test.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'chrome://os-settings/lazy_load.js';

import {OsResetBrowserProxyImpl, OsSettingsPowerwashDialogElement, SettingsResetCardElement} from 'chrome://os-settings/lazy_load.js';
import {CrButtonElement, LifetimeBrowserProxyImpl, Router, routes, settingMojom} from 'chrome://os-settings/os_settings.js';
import {setESimManagerRemoteForTesting} from 'chrome://resources/ash/common/cellular_setup/mojo_interface_provider.js';
import {getDeepActiveElement} from 'chrome://resources/ash/common/util.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.js';
import {ESimManagerRemote} from 'chrome://resources/mojo/chromeos/ash/services/cellular_setup/public/mojom/esim_manager.mojom-webui.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {assertEquals, assertFalse, assertTrue} from 'chrome://webui-test/chai_assert.js';
import {FakeESimManagerRemote} from 'chrome://webui-test/cr_components/chromeos/cellular_setup/fake_esim_manager_remote.js';
import {flushTasks, waitAfterNextRender} from 'chrome://webui-test/polymer_test_util.js';

import {TestLifetimeBrowserProxy} from '../test_os_lifetime_browser_proxy.js';
import {TestOsResetBrowserProxy} from '../test_os_reset_browser_proxy.js';

suite('<reset-card>', () => {
const isRevampWayfindingEnabled =
loadTimeData.getBoolean('isRevampWayfindingEnabled');
const route =
isRevampWayfindingEnabled ? routes.SYSTEM_PREFERENCES : routes.OS_RESET;

let resetCard: SettingsResetCardElement;
let resetPageBrowserProxy: TestOsResetBrowserProxy;
let lifetimeBrowserProxy: TestLifetimeBrowserProxy;
let eSimManagerRemote: FakeESimManagerRemote;

suiteSetup(() => {
lifetimeBrowserProxy = new TestLifetimeBrowserProxy();
LifetimeBrowserProxyImpl.setInstance(lifetimeBrowserProxy);

resetPageBrowserProxy = new TestOsResetBrowserProxy();
OsResetBrowserProxyImpl.setInstanceForTesting(resetPageBrowserProxy);
});

setup(() => {
eSimManagerRemote = new FakeESimManagerRemote();
setESimManagerRemoteForTesting(
eSimManagerRemote as unknown as ESimManagerRemote);

Router.getInstance().navigateTo(route);
resetCard = document.createElement('settings-reset-card');
document.body.appendChild(resetCard);
flush();
});

teardown(() => {
Router.getInstance().resetRouteForTesting();
resetCard.remove();
lifetimeBrowserProxy.reset();
resetPageBrowserProxy.reset();
});

function getPowerwashButton(): HTMLElement {
const powerwashButton =
resetCard.shadowRoot!.querySelector<CrButtonElement>(
'#powerwashButton');
assertTrue(!!powerwashButton);
return powerwashButton;
}

function getPowerwashDialog(): OsSettingsPowerwashDialogElement {
const powerwashDialog =
resetCard.shadowRoot!.querySelector('os-settings-powerwash-dialog');
assertTrue(!!powerwashDialog);
return powerwashDialog;
}

async function testOpenClosePowerwashDialog(
closeButtonFn: (dialog: OsSettingsPowerwashDialogElement) =>
HTMLElement): Promise<void> {
// Open powerwash dialog.
getPowerwashButton().click();
await flushTasks();

const dialog = getPowerwashDialog();
assertOpenDialogUIState(/*shouldBeShowingESimWarning=*/ false);

const onDialogClosedPromise = new Promise<void>((resolve) => {
dialog.addEventListener('close', () => {
assertFalse(dialog.$.dialog.open);
resolve();
});
});

closeButtonFn(dialog).click();
await Promise.all([
onDialogClosedPromise,
resetPageBrowserProxy.whenCalled('onPowerwashDialogShow'),
]);
}

async function openDialogWithESimWarning(): Promise<void> {
eSimManagerRemote.addEuiccForTest(2);

// Set the first profile's state to kActive.
const euiccResponse = await eSimManagerRemote.getAvailableEuiccs();
const euicc = euiccResponse.euiccs[0];
assertTrue(!!euicc);

const profileListResponse = await euicc.getProfileList();
const profile = profileListResponse.profiles[0];
assertTrue(!!profile);
await profile.installProfile('dummyCode');

// Click the powerwash button.
getPowerwashButton().click();
await flushTasks();

// The eSIM warning should be showing.
assertOpenDialogUIState(/*shouldBeShowingESimWarning=*/ true);
const dialog = getPowerwashDialog();
const itemLength =
dialog.shadowRoot!.querySelector('iron-list')!.items!.length;
assertEquals(1, itemLength);

// The 'Continue' button should initially be disabled.
assertTrue(dialog.shadowRoot!.querySelector<CrButtonElement>(
'#continue')!.disabled);
}

function assertOpenDialogUIState(shouldBeShowingESimWarning: boolean): void {
const dialog = getPowerwashDialog();
assertTrue(!!dialog);
assertTrue(dialog.$.dialog.open);

const hasPowerwashContainer =
!!dialog.shadowRoot!.querySelector('#powerwashContainer');
assertEquals(!shouldBeShowingESimWarning, hasPowerwashContainer);
assertEquals(!shouldBeShowingESimWarning, hasPowerwashContainer);
assertEquals(
!shouldBeShowingESimWarning,
!!dialog.shadowRoot!.querySelector('#powerwash'));

assertEquals(
shouldBeShowingESimWarning,
!!dialog.shadowRoot!.querySelector('#profilesListContainer'));
assertEquals(
shouldBeShowingESimWarning,
!!dialog.shadowRoot!.querySelector('#continue'));
}

/**
* Navigates to the deep link provided by |settingId| and returns true if
* the focused element is |deepLinkElement|.
*/
async function isDeepLinkFocusedForSettingId(
deepLinkElement: HTMLElement, settingId: string): Promise<boolean> {
const params = new URLSearchParams();
params.append('settingId', settingId);
Router.getInstance().navigateTo(route, params);

await waitAfterNextRender(deepLinkElement);
return deepLinkElement === getDeepActiveElement();
}

// Tests that the powerwash dialog with no EUICC opens and closes correctly,
// and that chrome.send calls are propagated as expected.
test('Powerwash dialog opens and closes correctly', async () => {
// Test case where the 'cancel' button is clicked.
await testOpenClosePowerwashDialog((dialog) => {
return dialog.$.cancel;
});
});

// Tests that when powerwash is requested chrome.send calls are
// propagated as expected.
test('Powerwash should trigger factory reset', async () => {
// Open powerwash dialog.
getPowerwashButton().click();
await flushTasks();
const dialog = getPowerwashDialog();
assertOpenDialogUIState(/*shouldBeShowingESimWarning=*/ false);
dialog.shadowRoot!.querySelector<CrButtonElement>('#powerwash')!.click();
const requestTpmFirmwareUpdate =
await lifetimeBrowserProxy.whenCalled('factoryReset');
assertFalse(requestTpmFirmwareUpdate);
});

// Tests that when the route changes to one containing a deep link to
// powerwash, powerwash is focused.
test('Powerwash button is focused via deep link', async () => {
const settingId = settingMojom.Setting.kPowerwash.toString();
const isFocused =
await isDeepLinkFocusedForSettingId(getPowerwashButton(), settingId);
assertTrue(
isFocused, `Powerwash should be focused for settingId=${settingId}.`);
});

// Tests that when the route changes to one containing a deep link not equal
// to powerwash, no focusing of powerwash occurs.
test(
'Powerwash button is not focused for different deep link setting ID',
async () => {
const invalidSettingId = '1234';
const isFocused = await isDeepLinkFocusedForSettingId(
getPowerwashButton(), invalidSettingId);
assertFalse(
isFocused,
`Powerwash should not be focused for settingId=${
invalidSettingId}.`);
});

test(
'EUICC with no non-pending profiles shows powerwash dialog', async () => {
eSimManagerRemote.addEuiccForTest(2);

await testOpenClosePowerwashDialog((dialog) => {
return dialog.$.cancel;
});
});

test('Non-pending profile shows eSIM warning dialog', async () => {
await openDialogWithESimWarning();

// Clicking the checkbox should enable the 'Continue' button.
const dialog = getPowerwashDialog();
const continueButton =
dialog.shadowRoot!.querySelector<CrButtonElement>('#continue');
assertTrue(!!continueButton);
dialog.shadowRoot!.querySelector('cr-checkbox')!.click();
assertFalse(continueButton.disabled);

// Click the 'Continue' button.
continueButton.click();
await flushTasks();
// The powerwash UI should now be showing.
assertOpenDialogUIState(/*shouldBeShowingESimWarning=*/ false);
});

test(
'Clicking the eSIM warning dialog link goes to the mobile data subpage',
async () => {
await openDialogWithESimWarning();

const dialog = getPowerwashDialog();
const mobileSettingsLink =
dialog.shadowRoot!.querySelector('localized-link')!.shadowRoot!
.querySelector('a');
assertTrue(!!mobileSettingsLink);

mobileSettingsLink.click();
await flushTasks();

assertEquals(
routes.INTERNET_NETWORKS, Router.getInstance().currentRoute);
assertEquals(
'type=Cellular',
Router.getInstance().getQueryParameters().toString());
});
});

0 comments on commit b730fd9

Please sign in to comment.