Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_unittest.cc

Issue 23717029: Disable submit button briefly when launching rAc dialog (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge master Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_number_(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
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 // 60 second delay to avoid test flakiness. The test would be flaky if this
Evan Stade 2013/09/05 16:29:44 I don't think this is necessary. The test executes
please use gerrit instead 2013/09/05 18:40:49 Using the same delay in production and in testing.
284 // delay expired before the test finishes. This delay does not affect
285 // execution time of the test.
286 static const int kSimulatedSubmitButtonDelaySeconds = 60;
287 AutofillDialogControllerImpl::SubmitButtonDelayBegin(
288 base::TimeDelta::FromSeconds(kSimulatedSubmitButtonDelaySeconds));
289 }
290
291 void SimulateSubmitButtonDelayEnd() {
292 AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting();
293 }
294
295 // Returns the number of times that the submit button was delayed.
296 int get_submit_button_delay_number() const {
297 return submit_button_delay_number_;
298 }
299
281 MOCK_METHOD0(LoadRiskFingerprintData, void()); 300 MOCK_METHOD0(LoadRiskFingerprintData, void());
282 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData; 301 using AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData;
283 using AutofillDialogControllerImpl::IsEditingExistingData; 302 using AutofillDialogControllerImpl::IsEditingExistingData;
284 303
285 protected: 304 protected:
286 virtual PersonalDataManager* GetManager() OVERRIDE { 305 virtual PersonalDataManager* GetManager() OVERRIDE {
287 return &test_manager_; 306 return &test_manager_;
288 } 307 }
289 308
290 virtual wallet::WalletClient* GetWalletClient() OVERRIDE { 309 virtual wallet::WalletClient* GetWalletClient() OVERRIDE {
(...skipping 10 matching lines...) Expand all
301 return true; 320 return true;
302 } 321 }
303 322
304 virtual void ShowNewCreditCardBubble( 323 virtual void ShowNewCreditCardBubble(
305 scoped_ptr<CreditCard> new_card, 324 scoped_ptr<CreditCard> new_card,
306 scoped_ptr<AutofillProfile> billing_profile) OVERRIDE { 325 scoped_ptr<AutofillProfile> billing_profile) OVERRIDE {
307 mock_new_card_bubble_controller_->Show(new_card.Pass(), 326 mock_new_card_bubble_controller_->Show(new_card.Pass(),
308 billing_profile.Pass()); 327 billing_profile.Pass());
309 } 328 }
310 329
330 // AutofillDialogControllerImpl calls this method before showing the dialog
331 // window.
332 virtual void SubmitButtonDelayBegin(base::TimeDelta delay) OVERRIDE {
333 // Do not delay enabling the submit button in testing.
334 submit_button_delay_number_++;
335 }
336
311 private: 337 private:
312 // To specify our own metric logger. 338 // To specify our own metric logger.
313 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { 339 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE {
314 return metric_logger_; 340 return metric_logger_;
315 } 341 }
316 342
317 const AutofillMetrics& metric_logger_; 343 const AutofillMetrics& metric_logger_;
318 TestPersonalDataManager test_manager_; 344 TestPersonalDataManager test_manager_;
319 testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_; 345 testing::NiceMock<wallet::MockWalletClient> mock_wallet_client_;
320 GURL open_tab_url_; 346 GURL open_tab_url_;
321 MockNewCreditCardBubbleController* mock_new_card_bubble_controller_; 347 MockNewCreditCardBubbleController* mock_new_card_bubble_controller_;
322 348
349 // The number of times that the submit button was delayed.
350 int submit_button_delay_number_;
351
323 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController); 352 DISALLOW_COPY_AND_ASSIGN(TestAutofillDialogController);
324 }; 353 };
325 354
326 class TestGeneratedCreditCardBubbleController : 355 class TestGeneratedCreditCardBubbleController :
327 public GeneratedCreditCardBubbleController { 356 public GeneratedCreditCardBubbleController {
328 public: 357 public:
329 explicit TestGeneratedCreditCardBubbleController( 358 explicit TestGeneratedCreditCardBubbleController(
330 content::WebContents* contents) 359 content::WebContents* contents)
331 : GeneratedCreditCardBubbleController(contents) { 360 : GeneratedCreditCardBubbleController(contents) {
332 contents->SetUserData(UserDataKey(), this); 361 contents->SetUserData(UserDataKey(), this);
(...skipping 2039 matching lines...) Expand 10 before | Expand all | Expand 10 after
2372 TEST_F(AutofillDialogControllerTest, 2401 TEST_F(AutofillDialogControllerTest,
2373 SaveInChromePreferenceRememberedOnSuccess) { 2402 SaveInChromePreferenceRememberedOnSuccess) {
2374 EXPECT_TRUE(controller()->ShouldSaveInChrome()); 2403 EXPECT_TRUE(controller()->ShouldSaveInChrome());
2375 SwitchToAutofill(); 2404 SwitchToAutofill();
2376 FillCreditCardInputs(); 2405 FillCreditCardInputs();
2377 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false); 2406 controller()->GetView()->CheckSaveDetailsLocallyCheckbox(false);
2378 controller()->OnAccept(); 2407 controller()->OnAccept();
2379 EXPECT_FALSE(controller()->ShouldSaveInChrome()); 2408 EXPECT_FALSE(controller()->ShouldSaveInChrome());
2380 } 2409 }
2381 2410
2411 TEST_F(AutofillDialogControllerTest, SubmitButtonIsDelayedOnShow) {
2412 EXPECT_EQ(1, controller()->get_submit_button_delay_number());
Evan Stade 2013/09/05 16:29:44 nit: instead of having a separate test for this, a
please use gerrit instead 2013/09/05 18:40:49 Done.
2413 }
2414
2415 TEST_F(AutofillDialogControllerTest,
2416 SubmitButtonIsDisabled_SpinnerFinishesBeforeDelay) {
2417 // Begin the submit button delay.
2418 controller()->SimulateSubmitButtonDelayBegin();
2419
2420 EXPECT_TRUE(controller()->ShouldShowSpinner());
2421 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2422
2423 // Stop the spinner.
2424 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2425
2426 EXPECT_FALSE(controller()->ShouldShowSpinner());
2427 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2428
2429 // End the submit button delay.
2430 controller()->SimulateSubmitButtonDelayEnd();
2431
2432 EXPECT_FALSE(controller()->ShouldShowSpinner());
2433 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2434 }
2435
2436 TEST_F(AutofillDialogControllerTest,
2437 SubmitButtonIsDisabled_SpinnerFinishesAfterDelay) {
2438 // Begin the submit button delay.
2439 controller()->SimulateSubmitButtonDelayBegin();
2440
2441 EXPECT_TRUE(controller()->ShouldShowSpinner());
2442 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2443
2444 // End the submit button delay.
2445 controller()->SimulateSubmitButtonDelayEnd();
2446
2447 EXPECT_TRUE(controller()->ShouldShowSpinner());
2448 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2449
2450 // Stop the spinner.
2451 controller()->OnDidGetWalletItems(CompleteAndValidWalletItems());
2452
2453 EXPECT_FALSE(controller()->ShouldShowSpinner());
2454 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2455 }
2456
2457 TEST_F(AutofillDialogControllerTest, SubmitButtonIsDisabled_NoSpinner) {
2458 // Begin the submit button delay.
2459 controller()->SimulateSubmitButtonDelayBegin();
2460
2461 EXPECT_TRUE(controller()->ShouldShowSpinner());
2462 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2463
2464 // There's no spinner in Autofill mode.
2465 SwitchToAutofill();
2466
2467 EXPECT_FALSE(controller()->ShouldShowSpinner());
2468 EXPECT_FALSE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2469
2470 // End the submit button delay.
2471 controller()->SimulateSubmitButtonDelayEnd();
2472
2473 EXPECT_FALSE(controller()->ShouldShowSpinner());
2474 EXPECT_TRUE(controller()->IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK));
2475 }
2476
2382 } // namespace autofill 2477 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698