Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lacros] IdentityBrowserTestBase tests can trigger AccountManager UI
Tests derived from IdentityBrowserTestBase currently crash if they try to show any system dialog. This happens because AccountManagerMojoService never gets a proper AccountManagerUI implementation. This CL injects a fake implementation of AccountManagerUI into AccountManagerMojoService in IdentityBrowserTestBase tests. These tests cannot use a real implementation because AccountManagerUIImpl is implemented in Ash. Bug: 1263505 Change-Id: I9ebc8e708a9c0ea54c0342d0aba466a735a24372 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3256683 Commit-Queue: Alex Ilin <alexilin@chromium.org> Reviewed-by: Boris Sazonov <bsazonov@chromium.org> Cr-Commit-Position: refs/heads/main@{#939338}
- Loading branch information
Alex Ilin
authored and
Chromium LUCI CQ
committed
Nov 8, 2021
1 parent
b185efd
commit 3f577be
Showing
9 changed files
with
184 additions
and
66 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
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
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
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
61 changes: 61 additions & 0 deletions
61
components/account_manager_core/chromeos/fake_account_manager_ui.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,61 @@ | ||
// Copyright 2021 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. | ||
|
||
#include "components/account_manager_core/chromeos/fake_account_manager_ui.h" | ||
|
||
#include "base/callback.h" | ||
|
||
FakeAccountManagerUI::FakeAccountManagerUI() = default; | ||
FakeAccountManagerUI::~FakeAccountManagerUI() = default; | ||
|
||
void FakeAccountManagerUI::AddObserver(Observer* observer) { | ||
observers_.AddObserver(observer); | ||
} | ||
|
||
void FakeAccountManagerUI::RemoveObserver(Observer* observer) { | ||
observers_.RemoveObserver(observer); | ||
} | ||
|
||
void FakeAccountManagerUI::SetIsDialogShown(bool is_dialog_shown) { | ||
is_dialog_shown_ = is_dialog_shown; | ||
} | ||
|
||
void FakeAccountManagerUI::CloseDialog() { | ||
if (!close_dialog_closure_.is_null()) { | ||
std::move(close_dialog_closure_).Run(); | ||
} | ||
is_dialog_shown_ = false; | ||
} | ||
|
||
void FakeAccountManagerUI::ShowAddAccountDialog( | ||
base::OnceClosure close_dialog_closure) { | ||
close_dialog_closure_ = std::move(close_dialog_closure); | ||
show_account_addition_dialog_calls_++; | ||
is_dialog_shown_ = true; | ||
|
||
for (auto& obs : observers_) | ||
obs.OnAddAccountDialogShown(); | ||
} | ||
|
||
void FakeAccountManagerUI::ShowReauthAccountDialog( | ||
const std::string& email, | ||
base::OnceClosure close_dialog_closure) { | ||
close_dialog_closure_ = std::move(close_dialog_closure); | ||
show_account_reauthentication_dialog_calls_++; | ||
is_dialog_shown_ = true; | ||
|
||
for (auto& obs : observers_) | ||
obs.OnReauthAccountDialogShown(); | ||
} | ||
|
||
bool FakeAccountManagerUI::IsDialogShown() { | ||
return is_dialog_shown_; | ||
} | ||
|
||
void FakeAccountManagerUI::ShowManageAccountsSettings() { | ||
show_manage_accounts_settings_calls_++; | ||
|
||
for (auto& obs : observers_) | ||
obs.OnManageAccountsSettingsShown(); | ||
} |
65 changes: 65 additions & 0 deletions
65
components/account_manager_core/chromeos/fake_account_manager_ui.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,65 @@ | ||
// Copyright 2021 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. | ||
|
||
#ifndef COMPONENTS_ACCOUNT_MANAGER_CORE_CHROMEOS_FAKE_ACCOUNT_MANAGER_UI_H_ | ||
#define COMPONENTS_ACCOUNT_MANAGER_CORE_CHROMEOS_FAKE_ACCOUNT_MANAGER_UI_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/callback_forward.h" | ||
#include "base/observer_list.h" | ||
#include "base/observer_list_types.h" | ||
#include "components/account_manager_core/chromeos/account_manager_ui.h" | ||
|
||
// Fake implementation of `AccountManagerUI` for tests. | ||
class FakeAccountManagerUI : public account_manager::AccountManagerUI { | ||
public: | ||
class Observer : public base::CheckedObserver { | ||
public: | ||
virtual void OnAddAccountDialogShown() {} | ||
virtual void OnReauthAccountDialogShown() {} | ||
virtual void OnManageAccountsSettingsShown() {} | ||
}; | ||
|
||
FakeAccountManagerUI(); | ||
FakeAccountManagerUI(const FakeAccountManagerUI&) = delete; | ||
FakeAccountManagerUI& operator=(const FakeAccountManagerUI&) = delete; | ||
~FakeAccountManagerUI() override; | ||
|
||
void AddObserver(Observer* observer); | ||
void RemoveObserver(Observer* observer); | ||
|
||
void SetIsDialogShown(bool is_dialog_shown); | ||
void CloseDialog(); | ||
|
||
int show_account_addition_dialog_calls() const { | ||
return show_account_addition_dialog_calls_; | ||
} | ||
|
||
int show_account_reauthentication_dialog_calls() const { | ||
return show_account_reauthentication_dialog_calls_; | ||
} | ||
|
||
int show_manage_accounts_settings_calls() const { | ||
return show_manage_accounts_settings_calls_; | ||
} | ||
|
||
// AccountManagerUI overrides: | ||
void ShowAddAccountDialog(base::OnceClosure close_dialog_closure) override; | ||
void ShowReauthAccountDialog(const std::string& email, | ||
base::OnceClosure close_dialog_closure) override; | ||
bool IsDialogShown() override; | ||
void ShowManageAccountsSettings() override; | ||
|
||
private: | ||
base::OnceClosure close_dialog_closure_; | ||
bool is_dialog_shown_ = false; | ||
int show_account_addition_dialog_calls_ = 0; | ||
int show_account_reauthentication_dialog_calls_ = 0; | ||
int show_manage_accounts_settings_calls_ = 0; | ||
|
||
base::ObserverList<Observer> observers_; | ||
}; | ||
|
||
#endif // COMPONENTS_ACCOUNT_MANAGER_CORE_CHROMEOS_FAKE_ACCOUNT_MANAGER_UI_H_ |