Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/signin/chrome_signin_client.h" | 5 #include "chrome/browser/signin/chrome_signin_client.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/prefs/browser_prefs.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 15 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 16 #include "chrome/browser/signin/signin_error_controller_factory.h" | |
| 17 #include "chrome/common/pref_names.h" | |
| 18 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 19 #include "chrome/test/base/testing_browser_process.h" | |
| 13 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "components/prefs/testing_pref_service.h" | |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "net/base/network_change_notifier.h" | 23 #include "net/base/network_change_notifier.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 26 |
| 18 // ChromeOS has its own network delay logic. | 27 // ChromeOS has its own network delay logic. |
| 19 #if !defined(OS_CHROMEOS) | 28 #if !defined(OS_CHROMEOS) |
| 20 | 29 |
| 21 namespace { | 30 namespace { |
| 22 | 31 |
| 23 class MockNetworkChangeNotifierNeverOffline : | 32 class MockNetworkChangeNotifierNeverOffline : |
| 24 public net::NetworkChangeNotifier { | 33 public net::NetworkChangeNotifier { |
| 25 public: | 34 public: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 | 118 |
| 110 CallbackTester tester; | 119 CallbackTester tester; |
| 111 signin_client()->DelayNetworkCall(base::Bind(&CallbackTester::Increment, | 120 signin_client()->DelayNetworkCall(base::Bind(&CallbackTester::Increment, |
| 112 base::Unretained(&tester))); | 121 base::Unretained(&tester))); |
| 113 ASSERT_FALSE(tester.WasCalledExactlyOnce()); | 122 ASSERT_FALSE(tester.WasCalledExactlyOnce()); |
| 114 mock->GoOnline(); | 123 mock->GoOnline(); |
| 115 base::RunLoop().RunUntilIdle(); | 124 base::RunLoop().RunUntilIdle(); |
| 116 ASSERT_TRUE(tester.WasCalledExactlyOnce()); | 125 ASSERT_TRUE(tester.WasCalledExactlyOnce()); |
| 117 } | 126 } |
| 118 | 127 |
| 128 #if !defined(OS_ANDROID) | |
| 129 | |
| 130 class MockChromeSigninClient : public ChromeSigninClient { | |
| 131 public: | |
| 132 MockChromeSigninClient(Profile* profile, SigninErrorController* controller) | |
| 133 : ChromeSigninClient(profile, controller) {} | |
| 134 | |
| 135 MOCK_METHOD1(ShowUserManager, void(const base::FilePath&)); | |
| 136 MOCK_METHOD1(LockProfile, void(const base::FilePath&)); | |
| 137 }; | |
| 138 | |
| 139 class MockSigninManager : public SigninManager { | |
| 140 public: | |
| 141 explicit MockSigninManager(SigninClient* client) | |
| 142 : SigninManager(client, nullptr, &fake_service_, nullptr) {} | |
| 143 | |
| 144 MOCK_METHOD2(DoSignOut, | |
| 145 void(signin_metrics::ProfileSignout, | |
| 146 signin_metrics::SignoutDelete)); | |
| 147 | |
| 148 AccountTrackerService fake_service_; | |
| 149 }; | |
| 150 | |
| 151 class ChromeSigninClientSignoutTest : public BrowserWithTestWindowTest { | |
| 152 public: | |
| 153 void SetUp() override { | |
| 154 BrowserWithTestWindowTest::SetUp(); | |
| 155 | |
| 156 prefs_.reset(new TestingPrefServiceSimple()); | |
| 157 chrome::RegisterLocalState(prefs_->registry()); | |
| 158 TestingBrowserProcess::GetGlobal()->SetLocalState(prefs_.get()); | |
| 159 prefs_->SetBoolean(prefs::kForceBrowserSignin, true); | |
| 160 | |
| 161 CreateClient(browser()->profile()); | |
| 162 manager_.reset(new MockSigninManager(client_.get())); | |
| 163 } | |
| 164 | |
| 165 void TearDown() override { | |
| 166 BrowserWithTestWindowTest::TearDown(); | |
| 167 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr); | |
| 168 } | |
| 169 | |
| 170 void CreateClient(Profile* profile) { | |
| 171 SigninErrorController* controller = new SigninErrorController(); | |
| 172 client_.reset(new MockChromeSigninClient(profile, controller)); | |
| 173 fake_controller_.reset(controller); | |
| 174 } | |
| 175 | |
| 176 std::unique_ptr<SigninErrorController> fake_controller_; | |
| 177 std::unique_ptr<MockChromeSigninClient> client_; | |
| 178 std::unique_ptr<MockSigninManager> manager_; | |
| 179 std::unique_ptr<TestingPrefServiceSimple> prefs_; | |
| 180 }; | |
| 181 | |
| 182 TEST_F(ChromeSigninClientSignoutTest, SignOut) { | |
| 183 signin_metrics::ProfileSignout source_metric = | |
| 184 signin_metrics::ProfileSignout::SIGNOUT_TEST; | |
| 185 signin_metrics::SignoutDelete delete_metric = | |
| 186 signin_metrics::SignoutDelete::IGNORE_METRIC; | |
| 187 | |
| 188 EXPECT_CALL(*client_, ShowUserManager(browser()->profile()->GetPath())) | |
| 189 .Times(1); | |
| 190 EXPECT_CALL(*client_, LockProfile(browser()->profile()->GetPath())).Times(1); | |
| 191 EXPECT_CALL(*manager_, DoSignOut(source_metric, delete_metric)).Times(1); | |
| 192 | |
| 193 manager_->SignOut(source_metric, delete_metric); | |
| 194 } | |
| 195 | |
| 196 TEST_F(ChromeSigninClientSignoutTest, SignOutWithoutManager) { | |
| 197 signin_metrics::ProfileSignout source_metric = | |
| 198 signin_metrics::ProfileSignout::SIGNOUT_TEST; | |
| 199 signin_metrics::SignoutDelete delete_metric = | |
| 200 signin_metrics::SignoutDelete::IGNORE_METRIC; | |
| 201 | |
| 202 MockSigninManager other_manager(client_.get()); | |
| 203 other_manager.CopyCredentialsFrom(*manager_.get()); | |
| 204 | |
| 205 EXPECT_CALL(*client_, ShowUserManager(browser()->profile()->GetPath())) | |
| 206 .Times(0); | |
| 207 EXPECT_CALL(*client_, LockProfile(browser()->profile()->GetPath())).Times(1); | |
| 208 EXPECT_CALL(*manager_, DoSignOut(source_metric, delete_metric)).Times(1); | |
| 209 manager_->SignOut(source_metric, delete_metric); | |
| 210 | |
| 211 EXPECT_CALL(*client_, ShowUserManager(browser()->profile()->GetPath())) | |
|
Roger Tawa OOO till Jul 10th
2016/11/02 13:20:39
Do you need to check and reset the expectations be
zmin
2016/11/02 20:30:22
Done.
| |
| 212 .Times(1); | |
| 213 EXPECT_CALL(*client_, LockProfile(browser()->profile()->GetPath())).Times(1); | |
| 214 EXPECT_CALL(*manager_, DoSignOut(source_metric, delete_metric)).Times(1); | |
| 215 manager_->SignOut(source_metric, delete_metric); | |
| 216 } | |
| 217 | |
| 218 TEST_F(ChromeSigninClientSignoutTest, SignOutWithoutForceSignin) { | |
| 219 prefs_->SetBoolean(prefs::kForceBrowserSignin, false); | |
| 220 CreateClient(browser()->profile()); | |
| 221 manager_.reset(new MockSigninManager(client_.get())); | |
| 222 | |
| 223 signin_metrics::ProfileSignout source_metric = | |
| 224 signin_metrics::ProfileSignout::SIGNOUT_TEST; | |
| 225 signin_metrics::SignoutDelete delete_metric = | |
| 226 signin_metrics::SignoutDelete::IGNORE_METRIC; | |
| 227 | |
| 228 EXPECT_CALL(*client_, ShowUserManager(browser()->profile()->GetPath())) | |
| 229 .Times(0); | |
| 230 EXPECT_CALL(*client_, LockProfile(browser()->profile()->GetPath())).Times(0); | |
| 231 EXPECT_CALL(*manager_, DoSignOut(source_metric, delete_metric)).Times(1); | |
| 232 manager_->SignOut(source_metric, delete_metric); | |
| 233 } | |
| 234 | |
| 235 TEST_F(ChromeSigninClientSignoutTest, SignOutGuestSession) { | |
| 236 TestingProfile::Builder builder; | |
| 237 builder.SetGuestSession(); | |
| 238 std::unique_ptr<TestingProfile> profile = builder.Build(); | |
| 239 | |
| 240 CreateClient(profile.get()); | |
| 241 manager_.reset(new MockSigninManager(client_.get())); | |
| 242 | |
| 243 signin_metrics::ProfileSignout source_metric = | |
| 244 signin_metrics::ProfileSignout::SIGNOUT_TEST; | |
| 245 signin_metrics::SignoutDelete delete_metric = | |
| 246 signin_metrics::SignoutDelete::IGNORE_METRIC; | |
| 247 | |
| 248 EXPECT_CALL(*client_, ShowUserManager(browser()->profile()->GetPath())) | |
| 249 .Times(0); | |
| 250 EXPECT_CALL(*client_, LockProfile(browser()->profile()->GetPath())).Times(0); | |
| 251 EXPECT_CALL(*manager_, DoSignOut(source_metric, delete_metric)).Times(1); | |
| 252 manager_->SignOut(source_metric, delete_metric); | |
| 253 } | |
| 254 | |
| 119 #endif | 255 #endif |
| 256 #endif | |
|
Roger Tawa OOO till Jul 10th
2016/11/02 13:20:39
Please add comments to the #endifs.
zmin
2016/11/02 20:30:22
Done.
| |
| OLD | NEW |