OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | |
12 #include "chrome/browser/chromeos/login/auth_attempt_state.h" | 11 #include "chrome/browser/chromeos/login/auth_attempt_state.h" |
13 #include "chrome/browser/chromeos/login/mock_auth_attempt_state_resolver.h" | 12 #include "chrome/browser/chromeos/login/mock_auth_attempt_state_resolver.h" |
14 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" | 13 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
15 #include "chrome/browser/chromeos/login/online_attempt.h" | 14 #include "chrome/browser/chromeos/login/online_attempt.h" |
16 #include "chrome/browser/chromeos/login/test_attempt_state.h" | 15 #include "chrome/browser/chromeos/login/test_attempt_state.h" |
17 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 16 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
18 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" | 17 #include "chrome/common/net/gaia/mock_url_fetcher_factory.h" |
19 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
20 #include "content/public/test/test_browser_thread.h" | 19 #include "content/public/test/test_browser_thread.h" |
21 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
(...skipping 13 matching lines...) Expand all Loading... |
35 OnlineAttemptTest() | 34 OnlineAttemptTest() |
36 : message_loop_(MessageLoop::TYPE_UI), | 35 : message_loop_(MessageLoop::TYPE_UI), |
37 ui_thread_(BrowserThread::UI, &message_loop_), | 36 ui_thread_(BrowserThread::UI, &message_loop_), |
38 state_("", "", "", "", "", false), | 37 state_("", "", "", "", "", false), |
39 resolver_(new MockAuthAttemptStateResolver) { | 38 resolver_(new MockAuthAttemptStateResolver) { |
40 } | 39 } |
41 | 40 |
42 virtual ~OnlineAttemptTest() {} | 41 virtual ~OnlineAttemptTest() {} |
43 | 42 |
44 virtual void SetUp() { | 43 virtual void SetUp() { |
45 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi(); | |
46 | |
47 MockLibraryLoader* loader = new MockLibraryLoader(); | |
48 ON_CALL(*loader, Load(_)) | |
49 .WillByDefault(Return(true)); | |
50 EXPECT_CALL(*loader, Load(_)) | |
51 .Times(AnyNumber()); | |
52 | |
53 // Passes ownership of |loader| to CrosLibrary. | |
54 test_api->SetLibraryLoader(loader, true); | |
55 | |
56 attempt_.reset(new OnlineAttempt(false, &state_, resolver_.get())); | 44 attempt_.reset(new OnlineAttempt(false, &state_, resolver_.get())); |
57 } | 45 } |
58 | 46 |
59 virtual void TearDown() { | 47 virtual void TearDown() { |
60 // Prevent bogus gMock leak check from firing. | |
61 chromeos::CrosLibrary::TestApi* test_api = | |
62 chromeos::CrosLibrary::Get()->GetTestApi(); | |
63 test_api->SetLibraryLoader(NULL, false); | |
64 } | 48 } |
65 | 49 |
66 void RunFailureTest(const GoogleServiceAuthError& error) { | 50 void RunFailureTest(const GoogleServiceAuthError& error) { |
67 EXPECT_CALL(*(resolver_.get()), Resolve()) | 51 EXPECT_CALL(*(resolver_.get()), Resolve()) |
68 .Times(1) | 52 .Times(1) |
69 .RetiresOnSaturation(); | 53 .RetiresOnSaturation(); |
70 | 54 |
71 BrowserThread::PostTask( | 55 BrowserThread::PostTask( |
72 BrowserThread::UI, FROM_HERE, | 56 BrowserThread::UI, FROM_HERE, |
73 base::Bind(&OnlineAttempt::OnClientLoginFailure, | 57 base::Bind(&OnlineAttempt::OnClientLoginFailure, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 attempt_->weak_factory_.GetWeakPtr(), | 248 attempt_->weak_factory_.GetWeakPtr(), |
265 error)); | 249 error)); |
266 | 250 |
267 // Force UI thread to finish tasks so I can verify |state_|. | 251 // Force UI thread to finish tasks so I can verify |state_|. |
268 message_loop_.RunAllPending(); | 252 message_loop_.RunAllPending(); |
269 EXPECT_TRUE(GoogleServiceAuthError::None() == | 253 EXPECT_TRUE(GoogleServiceAuthError::None() == |
270 state_.online_outcome().error()); | 254 state_.online_outcome().error()); |
271 } | 255 } |
272 | 256 |
273 } // namespace chromeos | 257 } // namespace chromeos |
OLD | NEW |