OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <map> | 5 #include <map> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 const std::string&)>& callback, | 234 const std::string&)>& callback, |
235 MockNewCreditCardBubbleController* mock_new_card_bubble_controller) | 235 MockNewCreditCardBubbleController* mock_new_card_bubble_controller) |
236 : AutofillDialogControllerImpl(contents, | 236 : AutofillDialogControllerImpl(contents, |
237 form_structure, | 237 form_structure, |
238 source_url, | 238 source_url, |
239 callback), | 239 callback), |
240 metric_logger_(metric_logger), | 240 metric_logger_(metric_logger), |
241 mock_wallet_client_( | 241 mock_wallet_client_( |
242 Profile::FromBrowserContext(contents->GetBrowserContext())-> | 242 Profile::FromBrowserContext(contents->GetBrowserContext())-> |
243 GetRequestContext(), this), | 243 GetRequestContext(), this), |
244 mock_new_card_bubble_controller_(mock_new_card_bubble_controller) {} | 244 mock_new_card_bubble_controller_(mock_new_card_bubble_controller), |
| 245 submit_button_delay_count_(0) {} |
245 | 246 |
246 virtual ~TestAutofillDialogController() {} | 247 virtual ~TestAutofillDialogController() {} |
247 | 248 |
248 virtual AutofillDialogView* CreateView() OVERRIDE { | 249 virtual AutofillDialogView* CreateView() OVERRIDE { |
249 return new testing::NiceMock<TestAutofillDialogView>(); | 250 return new testing::NiceMock<TestAutofillDialogView>(); |
250 } | 251 } |
251 | 252 |
252 void Init(content::BrowserContext* browser_context) { | 253 void Init(content::BrowserContext* browser_context) { |
253 test_manager_.Init(browser_context); | 254 test_manager_.Init(browser_context); |
254 } | 255 } |
(...skipping 16 matching lines...) Expand all Loading... |
271 OnWalletSigninError(); | 272 OnWalletSigninError(); |
272 } | 273 } |
273 | 274 |
274 // Skips past the 2 second wait between FinishSubmit and DoFinishSubmit. | 275 // Skips past the 2 second wait between FinishSubmit and DoFinishSubmit. |
275 void ForceFinishSubmit() { | 276 void ForceFinishSubmit() { |
276 #if defined(TOOLKIT_VIEWS) | 277 #if defined(TOOLKIT_VIEWS) |
277 DoFinishSubmit(); | 278 DoFinishSubmit(); |
278 #endif | 279 #endif |
279 } | 280 } |
280 | 281 |
| 282 void SimulateSubmitButtonDelayBegin() { |
| 283 AutofillDialogControllerImpl::SubmitButtonDelayBegin(); |
| 284 } |
| 285 |
| 286 void SimulateSubmitButtonDelayEnd() { |
| 287 AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting(); |
| 288 } |
| 289 |
| 290 // Returns the number of times that the submit button was delayed. |
| 291 int get_submit_button_delay_count() const { |
| 292 return submit_button_delay_count_; |
| 293 } |
| 294 |
281 MOCK_METHOD0(LoadRiskFingerprintData, void()); | 295 MOCK_METHOD0(LoadRiskFingerprintData, void()); |
282 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; | 296 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; |
283 using AutofillDialogControllerImpl::IsEditingExistingData; | 297 using AutofillDialogControllerImpl::IsEditingExistingData; |
284 | 298 |
285 protected: | 299 protected: |
286 virtual PersonalDataManager* GetManager() OVERRIDE { | 300 virtual PersonalDataManager* GetManager() OVERRIDE { |
287 return &test_manager_; | 301 return &test_manager_; |
288 } | 302 } |
289 | 303 |
290 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { | 304 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { |
(...skipping 10 matching lines...) Expand all Loading... |
301 return true; | 315 return true; |
302 } | 316 } |
303 | 317 |
304 virtual void ShowNewCreditCardBubble( | 318 virtual void ShowNewCreditCardBubble( |
305 scoped_ptr<CreditCard> new_card, | 319 scoped_ptr<CreditCard> new_card, |
306 scoped_ptr<AutofillProfile> billing_profile) OVERRIDE { | 320 scoped_ptr<AutofillProfile> billing_profile) OVERRIDE { |
307 mock_new_card_bubble_controller_->Show(new_card.Pass(), | 321 mock_new_card_bubble_controller_->Show(new_card.Pass(), |
308 billing_profile.Pass()); | 322 billing_profile.Pass()); |
309 } | 323 } |
310 | 324 |
| 325 // AutofillDialogControllerImpl calls this method before showing the dialog |
| 326 // window. |
| 327 virtual void SubmitButtonDelayBegin() OVERRIDE { |
| 328 // Do not delay enabling the submit button in testing. |
| 329 submit_button_delay_count_++; |
| 330 } |
| 331 |
311 private: | 332 private: |
312 // To specify our own metric logger. | 333 // To specify our own metric logger. |
313 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { | 334 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
314 return metric_logger_; | 335 return metric_logger_; |
315 } | 336 } |
316 | 337 |
317 const AutofillMetrics& metric_logger_; | 338 const AutofillMetrics& metric_logger_; |
318 TestPersonalDataManager test_manager_; | 339 TestPersonalDataManager test_manager_; |
319 testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_; | 340 testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_; |
320 GURL open_tab_url_; | 341 GURL open_tab_url_; |
321 MockNewCreditCardBubbleController* mock_new_card_bubble_controller_; | 342 MockNewCreditCardBubbleController* mock_new_card_bubble_controller_; |
322 | 343 |
| 344 // The number of times that the submit button was delayed. |
| 345 int submit_button_delay_count_; |
| 346 |
323 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); | 347 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); |
324 }; | 348 }; |
325 | 349 |
326 class TestGeneratedCreditCardBubbleController : | 350 class TestGeneratedCreditCardBubbleController : |
327 public GeneratedCreditCardBubbleController { | 351 public GeneratedCreditCardBubbleController { |
328 public: | 352 public: |
329 explicit TestGeneratedCreditCardBubbleController( | 353 explicit TestGeneratedCreditCardBubbleController( |
330 content::WebContents* contents) | 354 content::WebContents* contents) |
331 : GeneratedCreditCardBubbleController(contents) { | 355 : GeneratedCreditCardBubbleController(contents) { |
332 contents->SetUserData(UserDataKey(), this); | 356 contents->SetUserData(UserDataKey(), this); |
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2372 TEST_F(AutofillDialogControllerTest, | 2396 TEST_F(AutofillDialogControllerTest, |
2373 SaveInChromePreferenceRememberedOnSuccess) { | 2397 SaveInChromePreferenceRememberedOnSuccess) { |
2374 EXPECT_TRUE(controller()->ShouldSaveInChrome()); | 2398 EXPECT_TRUE(controller()->ShouldSaveInChrome()); |
2375 SwitchToAutofill(); | 2399 SwitchToAutofill(); |
2376 FillCreditCardInputs(); | 2400 FillCreditCardInputs(); |
2377 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false); | 2401 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false); |
2378 controller()->OnAccept(); | 2402 controller()->OnAccept(); |
2379 EXPECT_FALSE(controller()->ShouldSaveInChrome()); | 2403 EXPECT_FALSE(controller()->ShouldSaveInChrome()); |
2380 } | 2404 } |
2381 | 2405 |
| 2406 TEST_F(AutofillDialogControllerTest, |
| 2407 SubmitButtonIsDisabled_SpinnerFinishesBeforeDelay) { |
| 2408 EXPECT_EQ(1, controller()->get_submit_button_delay_count()); |
| 2409 |
| 2410 // Begin the submit button delay. |
| 2411 controller()->SimulateSubmitButtonDelayBegin(); |
| 2412 |
| 2413 EXPECT_TRUE(controller()->ShouldShowSpinner()); |
| 2414 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2415 |
| 2416 // Stop the spinner. |
| 2417 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
| 2418 |
| 2419 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
| 2420 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2421 |
| 2422 // End the submit button delay. |
| 2423 controller()->SimulateSubmitButtonDelayEnd(); |
| 2424 |
| 2425 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
| 2426 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2427 } |
| 2428 |
| 2429 TEST_F(AutofillDialogControllerTest, |
| 2430 SubmitButtonIsDisabled_SpinnerFinishesAfterDelay) { |
| 2431 EXPECT_EQ(1, controller()->get_submit_button_delay_count()); |
| 2432 |
| 2433 // Begin the submit button delay. |
| 2434 controller()->SimulateSubmitButtonDelayBegin(); |
| 2435 |
| 2436 EXPECT_TRUE(controller()->ShouldShowSpinner()); |
| 2437 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2438 |
| 2439 // End the submit button delay. |
| 2440 controller()->SimulateSubmitButtonDelayEnd(); |
| 2441 |
| 2442 EXPECT_TRUE(controller()->ShouldShowSpinner()); |
| 2443 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2444 |
| 2445 // Stop the spinner. |
| 2446 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems()); |
| 2447 |
| 2448 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
| 2449 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2450 } |
| 2451 |
| 2452 TEST_F(AutofillDialogControllerTest, SubmitButtonIsDisabled_NoSpinner) { |
| 2453 EXPECT_EQ(1, controller()->get_submit_button_delay_count()); |
| 2454 |
| 2455 // Begin the submit button delay. |
| 2456 controller()->SimulateSubmitButtonDelayBegin(); |
| 2457 |
| 2458 EXPECT_TRUE(controller()->ShouldShowSpinner()); |
| 2459 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2460 |
| 2461 // There's no spinner in Autofill mode. |
| 2462 SwitchToAutofill(); |
| 2463 |
| 2464 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
| 2465 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2466 |
| 2467 // End the submit button delay. |
| 2468 controller()->SimulateSubmitButtonDelayEnd(); |
| 2469 |
| 2470 EXPECT_FALSE(controller()->ShouldShowSpinner()); |
| 2471 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)); |
| 2472 } |
| 2473 |
2382 } // namespace autofill | 2474 } // namespace autofill |
OLD | NEW |