Commit ad6bef83 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS SplitSettings] Move OS reset tests into chromeos directory.

This CL is an example of how tests for components shared by OS
and Browser should be moved.

Change-Id: Ifa11ebbfc3faf526092b7fb1ea4713ae06073cae
Bug: 968182
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1677768
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarMay Lippert <maybelle@chromium.org>
Cr-Commit-Position: refs/heads/master@{#673434}
parent 9b178a28
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
cr.define('settings_reset_page', function() {
/** @enum {string} */
const TestNames = {
PowerwashDialogAction: 'PowerwashDialogAction',
PowerwashDialogOpenClose: 'PowerwashDialogOpenClose',
};
function registerDialogTests() {
suite('DialogTests', function() {
let resetPage = null;
/** @type {!settings.ResetPageBrowserProxy} */
let resetPageBrowserProxy = null;
/** @type {!settings.LifetimeBrowserProxy} */
let lifetimeBrowserProxy = null;
setup(function() {
lifetimeBrowserProxy = new settings.TestLifetimeBrowserProxy();
settings.LifetimeBrowserProxyImpl.instance_ = lifetimeBrowserProxy;
resetPageBrowserProxy = new reset_page.TestResetBrowserProxy();
settings.ResetOsProxyImpl.instance_ = resetPageBrowserProxy;
PolymerTest.clearBody();
resetPage = document.createElement('os-settings-reset-page');
document.body.appendChild(resetPage);
Polymer.dom.flush();
});
teardown(function() {
resetPage.remove();
});
/**
* @param {function(SettingsPowerwashDialogElement):!Element}
* closeButtonFn A function that returns the button to be used for
* closing the dialog.
* @return {!Promise}
*/
function testOpenClosePowerwashDialog(closeButtonFn) {
// Open powerwash dialog.
assertTrue(!!resetPage);
resetPage.$.powerwash.click();
Polymer.dom.flush();
const dialog = resetPage.$$('os-settings-powerwash-dialog');
assertTrue(!!dialog);
assertTrue(dialog.$.dialog.open);
const onDialogClosed = new Promise(function(resolve, reject) {
dialog.addEventListener('close', function() {
assertFalse(dialog.$.dialog.open);
resolve();
});
});
closeButtonFn(dialog).click();
return Promise.all([
onDialogClosed,
resetPageBrowserProxy.whenCalled('onPowerwashDialogShow'),
]);
}
// Tests that the powerwash dialog opens and closes correctly, and
// that chrome.send calls are propagated as expected.
test(TestNames.PowerwashDialogOpenClose, function() {
// Test case where the 'cancel' button is clicked.
return testOpenClosePowerwashDialog(function(dialog) {
return dialog.$.cancel;
});
});
// Tests that when powerwash is requested chrome.send calls are
// propagated as expected.
test(TestNames.PowerwashDialogAction, function() {
// Open powerwash dialog.
resetPage.$.powerwash.click();
Polymer.dom.flush();
const dialog = resetPage.$$('os-settings-powerwash-dialog');
assertTrue(!!dialog);
dialog.$.powerwash.click();
return lifetimeBrowserProxy.whenCalled('factoryReset')
.then((requestTpmFirmwareUpdate) => {
assertFalse(requestTpmFirmwareUpdate);
});
});
});
}
registerDialogTests();
});
...@@ -158,3 +158,22 @@ TEST_F('OSSettingsAboutPageTest', 'AboutPage_OfficialBuild', function() { ...@@ -158,3 +158,22 @@ TEST_F('OSSettingsAboutPageTest', 'AboutPage_OfficialBuild', function() {
mocha.run(); mocha.run();
}); });
GEN('#endif'); GEN('#endif');
// Tests for the Reset section.
// eslint-disable-next-line no-var
var OSSettingsResetPageTest = class extends OSSettingsBrowserTest {
/** @override */
get extraLibraries() {
return super.extraLibraries.concat([
BROWSER_SETTINGS_PATH + '../test_browser_proxy.js',
BROWSER_SETTINGS_PATH + 'test_lifetime_browser_proxy.js',
BROWSER_SETTINGS_PATH + 'test_reset_browser_proxy.js',
BROWSER_SETTINGS_PATH + 'test_util.js',
'os_reset_page_test.js',
]);
}
};
TEST_F('OSSettingsResetPageTest', 'AllJavascriptTests', function() {
mocha.run();
});
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
cr.define('settings_reset_page', function() { cr.define('settings_reset_page', function() {
/** @enum {string} */ /** @enum {string} */
const TestNames = { const TestNames = {
// TODO(crbug/950007): Remove PowerwashDialogAction and
// PowerwashDialogOpenClose associated tests when SplitSettings is complete.
PowerwashDialogAction: 'PowerwashDialogAction', PowerwashDialogAction: 'PowerwashDialogAction',
PowerwashDialogOpenClose: 'PowerwashDialogOpenClose', PowerwashDialogOpenClose: 'PowerwashDialogOpenClose',
ResetProfileDialogAction: 'ResetProfileDialogAction', ResetProfileDialogAction: 'ResetProfileDialogAction',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment