-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for password-settings in os-settings test
Bug: b:290917006 Change-Id: I8a184299884c3e97785091778918861f3676d8e7 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4692221 Commit-Queue: Martin Bidlingmaier <mbid@google.com> Reviewed-by: Wes Okuhara <wesokuhara@google.com> Cr-Commit-Position: refs/heads/main@{#1186464}
- Loading branch information
Showing
7 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
chrome/browser/ui/webui/settings/ash/os_settings_password_setup_browsertest.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,57 @@ | ||
// 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/ash/settings/test_support/os_settings_lock_screen_browser_test_base.h" | ||
#include "chrome/test/data/webui/settings/chromeos/os_people_page/password_settings_api.test-mojom-test-utils.h" | ||
#include "chrome/test/data/webui/settings/chromeos/test_api.test-mojom-test-utils.h" | ||
#include "content/public/test/browser_test.h" | ||
|
||
namespace ash::settings { | ||
|
||
class OSSettingsPasswordSetupTest : public OSSettingsLockScreenBrowserTestBase { | ||
using OSSettingsLockScreenBrowserTestBase:: | ||
OSSettingsLockScreenBrowserTestBase; | ||
|
||
public: | ||
mojom::PasswordSettingsApiAsyncWaiter GoToPasswordSettings( | ||
mojom::LockScreenSettingsAsyncWaiter& lock_screen_settings) { | ||
password_settings_remote_ = | ||
mojo::Remote(lock_screen_settings.GoToPasswordSettings()); | ||
return mojom::PasswordSettingsApiAsyncWaiter( | ||
password_settings_remote_.get()); | ||
} | ||
|
||
private: | ||
mojo::Remote<mojom::PasswordSettingsApi> password_settings_remote_; | ||
}; | ||
|
||
class OSSettingsPasswordSetupTestWithGaiaPassword | ||
: public OSSettingsPasswordSetupTest { | ||
public: | ||
OSSettingsPasswordSetupTestWithGaiaPassword() | ||
: OSSettingsPasswordSetupTest(PasswordType::kGaia) {} | ||
}; | ||
class OSSettingsPasswordSetupTestWithLocalPassword | ||
: public OSSettingsPasswordSetupTest { | ||
public: | ||
OSSettingsPasswordSetupTestWithLocalPassword() | ||
: OSSettingsPasswordSetupTest(PasswordType::kLocal) {} | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(OSSettingsPasswordSetupTestWithGaiaPassword, NotShown) { | ||
mojom::LockScreenSettingsAsyncWaiter lock_screen_settings = | ||
OpenLockScreenSettingsAndAuthenticate(); | ||
lock_screen_settings.AssertPasswordControlVisibility(false); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(OSSettingsPasswordSetupTestWithLocalPassword, Selected) { | ||
mojom::LockScreenSettingsAsyncWaiter lock_screen_settings = | ||
OpenLockScreenSettingsAndAuthenticate(); | ||
mojom::PasswordSettingsApiAsyncWaiter password_settings = | ||
GoToPasswordSettings(lock_screen_settings); | ||
|
||
password_settings.AssertSelectedPasswordType(mojom::PasswordType::kLocal); | ||
} | ||
|
||
} // namespace ash::settings |
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
16 changes: 16 additions & 0 deletions
16
chrome/test/data/webui/settings/chromeos/os_people_page/password_settings_api.test-mojom
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,16 @@ | ||
// 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. | ||
|
||
module ash.settings.mojom; | ||
|
||
enum PasswordType { | ||
kGaia, | ||
kLocal, | ||
}; | ||
|
||
// The test API for the settings-password-settings element. | ||
interface PasswordSettingsApi { | ||
// Verifies that the given password type is selected. | ||
AssertSelectedPasswordType(PasswordType? password_type) => (); | ||
}; |
68 changes: 68 additions & 0 deletions
68
chrome/test/data/webui/settings/chromeos/os_people_page/password_settings_api.ts
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,68 @@ | ||
// 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 {assertTrue} from 'chrome://webui-test/chai_assert.js'; | ||
|
||
import {PasswordSettingsApiInterface, PasswordSettingsApiReceiver, PasswordSettingsApiRemote, PasswordType} from '../password_settings_api.test-mojom-webui.js'; | ||
import {assertAsync, assertForDuration, hasBooleanProperty} from '../utils.js'; | ||
|
||
// The test API for the settings-password-settings element. | ||
export class PasswordSettingsApi implements PasswordSettingsApiInterface { | ||
private element: HTMLElement; | ||
|
||
constructor(element: HTMLElement) { | ||
this.element = element; | ||
assertTrue(this.element.shadowRoot !== null); | ||
} | ||
|
||
public newRemote(): PasswordSettingsApiRemote { | ||
const receiver = new PasswordSettingsApiReceiver(this); | ||
return receiver.$.bindNewPipeAndPassRemote(); | ||
} | ||
|
||
private shadowRoot(): ShadowRoot { | ||
const shadowRoot = this.element.shadowRoot; | ||
assertTrue(shadowRoot !== null); | ||
return shadowRoot; | ||
} | ||
|
||
private queryGaiaRadio(): {checked: boolean}&HTMLElement { | ||
const el = this.shadowRoot().querySelector('*[name="gaia"]'); | ||
assertTrue(el instanceof HTMLElement); | ||
assertTrue(hasBooleanProperty(el, 'checked')); | ||
return el; | ||
} | ||
|
||
private queryLocalRadio(): {checked: boolean}&HTMLElement { | ||
const el = this.shadowRoot().querySelector('*[name="local"]'); | ||
assertTrue(el instanceof HTMLElement); | ||
assertTrue(hasBooleanProperty(el, 'checked')); | ||
return el; | ||
} | ||
|
||
selectedPasswordType(): PasswordType|null { | ||
const gaiaRadio = this.queryGaiaRadio(); | ||
const localRadio = this.queryLocalRadio(); | ||
|
||
assertTrue( | ||
!(gaiaRadio.checked && localRadio.checked), | ||
'There must be at most one selected password type'); | ||
|
||
if (gaiaRadio.checked) { | ||
return PasswordType.kGaia; | ||
} | ||
if (localRadio.checked) { | ||
return PasswordType.kLocal; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
async assertSelectedPasswordType(passwordType: PasswordType| | ||
null): Promise<void> { | ||
const isSelected = () => this.selectedPasswordType() === passwordType; | ||
await assertAsync(isSelected); | ||
await assertForDuration(isSelected); | ||
} | ||
} |
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