OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/force_signin_verifier.h" | 5 #include "chrome/browser/signin/force_signin_verifier.h" |
6 | 6 |
7 #include "chrome/test/base/testing_profile.h" | 7 #include "chrome/test/base/testing_profile.h" |
8 #include "content/public/test/test_browser_thread_bundle.h" | 8 #include "content/public/test/test_browser_thread_bundle.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 class MockForceSigninVerifier : public ForceSigninVerifier { | 12 class MockForceSigninVerifier : public ForceSigninVerifier { |
13 public: | 13 public: |
14 explicit MockForceSigninVerifier(Profile* profile) | 14 explicit MockForceSigninVerifier(Profile* profile) |
15 : ForceSigninVerifier(profile) {} | 15 : ForceSigninVerifier(profile) {} |
16 | 16 |
17 bool ShouldSendRequest() override { return true; } | 17 bool ShouldSendRequest() override { return true; } |
18 | 18 |
19 void SendTestRequest() { SendRequest(); } | 19 void SendTestRequest() { SendRequest(); } |
20 | 20 |
21 bool IsDelayTaskPosted() { return GetOneShotTimerForTesting()->IsRunning(); } | 21 bool IsDelayTaskPosted() { return GetOneShotTimerForTesting()->IsRunning(); } |
22 | 22 |
23 int FailureCount() { return GetBackoffEntryForTesting()->failure_count(); } | 23 int FailureCount() { return GetBackoffEntryForTesting()->failure_count(); } |
24 | 24 |
25 OAuth2TokenService::Request* request() { return GetRequestForTesting(); } | 25 OAuth2TokenService::Request* request() { return GetRequestForTesting(); } |
26 | 26 |
| 27 bool IsCountdownTimerRunning() { |
| 28 base::Timer* timer = GetWindowCloseTimerForTesting(); |
| 29 return timer && timer->IsRunning(); |
| 30 } |
| 31 |
| 32 void OnShowDialog() { StartCountdown(); } |
| 33 |
27 MOCK_METHOD0(ShowDialog, void(void)); | 34 MOCK_METHOD0(ShowDialog, void(void)); |
28 }; | 35 }; |
29 | 36 |
30 class ForceSigninVerifierTest : public ::testing::Test { | 37 class ForceSigninVerifierTest : public ::testing::Test { |
31 public: | 38 public: |
32 void SetUp() override { | 39 void SetUp() override { |
33 verifier_ = base::MakeUnique<MockForceSigninVerifier>(&profile_); | 40 verifier_ = base::MakeUnique<MockForceSigninVerifier>(&profile_); |
34 } | 41 } |
35 | 42 |
36 void TearDown() override { verifier_.reset(); } | 43 void TearDown() override { verifier_.reset(); } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 ASSERT_EQ(nullptr, verifier_->request()); | 124 ASSERT_EQ(nullptr, verifier_->request()); |
118 ASSERT_TRUE(verifier_->IsDelayTaskPosted()); | 125 ASSERT_TRUE(verifier_->IsDelayTaskPosted()); |
119 | 126 |
120 verifier_->OnNetworkChanged( | 127 verifier_->OnNetworkChanged( |
121 net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); | 128 net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
122 | 129 |
123 ASSERT_EQ(0, verifier_->FailureCount()); | 130 ASSERT_EQ(0, verifier_->FailureCount()); |
124 ASSERT_NE(nullptr, verifier_->request()); | 131 ASSERT_NE(nullptr, verifier_->request()); |
125 ASSERT_FALSE(verifier_->IsDelayTaskPosted()); | 132 ASSERT_FALSE(verifier_->IsDelayTaskPosted()); |
126 } | 133 } |
| 134 |
| 135 TEST_F(ForceSigninVerifierTest, OnGetTokenPersistentFailureAndStartCountdown) { |
| 136 ASSERT_EQ(nullptr, verifier_->request()); |
| 137 ASSERT_FALSE(verifier_->IsCountdownTimerRunning()); |
| 138 EXPECT_CALL(*verifier_.get(), ShowDialog()) |
| 139 .WillOnce(::testing::Invoke(verifier_.get(), |
| 140 &MockForceSigninVerifier::OnShowDialog)); |
| 141 |
| 142 verifier_->SendTestRequest(); |
| 143 verifier_->OnGetTokenFailure(verifier_->request(), persistent_error_); |
| 144 |
| 145 ASSERT_TRUE(verifier_->IsCountdownTimerRunning()); |
| 146 } |
OLD | NEW |