| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/extensions/app_notify_channel_setup.h" | 10 #include "chrome/browser/extensions/app_notify_channel_setup.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 return new AppNotifyChannelSetup(&profile_, | 175 return new AppNotifyChannelSetup(&profile_, |
| 176 kFakeExtensionId, | 176 kFakeExtensionId, |
| 177 "1234", | 177 "1234", |
| 178 page_url, | 178 page_url, |
| 179 kRouteId, | 179 kRouteId, |
| 180 kCallbackId, | 180 kCallbackId, |
| 181 ui_.release(), | 181 ui_.release(), |
| 182 delegate_.AsWeakPtr()); | 182 delegate_.AsWeakPtr()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 virtual void SetupLogin(bool should_succeed) { | 185 virtual void SetupLogin(bool should_prompt, bool should_succeed) { |
| 186 if (should_succeed) { | 186 if (should_succeed) { |
| 187 SetLoggedInUser("user@gmail.com"); | 187 SetLoggedInUser("user@gmail.com"); |
| 188 profile_.SetTokenServiceHasTokenResult(true); | 188 profile_.SetTokenServiceHasTokenResult(true); |
| 189 } else { | |
| 190 ui_->SetSyncSetupResult(false); | |
| 191 } | 189 } |
| 190 if (should_prompt) |
| 191 ui_->SetSyncSetupResult(should_succeed); |
| 192 } | 192 } |
| 193 | 193 |
| 194 virtual void SetupFetchAccessToken(bool should_succeed) { | 194 virtual void SetupFetchAccessToken(bool should_succeed) { |
| 195 factory_.SetFakeResponse( | 195 factory_.SetFakeResponse( |
| 196 GaiaUrls::GetInstance()->oauth2_token_url(), | 196 GaiaUrls::GetInstance()->oauth2_token_url(), |
| 197 kValidAccessTokenResponse, | 197 kValidAccessTokenResponse, |
| 198 should_succeed); | 198 should_succeed); |
| 199 } | 199 } |
| 200 | 200 |
| 201 virtual void SetupRecordGrant(bool should_succeed) { | 201 virtual void SetupRecordGrant(bool should_succeed) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 223 protected: | 223 protected: |
| 224 MessageLoop message_loop_; | 224 MessageLoop message_loop_; |
| 225 content::TestBrowserThread ui_thread_; | 225 content::TestBrowserThread ui_thread_; |
| 226 TestProfile profile_; | 226 TestProfile profile_; |
| 227 TestDelegate delegate_; | 227 TestDelegate delegate_; |
| 228 scoped_ptr<TestUI> ui_; | 228 scoped_ptr<TestUI> ui_; |
| 229 FakeURLFetcherFactory factory_; | 229 FakeURLFetcherFactory factory_; |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 TEST_F(AppNotifyChannelSetupTest, LoginFailure) { | 232 TEST_F(AppNotifyChannelSetupTest, LoginFailure) { |
| 233 SetupLogin(false); | 233 SetupLogin(true, false); |
| 234 | 234 |
| 235 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); | 235 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
| 236 RunServerTest(setup, "", "canceled_by_user"); | 236 RunServerTest(setup, "", "canceled_by_user"); |
| 237 } | 237 } |
| 238 | 238 |
| 239 TEST_F(AppNotifyChannelSetupTest, FetchAccessTokenFailure) { | 239 TEST_F(AppNotifyChannelSetupTest, DoubleFetchAccessTokenFailure) { |
| 240 SetupLogin(true); | 240 SetupLogin(false, true); |
| 241 SetupFetchAccessToken(false); |
| 242 SetupLogin(true, true); |
| 241 SetupFetchAccessToken(false); | 243 SetupFetchAccessToken(false); |
| 242 | 244 |
| 243 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); | 245 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
| 244 RunServerTest(setup, "", "internal_error"); | 246 RunServerTest(setup, "", "internal_error"); |
| 245 } | 247 } |
| 246 | 248 |
| 247 TEST_F(AppNotifyChannelSetupTest, RecordGrantFailure) { | 249 TEST_F(AppNotifyChannelSetupTest, RecordGrantFailure) { |
| 248 SetupLogin(true); | 250 SetupLogin(false, true); |
| 249 SetupFetchAccessToken(true); | 251 SetupFetchAccessToken(true); |
| 250 SetupRecordGrant(false); | 252 SetupRecordGrant(false); |
| 251 | 253 |
| 252 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); | 254 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
| 253 RunServerTest(setup, "", "internal_error"); | 255 RunServerTest(setup, "", "internal_error"); |
| 254 } | 256 } |
| 255 | 257 |
| 256 TEST_F(AppNotifyChannelSetupTest, GetChannelIdFailure) { | 258 TEST_F(AppNotifyChannelSetupTest, GetChannelIdFailure) { |
| 257 SetupLogin(true); | 259 SetupLogin(false, true); |
| 258 SetupFetchAccessToken(true); | 260 SetupFetchAccessToken(true); |
| 259 SetupRecordGrant(true); | 261 SetupRecordGrant(true); |
| 260 SetupGetChannelId(false); | 262 SetupGetChannelId(false); |
| 261 | 263 |
| 262 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); | 264 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
| 263 RunServerTest(setup, "", "internal_error"); | 265 RunServerTest(setup, "", "internal_error"); |
| 264 } | 266 } |
| 265 | 267 |
| 266 TEST_F(AppNotifyChannelSetupTest, ServerSuccess) { | 268 TEST_F(AppNotifyChannelSetupTest, FirstFetchAccessTokenSuccess) { |
| 267 SetupLogin(true); | 269 SetupLogin(false, true); |
| 268 SetupFetchAccessToken(true); | 270 SetupFetchAccessToken(true); |
| 269 SetupRecordGrant(true); | 271 SetupRecordGrant(true); |
| 270 SetupGetChannelId(true); | 272 SetupGetChannelId(true); |
| 271 | 273 |
| 272 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); | 274 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
| 273 RunServerTest(setup, "dummy_do_not_use", ""); | 275 RunServerTest(setup, "dummy_do_not_use", ""); |
| 274 } | 276 } |
| 277 |
| 278 TEST_F(AppNotifyChannelSetupTest, SecondFetchAccessTokenSuccess) { |
| 279 SetupLogin(false, true); |
| 280 SetupFetchAccessToken(false); |
| 281 SetupLogin(true, true); |
| 282 SetupFetchAccessToken(true); |
| 283 SetupRecordGrant(true); |
| 284 SetupGetChannelId(true); |
| 285 |
| 286 scoped_refptr<AppNotifyChannelSetup> setup = CreateInstance(); |
| 287 RunServerTest(setup, "dummy_do_not_use", ""); |
| 288 } |
| OLD | NEW |