OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/time.h" | 6 #include "base/time.h" |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 8 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
9 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" | 9 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" |
10 #include "chrome/browser/chromeos/cros/mock_input_method_library.h" | 10 #include "chrome/browser/chromeos/cros/mock_input_method_library.h" |
11 #include "chrome/browser/chromeos/cros/mock_keyboard_library.h" | 11 #include "chrome/browser/chromeos/cros/mock_keyboard_library.h" |
12 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | 12 #include "chrome/browser/chromeos/cros/mock_library_loader.h" |
13 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 13 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
14 #include "chrome/browser/chromeos/cros/mock_power_library.h" | 14 #include "chrome/browser/chromeos/cros/mock_power_library.h" |
15 #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h" | 15 #include "chrome/browser/chromeos/cros/mock_screen_lock_library.h" |
16 #include "chrome/browser/chromeos/cros/mock_system_library.h" | 16 #include "chrome/browser/chromeos/cros/mock_system_library.h" |
17 #include "chrome/browser/chromeos/cros/mock_touchpad_library.h" | 17 #include "chrome/browser/chromeos/cros/mock_touchpad_library.h" |
18 #include "chrome/browser/profile_manager.h" | 18 #include "chrome/browser/profile_manager.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/test/in_process_browser_test.h" | 20 #include "chrome/test/in_process_browser_test.h" |
21 #include "chrome/test/ui_test_utils.h" | 21 #include "chrome/test/ui_test_utils.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
24 | 24 |
25 namespace chromeos { | 25 namespace chromeos { |
26 using ::testing::_; | 26 using ::testing::_; |
| 27 using ::testing::AnyNumber; |
27 using ::testing::InvokeWithoutArgs; | 28 using ::testing::InvokeWithoutArgs; |
| 29 using ::testing::NiceMock; |
28 using ::testing::Return; | 30 using ::testing::Return; |
29 using ::testing::ReturnRef; | 31 using ::testing::ReturnRef; |
30 using ::testing::NiceMock; | |
31 | 32 |
32 class LoginTestBase : public InProcessBrowserTest { | 33 class LoginTestBase : public CrosInProcessBrowserTest { |
33 public: | 34 public: |
34 LoginTestBase() { | 35 LoginTestBase() : mock_cryptohome_library_(NULL), |
35 testApi_ = chromeos::CrosLibrary::Get()->GetTestApi(); | 36 mock_screen_lock_library_(NULL) { |
36 testApi_->SetLibraryLoader(&loader_, false); | |
37 EXPECT_CALL(loader_, Load(_)) | |
38 .WillRepeatedly(Return(true)); | |
39 | |
40 testApi_->SetKeyboardLibrary(&mock_keyboard_library_, false); | |
41 testApi_->SetInputMethodLibrary(&mock_input_method_library_, false); | |
42 EXPECT_CALL(mock_input_method_library_, GetActiveInputMethods()) | |
43 .WillRepeatedly( | |
44 InvokeWithoutArgs(CreateFallbackInputMethodDescriptors)); | |
45 | |
46 testApi_->SetNetworkLibrary(&mock_network_library_, false); | |
47 | |
48 testApi_->SetPowerLibrary(&mock_power_library_, false); | |
49 EXPECT_CALL(mock_power_library_, battery_time_to_empty()) | |
50 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(42)))); | |
51 EXPECT_CALL(mock_power_library_, battery_time_to_full()) | |
52 .WillRepeatedly((Return(base::TimeDelta::FromMinutes(24)))); | |
53 | |
54 testApi_->SetTouchpadLibrary(&mock_touchpad_library_, false); | |
55 testApi_->SetCryptohomeLibrary(&mock_cryptohome_library_, false); | |
56 testApi_->SetScreenLockLibrary(&mock_screen_lock_library_, false); | |
57 testApi_->SetSystemLibrary(&mock_system_library_, false); | |
58 } | 37 } |
59 | 38 |
60 protected: | 39 protected: |
61 NiceMock<MockLibraryLoader> loader_; | 40 virtual void SetUpInProcessBrowserTestFixture() { |
62 NiceMock<MockCryptohomeLibrary> mock_cryptohome_library_; | 41 cros_mock_->InitStatusAreaMocks(); |
63 NiceMock<MockKeyboardLibrary> mock_keyboard_library_; | 42 cros_mock_->SetStatusAreaMocksExpectations(); |
64 NiceMock<MockInputMethodLibrary> mock_input_method_library_; | 43 cros_mock_->InitMockCryptohomeLibrary(); |
65 NiceMock<MockNetworkLibrary> mock_network_library_; | 44 cros_mock_->InitMockScreenLockLibrary(); |
66 NiceMock<MockPowerLibrary> mock_power_library_; | 45 mock_cryptohome_library_ = cros_mock_->mock_cryptohome_library(); |
67 NiceMock<MockScreenLockLibrary> mock_screen_lock_library_; | 46 mock_screen_lock_library_ = cros_mock_->mock_screen_lock_library(); |
68 NiceMock<MockTouchpadLibrary> mock_touchpad_library_; | 47 EXPECT_CALL(*mock_cryptohome_library_, IsMounted()) |
69 NiceMock<MockSystemLibrary> mock_system_library_; | 48 .WillRepeatedly(Return(true)); |
70 ImePropertyList ime_properties_; | 49 } |
71 chromeos::CrosLibrary::TestApi* testApi_; | 50 |
| 51 MockCryptohomeLibrary* mock_cryptohome_library_; |
| 52 MockScreenLockLibrary* mock_screen_lock_library_; |
| 53 |
| 54 private: |
| 55 DISALLOW_COPY_AND_ASSIGN(LoginTestBase); |
72 }; | 56 }; |
73 | 57 |
74 class LoginUserTest : public LoginTestBase { | 58 class LoginUserTest : public LoginTestBase { |
75 public: | 59 protected: |
76 LoginUserTest() { | 60 virtual void SetUpInProcessBrowserTestFixture() { |
77 EXPECT_CALL(mock_cryptohome_library_, IsMounted()) | 61 LoginTestBase::SetUpInProcessBrowserTestFixture(); |
78 .WillRepeatedly(Return(true)); | 62 EXPECT_CALL(*mock_screen_lock_library_, AddObserver(_)) |
79 EXPECT_CALL(mock_screen_lock_library_, AddObserver(_)) | |
80 .WillOnce(Return()); | 63 .WillOnce(Return()); |
81 } | 64 } |
82 | 65 |
83 virtual void SetUpCommandLine(CommandLine* command_line) { | 66 virtual void SetUpCommandLine(CommandLine* command_line) { |
84 command_line->AppendSwitchASCII(switches::kLoginUser, "TestUser@gmail.com"); | 67 command_line->AppendSwitchASCII(switches::kLoginUser, "TestUser@gmail.com"); |
85 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 68 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
86 command_line->AppendSwitch(switches::kNoFirstRun); | 69 command_line->AppendSwitch(switches::kNoFirstRun); |
87 } | 70 } |
88 }; | 71 }; |
89 | 72 |
90 class LoginProfileTest : public LoginTestBase { | 73 class LoginProfileTest : public LoginTestBase { |
91 public: | 74 protected: |
92 LoginProfileTest() { | |
93 EXPECT_CALL(mock_cryptohome_library_, IsMounted()) | |
94 .WillRepeatedly(Return(true)); | |
95 } | |
96 | |
97 virtual void SetUpCommandLine(CommandLine* command_line) { | 75 virtual void SetUpCommandLine(CommandLine* command_line) { |
98 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 76 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
99 command_line->AppendSwitch(switches::kNoFirstRun); | 77 command_line->AppendSwitch(switches::kNoFirstRun); |
100 } | 78 } |
101 }; | 79 }; |
102 | 80 |
103 // After a chrome crash, the session manager will restart chrome with | 81 // After a chrome crash, the session manager will restart chrome with |
104 // the -login-user flag indicating that the user is already logged in. | 82 // the -login-user flag indicating that the user is already logged in. |
105 // This profile should NOT be an OTR profile. | 83 // This profile should NOT be an OTR profile. |
106 IN_PROC_BROWSER_TEST_F(LoginUserTest, UserPassed) { | 84 IN_PROC_BROWSER_TEST_F(LoginUserTest, UserPassed) { |
107 Profile* profile = browser()->profile(); | 85 Profile* profile = browser()->profile(); |
108 EXPECT_EQ("user", profile->GetPath().BaseName().value()); | 86 EXPECT_EQ("user", profile->GetPath().BaseName().value()); |
109 EXPECT_FALSE(profile->IsOffTheRecord()); | 87 EXPECT_FALSE(profile->IsOffTheRecord()); |
110 } | 88 } |
111 | 89 |
112 // On initial launch, we should get the OTR default profile. | 90 // On initial launch, we should get the OTR default profile. |
113 IN_PROC_BROWSER_TEST_F(LoginProfileTest, UserNotPassed) { | 91 IN_PROC_BROWSER_TEST_F(LoginProfileTest, UserNotPassed) { |
114 Profile* profile = browser()->profile(); | 92 Profile* profile = browser()->profile(); |
115 EXPECT_EQ("Default", profile->GetPath().BaseName().value()); | 93 EXPECT_EQ("Default", profile->GetPath().BaseName().value()); |
116 EXPECT_TRUE(profile->IsOffTheRecord()); | 94 EXPECT_TRUE(profile->IsOffTheRecord()); |
117 // Ensure there's no extension service for this profile. | 95 // Ensure there's no extension service for this profile. |
118 EXPECT_EQ(NULL, profile->GetExtensionsService()); | 96 EXPECT_EQ(NULL, profile->GetExtensionsService()); |
119 } | 97 } |
120 | 98 |
121 } // namespace chromeos | 99 } // namespace chromeos |
OLD | NEW |