Skip to content

Commit

Permalink
[CrOS Settings] Check-in Polymer3 code for users/accounts tests
Browse files Browse the repository at this point in the history
We no longer need to generate modulized versions of the JS test files
(`.m.js`) at build time. Instead, we can check-in the modulized version
and then use the test source files directly in
`os_settings_v3_browsertest.js`.

Bug: 1180979
Test: out/Default/browser_tests --gtest_filter='*OSSettings*'
Change-Id: I60c419a93a309008156ee8154e05e04da57d4c9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3565018
Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
Commit-Queue: Wes Okuhara <wesokuhara@google.com>
Cr-Commit-Position: refs/heads/main@{#988118}
  • Loading branch information
Wes Okuhara authored and Chromium LUCI CQ committed Apr 1, 2022
1 parent abfe622 commit 6472203
Show file tree
Hide file tree
Showing 21 changed files with 1,173 additions and 1,269 deletions.
11 changes: 0 additions & 11 deletions chrome/test/data/webui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ if (include_js_tests) {
"$root_gen_dir/chrome/test/data/webui/nearby_share/shared/nearby_onboarding_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/nearby_share/shared/nearby_page_template_test.m.js",
"$root_gen_dir/chrome/test/data/webui/nearby_share/shared/nearby_visibility_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/add_users_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/crostini_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/crostini_extra_containers_subpage_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/cups_printer_page_tests.m.js",
Expand All @@ -284,11 +283,7 @@ if (include_js_tests) {
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/fake_quick_unlock_private.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/fake_quick_unlock_uma.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/fake_settings_search_handler.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/fake_users_private.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/fake_user_action_recorder.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/fingerprint_browsertest_chromeos.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/guest_os_shared_paths_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/guest_os_shared_usb_devices_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/onc_mojo_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/kerberos_accounts_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/kerberos_page_test.m.js",
Expand All @@ -302,7 +297,6 @@ if (include_js_tests) {
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_settings_ui_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_settings_ui_test_2.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_reset_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_people_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_privacy_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_settings_menu_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_sync_controls_test.m.js",
Expand All @@ -311,8 +305,6 @@ if (include_js_tests) {
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_search_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_settings_search_box_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/os_settings_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/people_page_account_manager_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/people_page_change_picture_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/quick_unlock_authenticate_browsertest_chromeos.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/smart_inputs_page_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/smart_privacy_subpage_tests.m.js",
Expand All @@ -326,19 +318,16 @@ if (include_js_tests) {
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_about_page_browser_proxy_chromeos.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_crostini_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_cups_printers_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_guest_os_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_os_languages_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_kerberos_accounts_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_os_languages_metrics_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_os_lifetime_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_os_reset_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_os_sync_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_personalization_hub_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/test_wallpaper_browser_proxy.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/tether_connection_dialog_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/text_to_speech_subpage_tests.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/tts_subpage_test.m.js",
"$root_gen_dir/chrome/test/data/webui/settings/chromeos/user_page_tests.m.js",
]
}
defines = [ "HAS_OUT_OF_PROC_TEST_RUNNER" ]
Expand Down
11 changes: 0 additions & 11 deletions chrome/test/data/webui/settings/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ js_library("fake_settings_search_handler") {

js_modulizer("modulize") {
input_files = [
"add_users_tests.js",
"crostini_page_test.js",
"crostini_extra_containers_subpage_test.js",
"cups_printer_entry_tests.js",
Expand All @@ -45,11 +44,7 @@ js_modulizer("modulize") {
"fake_receive_manager.js",
"fake_settings_search_handler.js",
"fake_system_display.js",
"fake_user_action_recorder.js",
"fake_users_private.js",
"fingerprint_browsertest_chromeos.js",
"guest_os_shared_paths_test.js",
"guest_os_shared_usb_devices_test.js",
"kerberos_accounts_test.js",
"kerberos_page_test.js",
"manage_accessibility_page_tests.js",
Expand All @@ -60,7 +55,6 @@ js_modulizer("modulize") {
"os_files_page_test.js",
"os_languages_page_v2_tests.js",
"os_reset_page_test.js",
"os_people_page_test.js",
"os_printing_page_tests.js",
"os_privacy_page_test.js",
"os_search_page_test.js",
Expand All @@ -71,8 +65,6 @@ js_modulizer("modulize") {
"os_settings_ui_test.js",
"os_settings_ui_test_2.js",
"os_sync_controls_test.js",
"people_page_account_manager_test.js",
"people_page_change_picture_test.js",
"quick_unlock_authenticate_browsertest_chromeos.js",
"lock_screen_tests.js",
"search_subpage_test.js",
Expand All @@ -89,19 +81,16 @@ js_modulizer("modulize") {
"test_crostini_browser_proxy.js",
"test_cups_printers_browser_proxy.js",
"test_device_name_browser_proxy.js",
"test_guest_os_browser_proxy.js",
"test_kerberos_accounts_browser_proxy.js",
"test_os_languages_browser_proxy.js",
"test_os_languages_metrics_proxy.js",
"test_os_lifetime_browser_proxy.js",
"test_os_reset_browser_proxy.js",
"test_os_sync_browser_proxy.js",
"test_personalization_hub_browser_proxy.js",
"test_wallpaper_browser_proxy.js",
"tether_connection_dialog_test.js",
"text_to_speech_subpage_tests.js",
"tts_subpage_test.js",
"user_page_tests.js",
]
namespace_rewrites =
os_settings_namespace_rewrites + os_test_namespace_rewrites +
Expand Down
11 changes: 5 additions & 6 deletions chrome/test/data/webui/settings/chromeos/add_users_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// clang-format off
// #import 'chrome://os-settings/chromeos/os_settings.js';
import 'chrome://os-settings/chromeos/os_settings.js';

// #import {FakeUsersPrivate} from './fake_users_private.m.js';
// #import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js';
// clang-format on
import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js';

import {FakeUsersPrivate} from './fake_users_private.js';

suite('AddPersonDialog', function() {
let dialog = null;
Expand All @@ -16,7 +15,7 @@ suite('AddPersonDialog', function() {
PolymerTest.clearBody();

dialog = document.createElement('settings-users-add-user-dialog');
dialog.usersPrivate_ = new settings.FakeUsersPrivate();
dialog.usersPrivate_ = new FakeUsersPrivate();

document.body.appendChild(dialog);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// #import 'chrome://os-settings/chromeos/lazy_load.js';
// #import 'chrome://os-settings/chromeos/os_settings.js';

// #import {TestGuestOsBrowserProxy} from './test_guest_os_browser_proxy.m.js';
// #import {TestGuestOsBrowserProxy} from './test_guest_os_browser_proxy.js';
// #import {TestCrostiniBrowserProxy} from './test_crostini_browser_proxy.m.js';
// #import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
// #import {assertEquals, assertFalse, assertNotEquals, assertTrue} from '../../chai_assert.js';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,46 @@
* chromeos.settings.mojom.UserActionRecorderRemote for testing.
*/

cr.define('settings', function() {
/**
* Fake implementation of chromeos.settings.mojom.UserActionRecorderRemote.
*
* @implements {chromeos.settings.mojom.UserActionRecorderInterface}
*/
/* #export */ class FakeUserActionRecorder {
constructor() {
this.pageFocusCount = 0;
this.pageBlurCount = 0;
this.clickCount = 0;
this.navigationCount = 0;
this.searchCount = 0;
this.settingChangeCount = 0;
}

recordPageFocus() {
++this.pageFocusCount;
}

recordPageBlur() {
++this.pageBlurCount;
}

recordClick() {
++this.clickCount;
}

recordNavigation() {
++this.navigationCount;
}

recordSearch() {
++this.searchCount;
}

recordSettingChange() {
++this.settingChangeCount;
}

recordSettingChangeWithDetails() {
++this.settingChangeCount;
}
}

// #cr_define_end
return {FakeUserActionRecorder: FakeUserActionRecorder};
});
/**
* Fake implementation of chromeos.settings.mojom.UserActionRecorderRemote.
*
* @implements {chromeos.settings.mojom.UserActionRecorderInterface}
*/
export class FakeUserActionRecorder {
constructor() {
this.pageFocusCount = 0;
this.pageBlurCount = 0;
this.clickCount = 0;
this.navigationCount = 0;
this.searchCount = 0;
this.settingChangeCount = 0;
}

recordPageFocus() {
++this.pageFocusCount;
}

recordPageBlur() {
++this.pageBlurCount;
}

recordClick() {
++this.clickCount;
}

recordNavigation() {
++this.navigationCount;
}

recordSearch() {
++this.searchCount;
}

recordSettingChange() {
++this.settingChangeCount;
}

recordSettingChangeWithDetails() {
++this.settingChangeCount;
}
}
51 changes: 23 additions & 28 deletions chrome/test/data/webui/settings/chromeos/fake_users_private.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,31 @@
* @fileoverview Fake implementation of chrome.usersPrivate
* for testing.
*/
cr.define('settings', function() {
/**
* Fake of the chrome.usersPrivate API. Only methods that are called
* during testing have been implemented.
*
* @constructor
* @implements {UsersPrivate}
*/
/* #export */ function FakeUsersPrivate() {}

FakeUsersPrivate.prototype = {
users: [],
/**
* Fake of the chrome.usersPrivate API. Only methods that are called
* during testing have been implemented.
*
* @constructor
* @implements {UsersPrivate}
*/
export function FakeUsersPrivate() {}

addUser: function(user) {
this.users.push(user);
},
FakeUsersPrivate.prototype = {
users: [],

getUsers: function(callback) {
return callback(this.users);
},
addUser: function(user) {
this.users.push(user);
},

removeUser: function(email, callback) {
this.users = this.users.filter(user => user.email !== email);
},
getUsers: function(callback) {
return callback(this.users);
},

isUserInList: function(user, callback) {
callback(this.users.includes(user));
},
};
removeUser: function(email, callback) {
this.users = this.users.filter(user => user.email !== email);
},

// #cr_define_end
return {FakeUsersPrivate: FakeUsersPrivate};
});
isUserInList: function(user, callback) {
callback(this.users.includes(user));
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// clang-format off
// #import 'chrome://os-settings/chromeos/os_settings.js';
import 'chrome://os-settings/chromeos/os_settings.js';

// #import {flush} from'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
// #import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js';
// #import {assert} from 'chrome://resources/js/assert.m.js';
// #import {TestBrowserProxy} from '../../test_browser_proxy.js';
// #import {GuestOsBrowserProxyImpl} from 'chrome://os-settings/chromeos/lazy_load.js';
// clang-format on
import {GuestOsBrowserProxyImpl} from 'chrome://os-settings/chromeos/lazy_load.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

/** @implements {settings.GuestOsBrowserProxy} */
import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js';
import {TestBrowserProxy} from '../../test_browser_proxy.js';

/** @implements {GuestOsBrowserProxy} */
class TestGuestOsBrowserProxy extends TestBrowserProxy {
constructor() {
super([
Expand Down Expand Up @@ -51,13 +49,13 @@ suite('SharedPaths', function() {
};
return guestOsBrowserProxy.whenCalled('getGuestOsSharedPathsDisplayText')
.then(() => {
Polymer.dom.flush();
flush();
});
}

setup(function() {
guestOsBrowserProxy = new TestGuestOsBrowserProxy();
settings.GuestOsBrowserProxyImpl.instance_ = guestOsBrowserProxy;
GuestOsBrowserProxyImpl.instance_ = guestOsBrowserProxy;
PolymerTest.clearBody();
page = document.createElement('settings-guest-os-shared-paths');
page.guestOsType = 'pluginVm';
Expand Down Expand Up @@ -116,7 +114,7 @@ suite('SharedPaths', function() {
page.$$('.list-item cr-icon-button').click();

await guestOsBrowserProxy.whenCalled('removeGuestOsSharedPath');
Polymer.dom.flush();
flush();
assertTrue(page.$$('#removeSharedPathFailedDialog').open);

// Click retry and make sure 'removeGuestOsSharedPath' is called
Expand Down

0 comments on commit 6472203

Please sign in to comment.