Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <algorithm> | |
| 6 #include <string> | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "chrome/browser/signin/google_auto_login_helper.h" | |
| 11 #include "chrome/test/base/testing_profile.h" | |
| 12 #include "google_apis/gaia/gaia_auth_fetcher.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 class MockUbertokenFetcher : public UbertokenFetcher { | |
| 19 public: | |
| 20 MockUbertokenFetcher(Profile* profile, UbertokenConsumer* consumer) : | |
| 21 UbertokenFetcher(profile, consumer), account_id("") {} | |
| 22 | |
| 23 void completePendingRequest() { | |
| 24 OnUberAuthTokenSuccess("mock token: " + account_id); | |
| 25 } | |
| 26 | |
| 27 virtual void StartFetchingToken(const std::string& id) { | |
| 28 account_id = id; | |
| 29 } | |
| 30 | |
| 31 std::string account_id; | |
| 32 }; | |
| 33 | |
| 34 class InstrumentedGoogleAutoLoginHelper : public GoogleAutoLoginHelper { | |
| 35 public: | |
| 36 std::vector<MockUbertokenFetcher*> mock_uber_fetchers_; | |
| 37 | |
| 38 InstrumentedGoogleAutoLoginHelper() : | |
| 39 GoogleAutoLoginHelper(0) { | |
| 40 } | |
| 41 | |
| 42 virtual void OnUbertokenSuccess(const std::string& token) OVERRIDE { | |
| 43 OnMergeSessionSuccess(token); | |
| 44 } | |
| 45 | |
| 46 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.
| |
| 47 MockUbertokenFetcher* m = new MockUbertokenFetcher( | |
| 48 new TestingProfile(), this); | |
| 49 mock_uber_fetchers_.push_back(m); | |
| 50 return m; | |
| 51 } | |
| 52 | |
| 53 void completePendingFetchers() { | |
| 54 for (std::vector<MockUbertokenFetcher*>::iterator i = | |
| 55 mock_uber_fetchers_.begin(); | |
| 56 i != mock_uber_fetchers_.end(); ++i) { | |
| 57 (*i)->completePendingRequest(); | |
| 58 } | |
| 59 } | |
| 60 MOCK_METHOD1(OnMergeSessionSuccess, void(const std::string& uber_token)); | |
| 61 }; | |
| 62 | |
| 63 class GoogleAutoLoginHelperTest : public testing::Test { | |
| 64 // Used to delete GoogleAutoLoginHelper | |
| 65 base::MessageLoop message_loop_; | |
| 66 }; | |
| 67 | |
| 68 } // namespace | |
| 69 | |
| 70 TEST_F(GoogleAutoLoginHelperTest, AllRequestsInOneGo) { | |
| 71 InstrumentedGoogleAutoLoginHelper* helper = | |
| 72 new InstrumentedGoogleAutoLoginHelper(); | |
| 73 EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc1@gmail.com")); | |
| 74 EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc2@gmail.com")); | |
| 75 EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc3@gmail.com")); | |
| 76 EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc4@gmail.com")); | |
| 77 EXPECT_CALL(*helper, OnMergeSessionSuccess("mock token: acc5@gmail.com")); | |
| 78 helper->LogIn("acc1@gmail.com"); | |
| 79 helper->LogIn("acc2@gmail.com"); | |
| 80 helper->LogIn("acc3@gmail.com"); | |
| 81 helper->LogIn("acc4@gmail.com"); | |
| 82 helper->LogIn("acc5@gmail.com"); | |
| 83 helper->completePendingFetchers(); | |
| 84 } | |
| 85 | |
| OLD | NEW |