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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_LOGIN_STATUS_CONSUMER_H_ 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_LOGIN_STATUS_CONSUMER_H_ 7 #pragma once 8 9 #include "chrome/browser/chromeos/login/login_status_consumer.h" 10 #include "chrome/common/net/gaia/gaia_auth_consumer.h" 11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace chromeos { 15 16 class MockConsumer : public LoginStatusConsumer { 17 public: MockConsumer()18 MockConsumer() {} ~MockConsumer()19 ~MockConsumer() {} 20 MOCK_METHOD1(OnLoginFailure, void(const LoginFailure& error)); 21 MOCK_METHOD4(OnLoginSuccess, void( 22 const std::string& username, 23 const std::string& password, 24 const GaiaAuthConsumer::ClientLoginResult& result, 25 bool pending_requests)); 26 MOCK_METHOD0(OnOffTheRecordLoginSuccess, void(void)); 27 MOCK_METHOD1(OnPasswordChangeDetected, 28 void(const GaiaAuthConsumer::ClientLoginResult& result)); 29 30 // The following functions can be used in gmock Invoke() clauses. 31 32 // Compatible with LoginStatusConsumer::OnOffTheRecordLoginSuccess() OnGuestSuccessQuit()33 static void OnGuestSuccessQuit() { 34 MessageLoop::current()->Quit(); 35 } 36 OnGuestSuccessQuitAndFail()37 static void OnGuestSuccessQuitAndFail() { 38 ADD_FAILURE() << "Guest Login should have failed!"; 39 MessageLoop::current()->Quit(); 40 } 41 42 // Compatible with LoginStatusConsumer::OnLoginSuccess() OnSuccessQuit(const std::string & username,const std::string & password,const GaiaAuthConsumer::ClientLoginResult & credentials,bool pending_requests)43 static void OnSuccessQuit( 44 const std::string& username, 45 const std::string& password, 46 const GaiaAuthConsumer::ClientLoginResult& credentials, 47 bool pending_requests) { 48 MessageLoop::current()->Quit(); 49 } 50 OnSuccessQuitAndFail(const std::string & username,const std::string & password,const GaiaAuthConsumer::ClientLoginResult & credentials,bool pending_requests)51 static void OnSuccessQuitAndFail( 52 const std::string& username, 53 const std::string& password, 54 const GaiaAuthConsumer::ClientLoginResult& credentials, 55 bool pending_requests) { 56 ADD_FAILURE() << "Login should NOT have succeeded!"; 57 MessageLoop::current()->Quit(); 58 } 59 60 // Compatible with LoginStatusConsumer::OnLoginFailure() OnFailQuit(const LoginFailure & error)61 static void OnFailQuit(const LoginFailure& error) { 62 MessageLoop::current()->Quit(); 63 } 64 OnFailQuitAndFail(const LoginFailure & error)65 static void OnFailQuitAndFail(const LoginFailure& error) { 66 ADD_FAILURE() << "Login should not have failed!"; 67 MessageLoop::current()->Quit(); 68 } 69 70 // Compatible with LoginStatusConsumer::OnPasswordChangeDetected() OnMigrateQuit(const GaiaAuthConsumer::ClientLoginResult & credentials)71 static void OnMigrateQuit( 72 const GaiaAuthConsumer::ClientLoginResult& credentials) { 73 MessageLoop::current()->Quit(); 74 } 75 OnMigrateQuitAndFail(const GaiaAuthConsumer::ClientLoginResult & credentials)76 static void OnMigrateQuitAndFail( 77 const GaiaAuthConsumer::ClientLoginResult& credentials) { 78 ADD_FAILURE() << "Should not have detected a PW change!"; 79 MessageLoop::current()->Quit(); 80 } 81 }; 82 83 } // namespace chromeos 84 85 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_LOGIN_STATUS_CONSUMER_H_ 86