Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4356)

Unified Diff: chrome/browser/signin/google_auto_login_helper_unittest.cc

Issue 63253003: Fix issues with token refresh in AccountReconcilor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added missing files Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/signin/google_auto_login_helper_unittest.cc
diff --git a/chrome/browser/signin/google_auto_login_helper_unittest.cc b/chrome/browser/signin/google_auto_login_helper_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..afc4f1d6a374ff3bec2c6e80775df091ff387db6
--- /dev/null
+++ b/chrome/browser/signin/google_auto_login_helper_unittest.cc
@@ -0,0 +1,85 @@
+// Copyright 2013 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 <algorithm>
+#include <string>
+#include <vector>
+
+#include "base/message_loop/message_loop.h"
+#include "chrome/browser/signin/google_auto_login_helper.h"
+#include "chrome/test/base/testing_profile.h"
+#include "google_apis/gaia/gaia_auth_fetcher.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class MockUbertokenFetcher : public UbertokenFetcher {
+ public:
+ MockUbertokenFetcher(Profile* profile, UbertokenConsumer* consumer) :
+ UbertokenFetcher(profile, consumer), account_id("") {}
+
+ void completePendingRequest() {
+ OnUberAuthTokenSuccess("mock token: " + account_id);
+ }
+
+ virtual void StartFetchingToken(const std::string& id) {
+ account_id = id;
+ }
+
+ std::string account_id;
+};
+
+class InstrumentedGoogleAutoLoginHelper : public GoogleAutoLoginHelper {
+ public:
+ std::vector<MockUbertokenFetcher*> mock_uber_fetchers_;
+
+ InstrumentedGoogleAutoLoginHelper() :
+ GoogleAutoLoginHelper(0) {
+ }
+
+ virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE {
+ OnMergeSessionSuccess(token);
+ }
+
+ virtual UbertokenFetcher* CreateNewUbertokenFetcher() {
Roger Tawa OOO till Jul 10th 2013/11/27 18:45:43 missing OVERRIDE?
acleung1 2013/11/28 00:52:44 Done.
+ MockUbertokenFetcher* m = new MockUbertokenFetcher(
+ new TestingProfile(), this);
+ mock_uber_fetchers_.push_back(m);
+ return m;
+ }
+
+ void completePendingFetchers() {
+ for (std::vector<MockUbertokenFetcher*>::iterator i =
+ mock_uber_fetchers_.begin();
+ i != mock_uber_fetchers_.end(); ++i) {
+ (*i)->completePendingRequest();
+ }
+ }
+ MOCK_METHOD1(OnMergeSessionSuccess, void(const std::string& uber_token));
+};
+
+class GoogleAutoLoginHelperTest : public testing::Test {
+ // Used to delete GoogleAutoLoginHelper
+ base::MessageLoop message_loop_;
+};
+
+} // namespace
+
+TEST_F(GoogleAutoLoginHelperTest, AllRequestsInOneGo) {
+ InstrumentedGoogleAutoLoginHelper* helper =
+ new InstrumentedGoogleAutoLoginHelper();
+ EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc1@gmail.com"));
+ EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc2@gmail.com"));
+ EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc3@gmail.com"));
+ EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc4@gmail.com"));
+ EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc5@gmail.com"));
+ helper->LogIn("acc1@gmail.com");
+ helper->LogIn("acc2@gmail.com");
+ helper->LogIn("acc3@gmail.com");
+ helper->LogIn("acc4@gmail.com");
+ helper->LogIn("acc5@gmail.com");
+ helper->completePendingFetchers();
+}
+

Powered by Google App Engine
This is Rietveld 408576698