Commit 761a7e81 authored by Alexander Alekseev's avatar Alexander Alekseev Committed by Commit Bot

Chrome OS: Integrate Discover PIN setup into First run UI.

Bug: 852553
Change-Id: I215392305eee1555441d5dd66f0bb2908d0f5525
Reviewed-on: https://chromium-review.googlesource.com/c/1250136
Commit-Queue: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599137}
parent 40a6cb9b
......@@ -79,6 +79,9 @@ constexpr size_t kMinLengthForNonWeakPin = 2U;
constexpr const char* kMostCommonPins[] = {"1212", "1004", "2000", "6969",
"1122", "1313", "2001", "1010"};
// QuickUnlockPrivateGetAuthTokenFunction test observer.
QuickUnlockPrivateGetAuthTokenFunction::TestObserver* test_observer;
// Returns the active set of quick unlock modes.
void ComputeActiveModes(Profile* profile, ActiveModeCallback result) {
user_manager::User* user =
......@@ -221,6 +224,12 @@ void QuickUnlockPrivateGetAuthTokenFunction::
authenticator_allocator_ = allocator;
}
// static
void QuickUnlockPrivateGetAuthTokenFunction::SetTestObserver(
QuickUnlockPrivateGetAuthTokenFunction::TestObserver* observer) {
test_observer = observer;
}
ExtensionFunction::ResponseAction
QuickUnlockPrivateGetAuthTokenFunction::Run() {
std::unique_ptr<quick_unlock_private::GetAuthToken::Params> params =
......@@ -233,6 +242,9 @@ QuickUnlockPrivateGetAuthTokenFunction::Run() {
chromeos::UserContext user_context(*user);
user_context.SetKey(chromeos::Key(params->account_password));
if (test_observer)
test_observer->OnGetAuthTokenCalled(params->account_password);
// Alter |user_context| if the user is supervised.
if (user->GetType() == user_manager::USER_TYPE_SUPERVISED) {
user_context = chromeos::ChromeUserManager::Get()
......
......@@ -29,6 +29,11 @@ class QuickUnlockPrivateGetAuthTokenFunction
base::Callback<chromeos::ExtendedAuthenticator*(
chromeos::AuthStatusConsumer* auth_status_consumer)>;
class TestObserver {
public:
virtual void OnGetAuthTokenCalled(const std::string&) = 0;
};
QuickUnlockPrivateGetAuthTokenFunction();
// Use the given |allocator| to create an ExtendedAuthenticator instance. This
......@@ -36,6 +41,10 @@ class QuickUnlockPrivateGetAuthTokenFunction
void SetAuthenticatorAllocatorForTesting(
const AuthenticatorAllocator& allocator);
// Test API.
static void SetTestObserver(
QuickUnlockPrivateGetAuthTokenFunction::TestObserver* observer);
DECLARE_EXTENSION_FUNCTION("quickUnlockPrivate.getAuthToken",
QUICKUNLOCKPRIVATE_GETAUTHTOKEN);
......
......@@ -4,7 +4,9 @@
#include "base/command_line.h"
#include "base/macros.h"
#include "base/optional.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/chromeos/extensions/quick_unlock_private/quick_unlock_private_api.h"
#include "chrome/browser/chromeos/login/screens/gaia_view.h"
#include "chrome/browser/chromeos/login/screens/sync_consent_screen.h"
#include "chrome/browser/chromeos/login/screens/update_screen.h"
......@@ -61,7 +63,27 @@ class JsConditionWaiter {
DISALLOW_COPY_AND_ASSIGN(JsConditionWaiter);
};
class OobeInteractiveUITest : public OobeBaseTest {
class ScopedQuickUnlockPrivateGetAuthTokenFunctionObserver {
public:
explicit ScopedQuickUnlockPrivateGetAuthTokenFunctionObserver(
extensions::QuickUnlockPrivateGetAuthTokenFunction::TestObserver*
observer) {
extensions::QuickUnlockPrivateGetAuthTokenFunction::SetTestObserver(
observer);
}
~ScopedQuickUnlockPrivateGetAuthTokenFunctionObserver() {
extensions::QuickUnlockPrivateGetAuthTokenFunction::SetTestObserver(
nullptr);
}
private:
DISALLOW_COPY_AND_ASSIGN(
ScopedQuickUnlockPrivateGetAuthTokenFunctionObserver);
};
class OobeInteractiveUITest
: public OobeBaseTest,
public extensions::QuickUnlockPrivateGetAuthTokenFunction::TestObserver {
public:
OobeInteractiveUITest() = default;
~OobeInteractiveUITest() override = default;
......@@ -72,6 +94,11 @@ class OobeInteractiveUITest : public OobeBaseTest {
OobeBaseTest::SetUpCommandLine(command_line);
}
// QuickUnlockPrivateGetAuthTokenFunction::TestObserver:
void OnGetAuthTokenCalled(const std::string& password) override {
quick_unlock_private_get_auth_token_password_ = password;
}
void TearDownOnMainThread() override {
// If the login display is still showing, exit gracefully.
if (LoginDisplayHost::default_host()) {
......@@ -219,6 +246,41 @@ class OobeInteractiveUITest : public OobeBaseTest {
screen->SetProfileSyncDisabledByPolicyForTesting(true);
screen->OnStateChanged(nullptr);
JsConditionWaiter(js_checker_,
"Oobe.getInstance().currentScreen.id != 'sync-consent'")
.Wait();
LOG(INFO) << "OobeInteractiveUITest: 'sync-consent' screen done.";
}
void WaitForDiscoverScreen() {
JsConditionWaiter(js_checker_,
"Oobe.getInstance().currentScreen.id == 'discover'")
.Wait();
LOG(INFO) << "OobeInteractiveUITest: Switched to 'discover' screen.";
}
void RunDiscoverScreenChecks() {
js_checker_.ExpectTrue("!$('discover').hidden");
js_checker_.ExpectTrue("!$('discover-impl').hidden");
js_checker_.ExpectTrue(
"!$('discover-impl').root.querySelector('discover-pin-setup-module')."
"hidden");
js_checker_.ExpectTrue(
"!$('discover-impl').root.querySelector('discover-pin-setup-module').$."
"setup.hidden");
EXPECT_TRUE(quick_unlock_private_get_auth_token_password_.has_value());
EXPECT_EQ(quick_unlock_private_get_auth_token_password_,
OobeBaseTest::kFakeUserPassword);
}
void ExitDiscoverPinSetupScreen() {
js_checker_.Evaluate(
"$('discover-impl').root.querySelector('discover-pin-setup-module')."
"$.setupSkipButton.click()");
JsConditionWaiter(js_checker_,
"Oobe.getInstance().currentScreen.id != 'discover'")
.Wait();
LOG(INFO) << "OobeInteractiveUITest: 'discover' screen done.";
}
void WaitForMarketingOptInScreen() {
......@@ -260,12 +322,16 @@ class OobeInteractiveUITest : public OobeBaseTest {
WaitForLoginDisplayHostShutdown();
}
base::Optional<std::string> quick_unlock_private_get_auth_token_password_;
private:
DISALLOW_COPY_AND_ASSIGN(OobeInteractiveUITest);
};
// Flakily times out: crbug.com/891484.
IN_PROC_BROWSER_TEST_F(OobeInteractiveUITest, DISABLED_SimpleEndToEnd) {
ScopedQuickUnlockPrivateGetAuthTokenFunctionObserver scoped_observer(this);
WaitForOobeWelcomeScreen();
RunWelcomeScreenChecks();
TapWelcomeNext();
......@@ -291,6 +357,10 @@ IN_PROC_BROWSER_TEST_F(OobeInteractiveUITest, DISABLED_SimpleEndToEnd) {
ExitScreenSyncConsent();
#endif
WaitForDiscoverScreen();
RunDiscoverScreenChecks();
ExitDiscoverPinSetupScreen();
WaitForMarketingOptInScreen();
RunMarketingOptInScreenChecks();
ExitMarketingOptInScreen();
......
......@@ -94,6 +94,8 @@
#include "chrome/browser/supervised_user/child_accounts/child_account_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_client_impl.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#include "chrome/browser/ui/webui/chromeos/login/discover/discover_manager.h"
#include "chrome/browser/ui/webui/chromeos/login/discover/modules/discover_module_pin_setup.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/logging_chrome.h"
......@@ -1186,25 +1188,31 @@ void UserSessionManager::InitProfilePreferences(
input_method::InputMethodManager::Get();
manager->SetState(GetDefaultIMEState(profile));
}
user_manager::UserManager* user_manager = user_manager::UserManager::Get();
// Set initial prefs if the user is new, or if the user was already present on
// the device and the profile was re-created. This can happen e.g. in ext4
// migration in wipe mode.
if (user_manager::UserManager::Get()->IsCurrentUserNew() ||
profile->IsNewProfile()) {
if (user_manager->IsCurrentUserNew() || profile->IsNewProfile()) {
SetFirstLoginPrefs(profile, user_context.GetPublicSessionLocale(),
user_context.GetPublicSessionInputMethod());
if (user_manager->GetPrimaryUser() == user &&
user->GetType() == user_manager::USER_TYPE_REGULAR &&
!user_manager->IsUserNonCryptohomeDataEphemeral(user->GetAccountId())) {
chromeos::DiscoverManager::Get()
->GetModule<chromeos::DiscoverModulePinSetup>()
->SetPrimaryUserPassword(user_context.GetPasswordKey()->GetSecret());
}
}
if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) {
user_manager::User* active_user =
user_manager::UserManager::Get()->GetActiveUser();
if (user_manager->IsLoggedInAsSupervisedUser()) {
user_manager::User* active_user = user_manager->GetActiveUser();
std::string supervised_user_sync_id =
ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
active_user->GetAccountId().GetUserEmail());
profile->GetPrefs()->SetString(prefs::kSupervisedUserId,
supervised_user_sync_id);
} else if (user_manager::UserManager::Get()
->IsLoggedInAsUserWithGaiaAccount()) {
} else if (user_manager->IsLoggedInAsUserWithGaiaAccount()) {
// Get the Gaia ID from the user context. If it's not available, this may
// not be available when unlocking a previously opened profile, or when
// creating a supervised users. However, in these cases the gaia_id should
......@@ -1238,7 +1246,7 @@ void UserSessionManager::InitProfilePreferences(
/*refresh_token=*/std::string());
std::string account_id = identity_manager->GetPrimaryAccountId();
const user_manager::User* user =
user_manager::UserManager::Get()->FindUser(user_context.GetAccountId());
user_manager->FindUser(user_context.GetAccountId());
bool is_child = user->GetType() == user_manager::USER_TYPE_CHILD;
DCHECK(is_child ==
(user_context.GetUserType() == user_manager::USER_TYPE_CHILD));
......
......@@ -1124,6 +1124,10 @@ void WizardController::OnTermsOfServiceAccepted() {
}
void WizardController::OnSyncConsentFinished() {
ShowDiscoverScreen();
}
void WizardController::OnDiscoverScreenFinished() {
ShowMarketingOptInScreen();
}
......@@ -1742,7 +1746,7 @@ void WizardController::OnExit(ScreenExitCode exit_code) {
OnDemoPreferencesCanceled();
break;
case ScreenExitCode::DISCOVER_FINISHED:
OnOobeFlowFinished();
OnDiscoverScreenFinished();
break;
case ScreenExitCode::FINGERPRINT_SETUP_FINISHED:
OnFingerprintSetupFinished();
......
......@@ -231,6 +231,7 @@ class WizardController : public BaseScreenDelegate,
void OnTermsOfServiceDeclined();
void OnTermsOfServiceAccepted();
void OnSyncConsentFinished();
void OnDiscoverScreenFinished();
void OnFingerprintSetupFinished();
void OnArcTermsOfServiceSkipped();
void OnArcTermsOfServiceAccepted();
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/logging.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/ui/webui/chromeos/login/discover/discover_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/discover/modules/discover_module_launch_help_app.h"
#include "chrome/browser/ui/webui/chromeos/login/discover/modules/discover_module_pin_setup.h"
......@@ -22,6 +23,11 @@ DiscoverManager::DiscoverManager() {
DiscoverManager::~DiscoverManager() = default;
// static
DiscoverManager* DiscoverManager::Get() {
return g_browser_process->platform_part()->GetDiscoverManager();
}
bool DiscoverManager::IsCompleted() const {
// Returns true if all of the modules are completed.
return std::all_of(modules_.begin(), modules_.end(),
......@@ -52,7 +58,7 @@ DiscoverManager::CreateWebUIHandlers() const {
return handlers;
}
DiscoverModule* DiscoverManager::GetModule(
DiscoverModule* DiscoverManager::GetModuleByName(
const std::string& module_name) const {
const auto it = modules_.find(module_name);
return it == modules_.end() ? nullptr : it->second.get();
......
......@@ -25,19 +25,29 @@ class DiscoverManager {
DiscoverManager();
~DiscoverManager();
// Returns object instance from platform_parts.
static DiscoverManager* Get();
// Returns true if there are no modules to be displayed.
bool IsCompleted() const;
// Returns vector of WebUI message handlers for visible modules.
std::vector<std::unique_ptr<DiscoverHandler>> CreateWebUIHandlers() const;
DiscoverModule* GetModule(const std::string& module_name) const;
template <typename T>
T* GetModule() {
return static_cast<T*>(GetModuleByName(T::kModuleName));
}
const ModulesMap& get_modules() const { return modules_; }
private:
// Creates all needed modules.
void CreateModules();
// Returns module by name.
DiscoverModule* GetModuleByName(const std::string& module_name) const;
ModulesMap modules_;
DISALLOW_COPY_AND_ASSIGN(DiscoverManager);
......
......@@ -4,7 +4,6 @@
#include "chrome/browser/ui/webui/chromeos/login/discover/discover_ui.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/ui/webui/chromeos/login/discover/discover_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/discover/discover_manager.h"
#include "content/public/browser/web_ui.h"
......@@ -17,9 +16,7 @@ DiscoverUI::~DiscoverUI() {}
void DiscoverUI::RegisterMessages(content::WebUI* web_ui) {
std::vector<std::unique_ptr<DiscoverHandler>> handlers =
g_browser_process->platform_part()
->GetDiscoverManager()
->CreateWebUIHandlers();
DiscoverManager::Get()->CreateWebUIHandlers();
for (auto& handler : handlers) {
handlers_.push_back(handler.get());
web_ui->AddMessageHandler(std::move(handler));
......
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