-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move cros settings test fixtures into common base
This commit refactors duplicated code of browser test fixtures for tests using the settings test api into a common base class. Bug: b:243696986 Change-Id: I04a669a90b4e2a75e2003d7369050b745580ea82 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4320927 Reviewed-by: Wes Okuhara <wesokuhara@google.com> Commit-Queue: Martin Bidlingmaier <mbid@google.com> Cr-Commit-Position: refs/heads/main@{#1115644}
- Loading branch information
Showing
6 changed files
with
145 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
chrome/browser/ui/webui/settings/ash/os_settings_lock_screen_browser_test_base.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// 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. | ||
|
||
#include "chrome/browser/ui/webui/settings/ash/os_settings_lock_screen_browser_test_base.h" | ||
|
||
namespace ash::settings { | ||
|
||
OSSettingsLockScreenBrowserTestBase::OSSettingsLockScreenBrowserTestBase() { | ||
// We configure FakeUserDataAuthClient (via `cryptohome_`) here and not | ||
// later because the global PinBackend object reads whether or not | ||
// cryptohome PINs are supported on startup. If we set up | ||
// FakeUserDataAuthClient in SetUpOnMainThread, then PinBackend would | ||
// determine whether PINs are supported before we have configured | ||
// FakeUserDataAuthClient. | ||
cryptohome_.set_enable_auth_check(true); | ||
cryptohome_.set_supports_low_entropy_credentials(true); | ||
cryptohome_.MarkUserAsExisting(GetAccountId()); | ||
cryptohome_.AddGaiaPassword(GetAccountId(), kPassword); | ||
} | ||
|
||
OSSettingsLockScreenBrowserTestBase::~OSSettingsLockScreenBrowserTestBase() = | ||
default; | ||
|
||
void OSSettingsLockScreenBrowserTestBase::SetUpOnMainThread() { | ||
MixinBasedInProcessBrowserTest::SetUpOnMainThread(); | ||
logged_in_user_mixin_.LogInUser(); | ||
} | ||
|
||
mojom::LockScreenSettingsAsyncWaiter | ||
OSSettingsLockScreenBrowserTestBase::OpenLockScreenSettings() { | ||
os_settings_driver_remote_ = | ||
mojo::Remote{os_settings_mixin_.OpenOSSettings()}; | ||
|
||
lock_screen_settings_remote_ = mojo::Remote{ | ||
mojom::OSSettingsDriverAsyncWaiter{os_settings_driver_remote_.get()} | ||
.GoToLockScreenSettings()}; | ||
|
||
return mojom::LockScreenSettingsAsyncWaiter{ | ||
lock_screen_settings_remote_.get()}; | ||
} | ||
|
||
mojom::LockScreenSettingsAsyncWaiter | ||
OSSettingsLockScreenBrowserTestBase::OpenLockScreenSettingsAndAuthenticate() { | ||
OpenLockScreenSettings().Authenticate(kPassword); | ||
// The mojom AsyncWaiter classes have deleted copy constructors even though | ||
// they only hold a non-owning pointer to a mojo remote. This restriction | ||
// should probably be dropped, so that we can just return the async waiter | ||
// created by the call to `OpenLockScreenSettings` here. As a workaround, we | ||
// simply create a new waiter. | ||
return mojom::LockScreenSettingsAsyncWaiter{ | ||
lock_screen_settings_remote_.get()}; | ||
} | ||
|
||
const AccountId& OSSettingsLockScreenBrowserTestBase::GetAccountId() { | ||
return logged_in_user_mixin_.GetAccountId(); | ||
} | ||
|
||
} // namespace ash::settings |
60 changes: 60 additions & 0 deletions
60
chrome/browser/ui/webui/settings/ash/os_settings_lock_screen_browser_test_base.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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. | ||
|
||
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_ASH_OS_SETTINGS_LOCK_SCREEN_BROWSER_TEST_BASE_H_ | ||
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_ASH_OS_SETTINGS_LOCK_SCREEN_BROWSER_TEST_BASE_H_ | ||
|
||
#include "ash/constants/ash_features.h" | ||
#include "chrome/browser/ash/login/test/cryptohome_mixin.h" | ||
#include "chrome/browser/ash/login/test/logged_in_user_mixin.h" | ||
#include "chrome/browser/ui/webui/settings/ash/os_settings_browser_test_mixin.h" | ||
#include "chrome/test/base/mixin_based_in_process_browser_test.h" | ||
#include "chrome/test/data/webui/settings/chromeos/test_api.test-mojom-test-utils.h" | ||
#include "components/account_id/account_id.h" | ||
|
||
namespace ash::settings { | ||
|
||
// Fixture for browser tests of the "lock screen" section in | ||
// chrome://os-settings. The fixture creates a user with a gaia password and | ||
// logs in. It provides methods to open the os settings page and navigate to | ||
// the "lock screen" section. Tests can then operate this section via its test | ||
// api. | ||
class OSSettingsLockScreenBrowserTestBase | ||
: public MixinBasedInProcessBrowserTest { | ||
public: | ||
// The password of the user that is set up by this fixture. | ||
static constexpr char kPassword[] = "the-password"; | ||
|
||
OSSettingsLockScreenBrowserTestBase(); | ||
~OSSettingsLockScreenBrowserTestBase() override; | ||
|
||
void SetUpOnMainThread() override; | ||
|
||
// Opens the ChromeOS settings app and navigates to the "lock screen" | ||
// section. The return value is an AsyncWaiter that can be used to interact | ||
// with the WebUI. The returned AsyncWaiter is valid until this function is | ||
// called again. | ||
mojom::LockScreenSettingsAsyncWaiter OpenLockScreenSettings(); | ||
|
||
// Calls `OpenLockScreenSettings` and authenticates. | ||
mojom::LockScreenSettingsAsyncWaiter OpenLockScreenSettingsAndAuthenticate(); | ||
|
||
// The account ID of the user set up by this fixture. | ||
const AccountId& GetAccountId(); | ||
|
||
protected: | ||
CryptohomeMixin cryptohome_{&mixin_host_}; | ||
LoggedInUserMixin logged_in_user_mixin_{ | ||
&mixin_host_, LoggedInUserMixin::LogInType::kRegular, | ||
embedded_test_server(), this}; | ||
OSSettingsBrowserTestMixin os_settings_mixin_{&mixin_host_}; | ||
|
||
private: | ||
mojo::Remote<mojom::OSSettingsDriver> os_settings_driver_remote_; | ||
mojo::Remote<mojom::LockScreenSettings> lock_screen_settings_remote_; | ||
}; | ||
|
||
} // namespace ash::settings | ||
|
||
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_ASH_OS_SETTINGS_LOCK_SCREEN_BROWSER_TEST_BASE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.