| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "chrome/browser/chrome_thread.h" | 15 #include "chrome/browser/chrome_thread.h" |
| 16 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" | 16 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" |
| 17 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | 17 #include "chrome/browser/chromeos/cros/mock_library_loader.h" |
| 18 #include "chrome/browser/chromeos/login/client_login_response_handler.h" | 18 #include "chrome/browser/chromeos/login/client_login_response_handler.h" |
| 19 #include "chrome/browser/chromeos/login/google_authenticator.h" | 19 #include "chrome/browser/chromeos/login/google_authenticator.h" |
| 20 #include "chrome/browser/chromeos/login/issue_response_handler.h" | 20 #include "chrome/browser/chromeos/login/issue_response_handler.h" |
| 21 #include "chrome/browser/chromeos/login/mock_auth_response_handler.h" | 21 #include "chrome/browser/chromeos/login/mock_auth_response_handler.h" |
| 22 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/net/gaia/gaia_authenticator2_unittest.h" | 24 #include "chrome/common/net/gaia/gaia_authenticator2_unittest.h" |
| 24 #include "chrome/common/net/url_fetcher.h" | 25 #include "chrome/common/net/url_fetcher.h" |
| 25 #include "chrome/test/testing_profile.h" | 26 #include "chrome/test/testing_profile.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 #include "net/base/net_errors.h" | 28 #include "net/base/net_errors.h" |
| 28 #include "net/url_request/url_request_status.h" | 29 #include "net/url_request/url_request_status.h" |
| 29 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 31 | 32 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 44 MockConsumer() {} | 45 MockConsumer() {} |
| 45 ~MockConsumer() {} | 46 ~MockConsumer() {} |
| 46 MOCK_METHOD1(OnLoginFailure, void(const LoginFailure& error)); | 47 MOCK_METHOD1(OnLoginFailure, void(const LoginFailure& error)); |
| 47 MOCK_METHOD2(OnLoginSuccess, void(const std::string& username, | 48 MOCK_METHOD2(OnLoginSuccess, void(const std::string& username, |
| 48 const GaiaAuthConsumer::ClientLoginResult& result)); | 49 const GaiaAuthConsumer::ClientLoginResult& result)); |
| 49 MOCK_METHOD0(OnOffTheRecordLoginSuccess, void(void)); | 50 MOCK_METHOD0(OnOffTheRecordLoginSuccess, void(void)); |
| 50 MOCK_METHOD1(OnPasswordChangeDetected, | 51 MOCK_METHOD1(OnPasswordChangeDetected, |
| 51 void(const GaiaAuthConsumer::ClientLoginResult& result)); | 52 void(const GaiaAuthConsumer::ClientLoginResult& result)); |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 // Simulates a URL fetch by posting a delayed task. This fetch expects to be | |
| 55 // canceled, and fails the test if it is not | |
| 56 class ExpectCanceledFetcher : public URLFetcher { | |
| 57 public: | |
| 58 ExpectCanceledFetcher(bool success, | |
| 59 const GURL& url, | |
| 60 const std::string& results, | |
| 61 URLFetcher::RequestType request_type, | |
| 62 URLFetcher::Delegate* d) | |
| 63 : URLFetcher(url, request_type, d) { | |
| 64 } | |
| 65 | |
| 66 virtual ~ExpectCanceledFetcher() { | |
| 67 task_->Cancel(); | |
| 68 } | |
| 69 | |
| 70 static void CompleteFetch() { | |
| 71 ADD_FAILURE() << "Fetch completed in ExpectCanceledFetcher!"; | |
| 72 MessageLoop::current()->Quit(); // Allow exiting even if we mess up. | |
| 73 } | |
| 74 | |
| 75 void Start() { | |
| 76 LOG(INFO) << "Delaying fetch completion in mock"; | |
| 77 task_ = NewRunnableFunction(&ExpectCanceledFetcher::CompleteFetch); | |
| 78 ChromeThread::PostDelayedTask(ChromeThread::UI, | |
| 79 FROM_HERE, | |
| 80 task_, | |
| 81 100); | |
| 82 } | |
| 83 | |
| 84 private: | |
| 85 CancelableTask* task_; | |
| 86 | |
| 87 DISALLOW_COPY_AND_ASSIGN(ExpectCanceledFetcher); | |
| 88 }; | |
| 89 | |
| 90 class GoogleAuthenticatorTest : public ::testing::Test { | 55 class GoogleAuthenticatorTest : public ::testing::Test { |
| 91 public: | 56 public: |
| 92 GoogleAuthenticatorTest() | 57 GoogleAuthenticatorTest() |
| 93 : username_("me@nowhere.org"), | 58 : username_("me@nowhere.org"), |
| 94 bytes_as_ascii_("ffff") { | 59 bytes_as_ascii_("ffff") { |
| 95 memset(fake_hash_, 0, sizeof(fake_hash_)); | 60 memset(fake_hash_, 0, sizeof(fake_hash_)); |
| 96 fake_hash_[0] = 10; | 61 fake_hash_[0] = 10; |
| 97 fake_hash_[1] = 1; | 62 fake_hash_[1] = 1; |
| 98 fake_hash_[7] = 10 << 4; | 63 fake_hash_[7] = 10 << 4; |
| 99 hash_ascii_.assign("0a010000000000a0"); | 64 hash_ascii_.assign("0a010000000000a0"); |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 // Post a task to cancel the login attempt. | 740 // Post a task to cancel the login attempt. |
| 776 CancelLogin(auth.get()); | 741 CancelLogin(auth.get()); |
| 777 | 742 |
| 778 URLFetcher::set_factory(NULL); | 743 URLFetcher::set_factory(NULL); |
| 779 | 744 |
| 780 // Run the UI thread until we exit it gracefully. | 745 // Run the UI thread until we exit it gracefully. |
| 781 message_loop.Run(); | 746 message_loop.Run(); |
| 782 } | 747 } |
| 783 | 748 |
| 784 } // namespace chromeos | 749 } // namespace chromeos |
| OLD | NEW |