Home | History | Annotate | Download | only in login
      1 // Copyright (c) 2011 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 #include "base/command_line.h"
      6 #include "base/time.h"
      7 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h"
      8 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h"
      9 #include "chrome/browser/chromeos/cros/mock_input_method_library.h"
     10 #include "chrome/browser/chromeos/cros/mock_library_loader.h"
     11 #include "chrome/browser/chromeos/cros/mock_network_library.h"
     12 #include "chrome/browser/chromeos/cros/mock_power_library.h"
     13 #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h"
     14 #include "chrome/browser/chromeos/cros/mock_touchpad_library.h"
     15 #include "chrome/browser/profiles/profile_manager.h"
     16 #include "chrome/browser/ui/browser.h"
     17 #include "chrome/common/chrome_switches.h"
     18 #include "chrome/test/in_process_browser_test.h"
     19 #include "chrome/test/ui_test_utils.h"
     20 #include "testing/gmock/include/gmock/gmock.h"
     21 #include "testing/gtest/include/gtest/gtest.h"
     22 
     23 namespace chromeos {
     24 using ::testing::_;
     25 using ::testing::AnyNumber;
     26 using ::testing::InvokeWithoutArgs;
     27 using ::testing::NiceMock;
     28 using ::testing::Return;
     29 using ::testing::ReturnRef;
     30 
     31 class LoginTestBase : public CrosInProcessBrowserTest {
     32  public:
     33   LoginTestBase() : mock_cryptohome_library_(NULL),
     34                     mock_screen_lock_library_(NULL) {
     35   }
     36 
     37  protected:
     38   virtual void SetUpInProcessBrowserTestFixture() {
     39     cros_mock_->InitStatusAreaMocks();
     40     cros_mock_->SetStatusAreaMocksExpectations();
     41     cros_mock_->InitMockCryptohomeLibrary();
     42     cros_mock_->InitMockScreenLockLibrary();
     43     mock_cryptohome_library_ = cros_mock_->mock_cryptohome_library();
     44     mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library();
     45     EXPECT_CALL(*mock_cryptohome_library_, IsMounted())
     46         .WillRepeatedly(Return(true));
     47   }
     48 
     49   MockCryptohomeLibrary* mock_cryptohome_library_;
     50   MockScreenLockLibrary* mock_screen_lock_library_;
     51 
     52  private:
     53   DISALLOW_COPY_AND_ASSIGN(LoginTestBase);
     54 };
     55 
     56 class LoginUserTest : public LoginTestBase {
     57  protected:
     58   virtual void SetUpInProcessBrowserTestFixture() {
     59     LoginTestBase::SetUpInProcessBrowserTestFixture();
     60     EXPECT_CALL(*mock_screen_lock_library_, AddObserver(_))
     61         .WillOnce(Return());
     62   }
     63 
     64   virtual void SetUpCommandLine(CommandLine* command_line) {
     65     command_line->AppendSwitchASCII(switches::kLoginUser, "TestUser (at) gmail.com");
     66     command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
     67     command_line->AppendSwitch(switches::kNoFirstRun);
     68   }
     69 };
     70 
     71 class LoginProfileTest : public LoginTestBase {
     72  protected:
     73   virtual void SetUpCommandLine(CommandLine* command_line) {
     74     command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
     75     command_line->AppendSwitch(switches::kNoFirstRun);
     76   }
     77 };
     78 
     79 // After a chrome crash, the session manager will restart chrome with
     80 // the -login-user flag indicating that the user is already logged in.
     81 // This profile should NOT be an OTR profile.
     82 IN_PROC_BROWSER_TEST_F(LoginUserTest, UserPassed) {
     83   Profile* profile = browser()->profile();
     84   EXPECT_EQ("user", profile->GetPath().BaseName().value());
     85   EXPECT_FALSE(profile->IsOffTheRecord());
     86 }
     87 
     88 // On initial launch, we should get the OTR default profile.
     89 IN_PROC_BROWSER_TEST_F(LoginProfileTest, UserNotPassed) {
     90   Profile* profile = browser()->profile();
     91   EXPECT_EQ("Default", profile->GetPath().BaseName().value());
     92   EXPECT_TRUE(profile->IsOffTheRecord());
     93   // Ensure there's extension service for this profile.
     94   EXPECT_TRUE(profile->GetExtensionService());
     95 }
     96 
     97 } // namespace chromeos
     98