| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" | 5 #import "ios/chrome/browser/signin/chrome_identity_service_observer_bridge.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/mac/scoped_nsobject.h" | |
| 10 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" | 9 #import "ios/public/provider/chrome/browser/signin/chrome_identity.h" |
| 11 #include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" | 10 #include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" |
| 12 #include "testing/gtest_mac.h" | 11 #include "testing/gtest_mac.h" |
| 13 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 14 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
| 15 @interface TestChromeIdentityServiceObserver | 18 @interface TestChromeIdentityServiceObserver |
| 16 : NSObject<ChromeIdentityServiceObserver> | 19 : NSObject<ChromeIdentityServiceObserver> |
| 17 @property(nonatomic) BOOL onIdentityListChangedCalled; | 20 @property(nonatomic) BOOL onIdentityListChangedCalled; |
| 18 @property(nonatomic) BOOL onAccessTokenRefreshFailedCalled; | 21 @property(nonatomic) BOOL onAccessTokenRefreshFailedCalled; |
| 19 @property(nonatomic) BOOL onProfileUpdateCalled; | 22 @property(nonatomic) BOOL onProfileUpdateCalled; |
| 20 @property(nonatomic) BOOL onChromeIdentityServiceWillBeDestroyedCalled; | 23 @property(nonatomic) BOOL onChromeIdentityServiceWillBeDestroyedCalled; |
| 21 @property(nonatomic, assign) ChromeIdentity* identity; | 24 @property(nonatomic, weak) ChromeIdentity* identity; |
| 22 @property(nonatomic, readonly) NSDictionary* userInfo; | 25 @property(weak, nonatomic, readonly) NSDictionary* userInfo; |
| 23 @property(nonatomic, readonly) | 26 @property(nonatomic, readonly) |
| 24 ios::ChromeIdentityService::Observer* observerBridge; | 27 ios::ChromeIdentityService::Observer* observerBridge; |
| 25 @end | 28 @end |
| 26 | 29 |
| 27 @implementation TestChromeIdentityServiceObserver { | 30 @implementation TestChromeIdentityServiceObserver { |
| 28 std::unique_ptr<ios::ChromeIdentityService::Observer> observer_bridge_; | 31 std::unique_ptr<ios::ChromeIdentityService::Observer> observer_bridge_; |
| 29 } | 32 } |
| 30 | 33 |
| 31 @synthesize onIdentityListChangedCalled = _onIdentityListChangedCalled; | 34 @synthesize onIdentityListChangedCalled = _onIdentityListChangedCalled; |
| 32 @synthesize onAccessTokenRefreshFailedCalled = | 35 @synthesize onAccessTokenRefreshFailedCalled = |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 84 |
| 82 ios::ChromeIdentityService::Observer* GetObserverBridge() { | 85 ios::ChromeIdentityService::Observer* GetObserverBridge() { |
| 83 return [test_observer_ observerBridge]; | 86 return [test_observer_ observerBridge]; |
| 84 } | 87 } |
| 85 | 88 |
| 86 TestChromeIdentityServiceObserver* GetTestObserver() { | 89 TestChromeIdentityServiceObserver* GetTestObserver() { |
| 87 return test_observer_; | 90 return test_observer_; |
| 88 } | 91 } |
| 89 | 92 |
| 90 private: | 93 private: |
| 91 base::scoped_nsobject<TestChromeIdentityServiceObserver> test_observer_; | 94 TestChromeIdentityServiceObserver* test_observer_; |
| 92 }; | 95 }; |
| 93 | 96 |
| 94 // Tests that |onIdentityListChanged| is forwarded. | 97 // Tests that |onIdentityListChanged| is forwarded. |
| 95 TEST_F(ChromeIdentityServiceObserverBridgeTest, onIdentityListChanged) { | 98 TEST_F(ChromeIdentityServiceObserverBridgeTest, onIdentityListChanged) { |
| 96 ASSERT_FALSE(GetTestObserver().onIdentityListChangedCalled); | 99 ASSERT_FALSE(GetTestObserver().onIdentityListChangedCalled); |
| 97 GetObserverBridge()->OnIdentityListChanged(); | 100 GetObserverBridge()->OnIdentityListChanged(); |
| 98 EXPECT_TRUE(GetTestObserver().onIdentityListChangedCalled); | 101 EXPECT_TRUE(GetTestObserver().onIdentityListChangedCalled); |
| 99 EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); | 102 EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); |
| 100 EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); | 103 EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); |
| 101 EXPECT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); | 104 EXPECT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); |
| 102 } | 105 } |
| 103 | 106 |
| 104 // Tests that |onAccessTokenRefreshFailed| is forwarded. | 107 // Tests that |onAccessTokenRefreshFailed| is forwarded. |
| 105 TEST_F(ChromeIdentityServiceObserverBridgeTest, onAccessTokenRefreshFailed) { | 108 TEST_F(ChromeIdentityServiceObserverBridgeTest, onAccessTokenRefreshFailed) { |
| 106 base::scoped_nsobject<ChromeIdentity> identity([[ChromeIdentity alloc] init]); | 109 ChromeIdentity* identity = [[ChromeIdentity alloc] init]; |
| 107 NSDictionary* userInfo = [NSDictionary dictionary]; | 110 NSDictionary* userInfo = [NSDictionary dictionary]; |
| 108 ASSERT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); | 111 ASSERT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); |
| 109 GetObserverBridge()->OnAccessTokenRefreshFailed(identity, userInfo); | 112 GetObserverBridge()->OnAccessTokenRefreshFailed(identity, userInfo); |
| 110 EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); | 113 EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); |
| 111 EXPECT_TRUE(GetTestObserver().onAccessTokenRefreshFailedCalled); | 114 EXPECT_TRUE(GetTestObserver().onAccessTokenRefreshFailedCalled); |
| 112 EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); | 115 EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); |
| 113 EXPECT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); | 116 EXPECT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); |
| 114 EXPECT_EQ(identity, GetTestObserver().identity); | 117 EXPECT_EQ(identity, GetTestObserver().identity); |
| 115 EXPECT_NSEQ(userInfo, GetTestObserver().userInfo); | 118 EXPECT_NSEQ(userInfo, GetTestObserver().userInfo); |
| 116 } | 119 } |
| 117 | 120 |
| 118 // Tests that |onProfileUpdate| is forwarded. | 121 // Tests that |onProfileUpdate| is forwarded. |
| 119 TEST_F(ChromeIdentityServiceObserverBridgeTest, onProfileUpdate) { | 122 TEST_F(ChromeIdentityServiceObserverBridgeTest, onProfileUpdate) { |
| 120 base::scoped_nsobject<ChromeIdentity> identity([[ChromeIdentity alloc] init]); | 123 ChromeIdentity* identity = [[ChromeIdentity alloc] init]; |
| 121 ASSERT_FALSE(GetTestObserver().onProfileUpdateCalled); | 124 ASSERT_FALSE(GetTestObserver().onProfileUpdateCalled); |
| 122 GetObserverBridge()->OnProfileUpdate(identity); | 125 GetObserverBridge()->OnProfileUpdate(identity); |
| 123 EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); | 126 EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); |
| 124 EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); | 127 EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); |
| 125 EXPECT_TRUE(GetTestObserver().onProfileUpdateCalled); | 128 EXPECT_TRUE(GetTestObserver().onProfileUpdateCalled); |
| 126 EXPECT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); | 129 EXPECT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); |
| 127 EXPECT_EQ(identity, GetTestObserver().identity); | 130 EXPECT_EQ(identity, GetTestObserver().identity); |
| 128 } | 131 } |
| 129 | 132 |
| 130 // Tests that |onChromeIdentityServiceWillBeDestroyed| is forwarded. | 133 // Tests that |onChromeIdentityServiceWillBeDestroyed| is forwarded. |
| 131 TEST_F(ChromeIdentityServiceObserverBridgeTest, | 134 TEST_F(ChromeIdentityServiceObserverBridgeTest, |
| 132 onChromeIdentityServiceWillBeDestroyed) { | 135 onChromeIdentityServiceWillBeDestroyed) { |
| 133 ASSERT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); | 136 ASSERT_FALSE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); |
| 134 GetObserverBridge()->OnChromeIdentityServiceWillBeDestroyed(); | 137 GetObserverBridge()->OnChromeIdentityServiceWillBeDestroyed(); |
| 135 EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); | 138 EXPECT_FALSE(GetTestObserver().onIdentityListChangedCalled); |
| 136 EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); | 139 EXPECT_FALSE(GetTestObserver().onAccessTokenRefreshFailedCalled); |
| 137 EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); | 140 EXPECT_FALSE(GetTestObserver().onProfileUpdateCalled); |
| 138 EXPECT_TRUE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); | 141 EXPECT_TRUE(GetTestObserver().onChromeIdentityServiceWillBeDestroyedCalled); |
| 139 } | 142 } |
| OLD | NEW |