OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 14 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
15 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 15 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "components/arc/arc_bridge_service.h" | 19 #include "components/arc/arc_bridge_service.h" |
20 #include "components/arc/auth/arc_auth_fetcher.h" | |
21 #include "components/arc/test/fake_arc_bridge_service.h" | 20 #include "components/arc/test/fake_arc_bridge_service.h" |
22 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
23 #include "components/syncable_prefs/testing_pref_service_syncable.h" | 22 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/test/test_browser_thread_bundle.h" | 24 #include "content/public/test/test_browser_thread_bundle.h" |
26 #include "google_apis/gaia/gaia_constants.h" | 25 #include "google_apis/gaia/gaia_constants.h" |
27 #include "google_apis/gaia/gaia_urls.h" | 26 #include "google_apis/gaia/gaia_urls.h" |
28 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
29 #include "net/url_request/test_url_fetcher_factory.h" | |
30 #include "net/url_request/url_fetcher.h" | |
31 #include "sync/api/fake_sync_change_processor.h" | 28 #include "sync/api/fake_sync_change_processor.h" |
32 #include "sync/api/sync_error_factory_mock.h" | 29 #include "sync/api/sync_error_factory_mock.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
34 | 31 |
35 namespace arc { | 32 namespace arc { |
36 | 33 |
37 namespace { | 34 namespace { |
38 | 35 |
39 const int kThreadOptions = content::TestBrowserThreadBundle::IO_MAINLOOP; | 36 const int kThreadOptions = content::TestBrowserThreadBundle::IO_MAINLOOP; |
40 const char kTestAuthCode[] = "4/Qa3CPIhh-WcMfWSf9HZaYcGUhEeax-F9sQK9CNRhZWs"; | 37 const char kTestAuthCode[] = "4/Qa3CPIhh-WcMfWSf9HZaYcGUhEeax-F9sQK9CNRhZWs"; |
41 | 38 |
42 } // namespace | 39 } // namespace |
43 | 40 |
44 class ArcAuthServiceTest : public testing::Test { | 41 class ArcAuthServiceTest : public testing::Test { |
45 public: | 42 public: |
46 ArcAuthServiceTest() | 43 ArcAuthServiceTest() |
47 : thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)), | 44 : thread_bundle_(new content::TestBrowserThreadBundle(kThreadOptions)) {} |
48 url_fetcher_factory_( | |
49 nullptr, | |
50 base::Bind(&ArcAuthServiceTest::FakeURLFetcherCreator, | |
51 base::Unretained(this))) {} | |
52 ~ArcAuthServiceTest() override = default; | 45 ~ArcAuthServiceTest() override = default; |
53 | 46 |
54 void SetUp() override { | 47 void SetUp() override { |
55 ArcAuthService::DisableUIForTesting(); | 48 ArcAuthService::DisableUIForTesting(); |
56 | 49 |
57 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 50 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
58 TestingProfile::Builder profile_builder; | 51 TestingProfile::Builder profile_builder; |
59 profile_builder.SetPath(temp_dir_.path().AppendASCII("TestArcProfile")); | 52 profile_builder.SetPath(temp_dir_.path().AppendASCII("TestArcProfile")); |
60 | 53 |
61 profile_ = profile_builder.Build(); | 54 profile_ = profile_builder.Build(); |
62 StartPreferenceSyncing(); | 55 StartPreferenceSyncing(); |
63 | 56 |
64 bridge_service_.reset(new FakeArcBridgeService()); | 57 bridge_service_.reset(new FakeArcBridgeService()); |
65 auth_service_.reset(new ArcAuthService(bridge_service_.get())); | 58 auth_service_.reset(new ArcAuthService(bridge_service_.get())); |
66 | 59 |
67 // Check initial conditions. | 60 // Check initial conditions. |
68 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); | 61 EXPECT_EQ(bridge_service_.get(), ArcBridgeService::Get()); |
69 EXPECT_EQ(true, !ArcBridgeService::Get()->available()); | 62 EXPECT_EQ(true, !ArcBridgeService::Get()->available()); |
70 EXPECT_EQ(ArcBridgeService::State::STOPPED, | 63 EXPECT_EQ(ArcBridgeService::State::STOPPED, |
71 ArcBridgeService::Get()->state()); | 64 ArcBridgeService::Get()->state()); |
72 } | 65 } |
73 | 66 |
74 void TearDown() override {} | 67 void TearDown() override {} |
75 | 68 |
76 protected: | 69 protected: |
77 Profile* profile() { return profile_.get(); } | 70 Profile* profile() { return profile_.get(); } |
78 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } | 71 FakeArcBridgeService* bridge_service() { return bridge_service_.get(); } |
79 ArcAuthService* auth_service() { return auth_service_.get(); } | 72 ArcAuthService* auth_service() { return auth_service_.get(); } |
80 | 73 |
81 void PrepareURLResponse(net::HttpStatusCode code, bool enable_auth_code) { | |
82 const GURL gaia_gurl = ArcAuthFetcher::CreateURL(); | |
83 url_fetcher_factory_.SetFakeResponse(gaia_gurl, std::string(), code, | |
84 net::URLRequestStatus::SUCCESS); | |
85 if (enable_auth_code) { | |
86 std::string cookie = "oauth_code="; | |
87 cookie += kTestAuthCode; | |
88 cookie += "; Path=/o/oauth2/programmatic_auth; Secure; HttpOnly"; | |
89 rt_cookie_ = cookie; | |
90 } | |
91 } | |
92 | |
93 private: | 74 private: |
94 scoped_ptr<net::FakeURLFetcher> FakeURLFetcherCreator( | |
95 const GURL& url, | |
96 net::URLFetcherDelegate* delegate, | |
97 const std::string& response_data, | |
98 net::HttpStatusCode response_code, | |
99 net::URLRequestStatus::Status status) { | |
100 scoped_ptr<net::FakeURLFetcher> fetcher(new net::FakeURLFetcher( | |
101 url, delegate, response_data, response_code, status)); | |
102 // Use cookie only once. | |
103 if (!rt_cookie_.empty()) { | |
104 net::ResponseCookies cookies; | |
105 cookies.push_back(rt_cookie_); | |
106 fetcher->set_cookies(cookies); | |
107 rt_cookie_.clear(); | |
108 } | |
109 return fetcher; | |
110 } | |
111 | |
112 void StartPreferenceSyncing() const { | 75 void StartPreferenceSyncing() const { |
113 PrefServiceSyncableFromProfile(profile_.get()) | 76 PrefServiceSyncableFromProfile(profile_.get()) |
114 ->GetSyncableService(syncer::PREFERENCES) | 77 ->GetSyncableService(syncer::PREFERENCES) |
115 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), | 78 ->MergeDataAndStartSyncing(syncer::PREFERENCES, syncer::SyncDataList(), |
116 scoped_ptr<syncer::SyncChangeProcessor>( | 79 scoped_ptr<syncer::SyncChangeProcessor>( |
117 new syncer::FakeSyncChangeProcessor), | 80 new syncer::FakeSyncChangeProcessor), |
118 scoped_ptr<syncer::SyncErrorFactory>( | 81 scoped_ptr<syncer::SyncErrorFactory>( |
119 new syncer::SyncErrorFactoryMock())); | 82 new syncer::SyncErrorFactoryMock())); |
120 } | 83 } |
121 | 84 |
122 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; | 85 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
123 net::FakeURLFetcherFactory url_fetcher_factory_; | |
124 scoped_ptr<arc::FakeArcBridgeService> bridge_service_; | 86 scoped_ptr<arc::FakeArcBridgeService> bridge_service_; |
125 scoped_ptr<arc::ArcAuthService> auth_service_; | 87 scoped_ptr<arc::ArcAuthService> auth_service_; |
126 scoped_ptr<TestingProfile> profile_; | 88 scoped_ptr<TestingProfile> profile_; |
127 base::ScopedTempDir temp_dir_; | 89 base::ScopedTempDir temp_dir_; |
128 std::string rt_cookie_; | |
129 | 90 |
130 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceTest); | 91 DISALLOW_COPY_AND_ASSIGN(ArcAuthServiceTest); |
131 }; | 92 }; |
132 | 93 |
133 TEST_F(ArcAuthServiceTest, PrefChangeTriggersService) { | 94 TEST_F(ArcAuthServiceTest, PrefChangeTriggersService) { |
134 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 95 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
135 | 96 |
136 PrefService* pref = profile()->GetPrefs(); | 97 PrefService* pref = profile()->GetPrefs(); |
137 DCHECK_EQ(false, pref->GetBoolean(prefs::kArcEnabled)); | 98 DCHECK_EQ(false, pref->GetBoolean(prefs::kArcEnabled)); |
138 | 99 |
139 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 100 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
140 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 101 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
141 | 102 |
142 PrepareURLResponse(net::HTTP_OK, false); | |
143 pref->SetBoolean(prefs::kArcEnabled, true); | 103 pref->SetBoolean(prefs::kArcEnabled, true); |
144 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 104 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
145 | 105 |
146 pref->SetBoolean(prefs::kArcEnabled, false); | 106 pref->SetBoolean(prefs::kArcEnabled, false); |
147 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 107 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
148 | 108 |
149 // Correctly stop service. | 109 // Correctly stop service. |
150 auth_service()->Shutdown(); | 110 auth_service()->Shutdown(); |
151 } | 111 } |
152 | 112 |
153 TEST_F(ArcAuthServiceTest, BaseWorkflow) { | 113 TEST_F(ArcAuthServiceTest, BaseWorkflow) { |
154 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); | 114 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); |
155 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 115 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
156 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 116 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
157 | 117 |
158 PrepareURLResponse(net::HTTP_OK, true); | |
159 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 118 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
160 | 119 |
161 // By default ARC is not enabled. | 120 // By default ARC is not enabled. |
162 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 121 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
163 | 122 |
164 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 123 profile()->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
165 | 124 |
166 // Setting profile and pref initiates a code fetching process. | 125 // Setting profile and pref initiates a code fetching process. |
167 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 126 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
168 | 127 |
169 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 128 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
170 base::RunLoop().RunUntilIdle(); | |
171 | 129 |
172 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 130 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
173 ASSERT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); | 131 ASSERT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); |
174 // Auth code valid only for one call. | 132 // Auth code valid only for one call. |
175 ASSERT_EQ(kTestAuthCode, auth_service()->GetAndResetAuthCode()); | 133 ASSERT_EQ(kTestAuthCode, auth_service()->GetAndResetAuthCode()); |
176 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 134 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
177 | 135 |
178 auth_service()->Shutdown(); | 136 auth_service()->Shutdown(); |
179 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 137 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
180 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); | 138 ASSERT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); |
181 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); | 139 ASSERT_EQ(std::string(), auth_service()->GetAndResetAuthCode()); |
182 | 140 |
183 // Send profile and don't provide a code. | 141 // Send profile and don't provide a code. |
184 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 142 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
185 | 143 |
186 // Setting profile initiates a code fetching process. | 144 // Setting profile initiates a code fetching process. |
187 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 145 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
188 | 146 |
189 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 147 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
190 base::RunLoop().RunUntilIdle(); | 148 base::RunLoop().RunUntilIdle(); |
191 | 149 |
192 // UI is disabled in unit tests and this code is unchanged. | 150 // UI is disabled in unit tests and this code is unchanged. |
193 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 151 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
194 | 152 |
195 // Send error response. | |
196 PrepareURLResponse(net::HTTP_BAD_REQUEST, false); | |
197 auth_service()->Shutdown(); | |
198 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | |
199 auth_service()->OnPrimaryUserProfilePrepared(profile()); | |
200 | |
201 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | |
202 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
203 base::RunLoop().RunUntilIdle(); | |
204 | |
205 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | |
206 | |
207 // Correctly stop service. | 153 // Correctly stop service. |
208 auth_service()->Shutdown(); | 154 auth_service()->Shutdown(); |
209 } | 155 } |
210 | 156 |
211 TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { | 157 TEST_F(ArcAuthServiceTest, CancelFetchingDisablesArc) { |
212 PrepareURLResponse(net::HTTP_OK, false); | |
213 PrefService* pref = profile()->GetPrefs(); | 158 PrefService* pref = profile()->GetPrefs(); |
214 | 159 |
215 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 160 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
216 pref->SetBoolean(prefs::kArcEnabled, true); | 161 pref->SetBoolean(prefs::kArcEnabled, true); |
217 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 162 ASSERT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
218 | 163 |
219 auth_service()->CancelAuthCode(); | 164 auth_service()->CancelAuthCode(); |
220 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 165 ASSERT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
221 ASSERT_EQ(false, pref->GetBoolean(prefs::kArcEnabled)); | 166 ASSERT_EQ(false, pref->GetBoolean(prefs::kArcEnabled)); |
222 | 167 |
223 // Correctly stop service. | 168 // Correctly stop service. |
224 auth_service()->Shutdown(); | 169 auth_service()->Shutdown(); |
225 } | 170 } |
226 | 171 |
227 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { | 172 TEST_F(ArcAuthServiceTest, CloseUIKeepsArcEnabled) { |
228 PrepareURLResponse(net::HTTP_OK, true); | |
229 PrefService* pref = profile()->GetPrefs(); | 173 PrefService* pref = profile()->GetPrefs(); |
230 | 174 |
231 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 175 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
232 pref->SetBoolean(prefs::kArcEnabled, true); | 176 pref->SetBoolean(prefs::kArcEnabled, true); |
233 | 177 |
234 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 178 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
235 base::RunLoop().RunUntilIdle(); | |
236 | 179 |
237 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 180 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
238 | 181 |
239 auth_service()->CancelAuthCode(); | 182 auth_service()->CancelAuthCode(); |
240 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 183 ASSERT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
241 ASSERT_EQ(true, pref->GetBoolean(prefs::kArcEnabled)); | 184 ASSERT_EQ(true, pref->GetBoolean(prefs::kArcEnabled)); |
242 | 185 |
243 // Correctly stop service. | 186 // Correctly stop service. |
244 auth_service()->Shutdown(); | 187 auth_service()->Shutdown(); |
245 } | 188 } |
246 | 189 |
247 TEST_F(ArcAuthServiceTest, EnableDisablesArc) { | 190 TEST_F(ArcAuthServiceTest, EnableDisablesArc) { |
248 PrepareURLResponse(net::HTTP_OK, false); | |
249 PrefService* pref = profile()->GetPrefs(); | 191 PrefService* pref = profile()->GetPrefs(); |
250 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 192 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
251 | 193 |
252 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 194 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
253 auth_service()->EnableArc(); | 195 auth_service()->EnableArc(); |
254 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); | 196 EXPECT_TRUE(pref->GetBoolean(prefs::kArcEnabled)); |
255 auth_service()->DisableArc(); | 197 auth_service()->DisableArc(); |
256 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 198 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
257 | 199 |
258 // Correctly stop service. | 200 // Correctly stop service. |
259 auth_service()->Shutdown(); | 201 auth_service()->Shutdown(); |
260 } | 202 } |
261 | 203 |
262 TEST_F(ArcAuthServiceTest, SignInStatus) { | 204 TEST_F(ArcAuthServiceTest, SignInStatus) { |
263 PrefService* prefs = profile()->GetPrefs(); | 205 PrefService* prefs = profile()->GetPrefs(); |
264 | 206 |
265 PrepareURLResponse(net::HTTP_OK, true); | |
266 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 207 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
267 prefs->SetBoolean(prefs::kArcEnabled, true); | 208 prefs->SetBoolean(prefs::kArcEnabled, true); |
268 | 209 |
269 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 210 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
270 EXPECT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); | 211 EXPECT_EQ(ArcAuthService::State::FETCHING_CODE, auth_service()->state()); |
271 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 212 auth_service()->SetAuthCodeAndStartArc(kTestAuthCode); |
272 base::RunLoop().RunUntilIdle(); | |
273 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 213 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
274 EXPECT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); | 214 EXPECT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); |
275 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 215 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
276 auth_service()->OnSignInComplete(); | 216 auth_service()->OnSignInComplete(); |
277 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 217 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
278 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 218 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
279 EXPECT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); | 219 EXPECT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); |
280 | 220 |
281 // Second start, no fetching code is expected. | 221 // Second start, no fetching code is expected. |
282 auth_service()->Shutdown(); | 222 auth_service()->Shutdown(); |
283 EXPECT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 223 EXPECT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
284 EXPECT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); | 224 EXPECT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); |
285 auth_service()->OnPrimaryUserProfilePrepared(profile()); | 225 auth_service()->OnPrimaryUserProfilePrepared(profile()); |
286 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); | 226 EXPECT_TRUE(prefs->GetBoolean(prefs::kArcSignedIn)); |
287 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); | 227 EXPECT_EQ(ArcAuthService::State::ACTIVE, auth_service()->state()); |
288 EXPECT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); | 228 EXPECT_EQ(ArcBridgeService::State::READY, bridge_service()->state()); |
289 | 229 |
290 // Report failure. | 230 // Report failure. |
291 auth_service()->OnSignInFailed(arc::ArcSignInFailureReason::UNKNOWN_ERROR); | 231 auth_service()->OnSignInFailed(arc::ArcSignInFailureReason::UNKNOWN_ERROR); |
292 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); | 232 EXPECT_FALSE(prefs->GetBoolean(prefs::kArcSignedIn)); |
293 EXPECT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); | 233 EXPECT_EQ(ArcAuthService::State::STOPPED, auth_service()->state()); |
294 EXPECT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); | 234 EXPECT_EQ(ArcBridgeService::State::STOPPED, bridge_service()->state()); |
295 | 235 |
296 // Correctly stop service. | 236 // Correctly stop service. |
297 auth_service()->Shutdown(); | 237 auth_service()->Shutdown(); |
298 } | 238 } |
299 | 239 |
300 } // namespace arc | 240 } // namespace arc |
OLD | NEW |