Home | History | Annotate | Download | only in login
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_LOGIN_UTILS_H_
      6 #define CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_LOGIN_UTILS_H_
      7 
      8 #include "chrome/browser/chromeos/login/login_utils.h"
      9 
     10 namespace chromeos {
     11 
     12 // This class emulates behavior of LoginUtils for browser tests.
     13 // It provides:
     14 //  * Fake authentication. You can configure expected usernames and password for
     15 //    next auth attempt.
     16 //  * Preparing of profiles for authenticated users.
     17 //  * Launching browser for user, if |should_launch_browser_| set.
     18 //  * Correct communication with LoginDisplayHost and UserManager.
     19 class FakeLoginUtils : public LoginUtils {
     20  public:
     21   FakeLoginUtils();
     22   virtual ~FakeLoginUtils();
     23   virtual void DoBrowserLaunch(Profile* profile,
     24                                LoginDisplayHost* login_host) OVERRIDE;
     25   virtual void PrepareProfile(const UserContext& user_context,
     26                               const std::string& display_email,
     27                               bool using_oauth,
     28                               bool has_cookies,
     29                               bool has_active_session,
     30                               LoginUtils::Delegate* delegate) OVERRIDE;
     31   virtual void DelegateDeleted(LoginUtils::Delegate* delegate) OVERRIDE;
     32   virtual void CompleteOffTheRecordLogin(const GURL& start_url) OVERRIDE;
     33   virtual void SetFirstLoginPrefs(PrefService* prefs) OVERRIDE;
     34   virtual scoped_refptr<Authenticator> CreateAuthenticator(
     35       LoginStatusConsumer* consumer) OVERRIDE;
     36   virtual void RestoreAuthenticationSession(Profile* profile) OVERRIDE;
     37   virtual void StopBackgroundFetchers() OVERRIDE;
     38   virtual void InitRlzDelayed(Profile* user_profile) OVERRIDE;
     39 
     40   void SetExpectedCredentials(const std::string& username,
     41                               const std::string& password);
     42   void set_should_launch_browser(bool should_launch_browser) {
     43     should_launch_browser_ = should_launch_browser;
     44   }
     45 
     46  private:
     47   Profile* CreateProfile(const std::string& username_hash);
     48 
     49   scoped_refptr<Authenticator> authenticator_;
     50   std::string expected_username_;
     51   std::string expected_password_;
     52   bool should_launch_browser_;
     53 
     54   DISALLOW_COPY_AND_ASSIGN(FakeLoginUtils);
     55 };
     56 
     57 }  // namespace chromeos
     58 
     59 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_LOGIN_UTILS_H_
     60