summaryrefslogtreecommitdiffstats
path: root/google_apis/gaia/ubertoken_fetcher_unittest.cc
diff options
context:
space:
mode:
authorblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-16 22:52:57 +0000
committerblundell@chromium.org <blundell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-16 22:52:57 +0000
commitdf6a024c8ef52bd882e2ef046d8b55fe9a4b2167 (patch)
tree618684a2cbfc4392fae0d2a15352180e356884a4 /google_apis/gaia/ubertoken_fetcher_unittest.cc
parent50136d7e76e9ab72c056f93c95a974352b993330 (diff)
downloadchromium_src-df6a024c8ef52bd882e2ef046d8b55fe9a4b2167.zip
chromium_src-df6a024c8ef52bd882e2ef046d8b55fe9a4b2167.tar.gz
chromium_src-df6a024c8ef52bd882e2ef046d8b55fe9a4b2167.tar.bz2
Move UbertokenFetcher from //chrome to //google_apis.
This CL eliminates //chrome- and //content-level dependencies from UbertokenFetcher and moves it to //google_apis/gaia. Notable changes: - Change UbertokenFetcher to take in the OAuth2TokenService and URLRequestContextGetter to use rather than the Profile. - Add a FakeOAuth2TokenService to enable moving the UbertokenFetcher unittest away from using FakeProfileOAuth2TokenService. BUG=330292 TBR=thakis Review URL: https://codereview.chromium.org/136723009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245359 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis/gaia/ubertoken_fetcher_unittest.cc')
-rw-r--r--google_apis/gaia/ubertoken_fetcher_unittest.cc112
1 files changed, 112 insertions, 0 deletions
diff --git a/google_apis/gaia/ubertoken_fetcher_unittest.cc b/google_apis/gaia/ubertoken_fetcher_unittest.cc
new file mode 100644
index 0000000..d2aefde
--- /dev/null
+++ b/google_apis/gaia/ubertoken_fetcher_unittest.cc
@@ -0,0 +1,112 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "google_apis/gaia/ubertoken_fetcher.h"
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop/message_loop.h"
+#include "google_apis/gaia/fake_oauth2_token_service.h"
+#include "google_apis/gaia/gaia_constants.h"
+#include "net/url_request/test_url_fetcher_factory.h"
+#include "net/url_request/url_request_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kTestAccountId[] = "test@gmail.com";
+
+class MockUbertokenConsumer : public UbertokenConsumer {
+ public:
+ MockUbertokenConsumer()
+ : nb_correct_token_(0),
+ last_error_(GoogleServiceAuthError::AuthErrorNone()),
+ nb_error_(0) {
+ }
+ virtual ~MockUbertokenConsumer() {}
+
+ virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE {
+ last_token_ = token;
+ ++ nb_correct_token_;
+ }
+
+ virtual void OnUbertokenFailure(const GoogleServiceAuthError& error)
+ OVERRIDE {
+ last_error_ = error;
+ ++nb_error_;
+ }
+
+ std::string last_token_;
+ int nb_correct_token_;
+ GoogleServiceAuthError last_error_;
+ int nb_error_;
+};
+
+} // namespace
+
+class UbertokenFetcherTest : public testing::Test {
+ public:
+ virtual void SetUp() OVERRIDE {
+ OAuth2TokenService* token_service = new FakeOAuth2TokenService();
+ request_context_getter_ = new net::TestURLRequestContextGetter(
+ base::MessageLoopProxy::current());
+ fetcher_.reset(new UbertokenFetcher(token_service,
+ &consumer_,
+ request_context_getter_.get()));
+ }
+
+ virtual void TearDown() OVERRIDE {
+ fetcher_.reset();
+ }
+
+ protected:
+ base::MessageLoop message_loop_;
+ net::TestURLFetcherFactory factory_;
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
+ MockUbertokenConsumer consumer_;
+ scoped_ptr<UbertokenFetcher> fetcher_;
+};
+
+TEST_F(UbertokenFetcherTest, Basic) {
+}
+
+TEST_F(UbertokenFetcherTest, Success) {
+ fetcher_->StartFetchingToken(kTestAccountId);
+ fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
+ fetcher_->OnUberAuthTokenSuccess("uberToken");
+
+ EXPECT_EQ(0, consumer_.nb_error_);
+ EXPECT_EQ(1, consumer_.nb_correct_token_);
+ EXPECT_EQ("uberToken", consumer_.last_token_);
+}
+
+TEST_F(UbertokenFetcherTest, NoRefreshToken) {
+ fetcher_->StartFetchingToken(kTestAccountId);
+ GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
+ fetcher_->OnGetTokenFailure(NULL, error);
+
+ EXPECT_EQ(1, consumer_.nb_error_);
+ EXPECT_EQ(0, consumer_.nb_correct_token_);
+}
+
+TEST_F(UbertokenFetcherTest, FailureToGetAccessToken) {
+ fetcher_->StartFetchingToken(kTestAccountId);
+ GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
+ fetcher_->OnGetTokenFailure(NULL, error);
+
+ EXPECT_EQ(1, consumer_.nb_error_);
+ EXPECT_EQ(0, consumer_.nb_correct_token_);
+ EXPECT_EQ("", consumer_.last_token_);
+}
+
+TEST_F(UbertokenFetcherTest, FailureToGetUberToken) {
+ fetcher_->StartFetchingToken(kTestAccountId);
+ GoogleServiceAuthError error(GoogleServiceAuthError::USER_NOT_SIGNED_UP);
+ fetcher_->OnGetTokenSuccess(NULL, "accessToken", base::Time());
+ fetcher_->OnUberAuthTokenFailure(error);
+
+ EXPECT_EQ(1, consumer_.nb_error_);
+ EXPECT_EQ(0, consumer_.nb_correct_token_);
+ EXPECT_EQ("", consumer_.last_token_);
+}