17d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file.
47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/chromeos/login/fake_login_utils.h"
67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/command_line.h"
87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/path_service.h"
97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/browser_process.h"
107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/chromeos/login/login_display_host.h"
117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/chromeos/login/mock_authenticator.h"
127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/first_run/first_run.h"
137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/ui/startup/startup_browser_creator.h"
157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/common/chrome_constants.h"
167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/common/chrome_paths.h"
177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/test/base/testing_profile.h"
187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace chromeos {
217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)FakeLoginUtils::FakeLoginUtils() : should_launch_browser_(false) {}
237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)FakeLoginUtils::~FakeLoginUtils() {}
257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::DoBrowserLaunch(Profile* profile,
277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                     LoginDisplayHost* login_host) {
281347ae41cdcd6a32dafcda3a178e53b6d8e88f2cTorne (Richard Coles)  login_host->BeforeSessionStart();
297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (should_launch_browser_) {
307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    StartupBrowserCreator browser_creator;
317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    chrome::startup::IsFirstRun first_run =
327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN
337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      : chrome::startup::IS_NOT_FIRST_RUN;
347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    ASSERT_TRUE(
357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(),
367d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      profile,
377d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      base::FilePath(),
387d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      chrome::startup::IS_PROCESS_STARTUP,
397d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      first_run,
407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                      NULL));
417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (login_host)
437d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    login_host->Finalize();
441347ae41cdcd6a32dafcda3a178e53b6d8e88f2cTorne (Richard Coles)  UserManager::Get()->SessionStarted();
457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::PrepareProfile(const UserContext& user_context,
487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                    const std::string& display_email,
497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                    bool using_oauth,
507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                    bool has_cookies,
517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                    bool has_active_session,
527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                    LoginUtils::Delegate* delegate) {
537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  UserManager::Get()->UserLoggedIn(
547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      user_context.username, user_context.username_hash, false);
557d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  Profile* profile;
567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (should_launch_browser_) {
577d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    profile = CreateProfile(user_context.username);
587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  } else {
597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    profile = new TestingProfile();
607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    g_browser_process->profile_manager()->
617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        RegisterTestingProfile(profile, false, false);
627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (delegate)
647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    delegate->OnProfilePrepared(profile);
657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) {
687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  NOTREACHED() << "Method not implemented.";
697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
707d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
717d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::CompleteOffTheRecordLogin(const GURL& start_url) {
727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  NOTREACHED() << "Method not implemented.";
737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::SetFirstLoginPrefs(PrefService* prefs) {
767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  NOTREACHED() << "Method not implemented.";
777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator(
807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    LoginStatusConsumer* consumer) {
817d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  authenticator_ =
827d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)      new MockAuthenticator(consumer, expected_username_, expected_password_);
837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return authenticator_;
847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
857d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::RestoreAuthenticationSession(Profile* profile) {
877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  NOTREACHED() << "Method not implemented.";
887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::StopBackgroundFetchers() {
917d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  NOTREACHED() << "Method not implemented.";
927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::InitRlzDelayed(Profile* user_profile) {
957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  NOTREACHED() << "Method not implemented.";
967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)Profile* FakeLoginUtils::CreateProfile(const std::string& username_hash) {
997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  base::FilePath path;
1007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  PathService::Get(chrome::DIR_USER_DATA, &path);
1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  path = path.AppendASCII(chrome::kProfileDirPrefix + username_hash);
1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  Profile* profile = g_browser_process->profile_manager()->GetProfile(path);
1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  return profile;
1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)void FakeLoginUtils::SetExpectedCredentials(const std::string& username,
1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)                                            const std::string& password) {
1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  expected_username_ = username;
1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  expected_password_ = password;
1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  if (authenticator_.get()) {
1117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    static_cast<MockAuthenticator*>(authenticator_.get())->
1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)        SetExpectedCredentials(username, password);
1137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)  }
1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}
1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)
1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}  //  namespace chromeos
117