Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/guid.h" | 6 #include "base/guid.h" |
| 7 #include "base/location.h" | 7 #include "base/location.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h" | 13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h" |
| 14 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" | 14 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "components/autofill/core/browser/autofill_test_utils.h" | 18 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 19 #include "components/autofill/core/browser/card_unmask_delegate.h" | 19 #include "components/autofill/core/browser/card_unmask_delegate.h" |
| 20 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl .h" | 20 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl .h" |
| 21 #include "components/user_prefs/user_prefs.h" | 21 #include "components/user_prefs/user_prefs.h" |
| 22 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 25 #include "ui/base/test/user_interactive_test_case.h" | |
| 25 | 26 |
| 26 namespace autofill { | 27 namespace autofill { |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 class TestCardUnmaskDelegate : public CardUnmaskDelegate { | 31 class TestCardUnmaskDelegate : public CardUnmaskDelegate { |
| 31 public: | 32 public: |
| 32 TestCardUnmaskDelegate() : weak_factory_(this) {} | 33 TestCardUnmaskDelegate() : weak_factory_(this) {} |
| 33 | 34 |
| 34 virtual ~TestCardUnmaskDelegate() {} | 35 virtual ~TestCardUnmaskDelegate() {} |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 | 89 |
| 89 ~CardUnmaskPromptViewBrowserTest() override {} | 90 ~CardUnmaskPromptViewBrowserTest() override {} |
| 90 | 91 |
| 91 void SetUpOnMainThread() override { | 92 void SetUpOnMainThread() override { |
| 92 runner_ = new content::MessageLoopRunner; | 93 runner_ = new content::MessageLoopRunner; |
| 93 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); | 94 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| 94 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); | 95 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); |
| 95 delegate_.reset(new TestCardUnmaskDelegate()); | 96 delegate_.reset(new TestCardUnmaskDelegate()); |
| 96 } | 97 } |
| 97 | 98 |
| 99 void ShowUI(bool expired) { | |
|
Ilya Sherman
2016/10/18 23:59:58
nit: Please define an enum with values EXPIRED and
Patti Lor
2016/10/20 00:58:06
Done, thanks!
| |
| 100 CardUnmaskPromptView* dialog = | |
| 101 CreateCardUnmaskPromptView(controller(), contents()); | |
| 102 CreditCard cc = | |
|
Ilya Sherman
2016/10/18 23:59:58
nit: s/cc/card
Patti Lor
2016/10/20 00:58:06
Done.
| |
| 103 expired ? test::GetMaskedServerCard() : test::GetMaskedServerCardAmex(); | |
| 104 controller()->ShowPrompt(dialog, cc, AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 105 delegate()->GetWeakPtr()); | |
| 106 } | |
| 107 | |
| 98 void FreeDelegate() { delegate_.reset(); } | 108 void FreeDelegate() { delegate_.reset(); } |
| 99 | 109 |
| 100 content::WebContents* contents() { return contents_; } | 110 content::WebContents* contents() { return contents_; } |
| 101 TestCardUnmaskPromptController* controller() { return controller_.get(); } | 111 TestCardUnmaskPromptController* controller() { return controller_.get(); } |
| 102 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } | 112 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } |
| 103 | 113 |
| 104 protected: | 114 protected: |
| 105 // This member must outlive the controller. | 115 // This member must outlive the controller. |
| 106 scoped_refptr<content::MessageLoopRunner> runner_; | 116 scoped_refptr<content::MessageLoopRunner> runner_; |
| 107 | 117 |
| 108 private: | 118 private: |
| 109 content::WebContents* contents_; | 119 content::WebContents* contents_; |
| 110 std::unique_ptr<TestCardUnmaskPromptController> controller_; | 120 std::unique_ptr<TestCardUnmaskPromptController> controller_; |
| 111 std::unique_ptr<TestCardUnmaskDelegate> delegate_; | 121 std::unique_ptr<TestCardUnmaskDelegate> delegate_; |
| 112 | 122 |
| 113 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); | 123 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); |
| 114 }; | 124 }; |
| 115 | 125 |
| 126 // Permanently disabled test used to invoke the UI for the card unmask prompt | |
| 127 // with an expired credit card, which shows additional month/year controls. | |
| 128 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | |
| 129 DISABLED_InvokeExpired) { | |
| 130 ShowUI(true); | |
| 131 ::test::RunTestInteractively(); | |
| 132 } | |
| 133 | |
| 134 // Permanently disabled test used to invoke the UI for the card unmask prompt | |
| 135 // with a valid credit card, which only shows the CCV Textfield. | |
| 136 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DISABLED_InvokeValid) { | |
| 137 ShowUI(false); | |
| 138 ::test::RunTestInteractively(); | |
| 139 } | |
| 140 | |
| 116 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { | 141 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { |
| 117 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 142 ShowUI(true); |
| 118 test::GetMaskedServerCard(), | |
| 119 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 120 delegate()->GetWeakPtr()); | |
| 121 } | 143 } |
| 122 | 144 |
| 123 // TODO(bondd): bring up on Mac. | 145 // TODO(bondd): bring up on Mac. |
| 124 #if !defined(OS_MACOSX) | 146 #if !defined(OS_MACOSX) |
| 125 // Makes sure the user can close the dialog while the verification success | 147 // Makes sure the user can close the dialog while the verification success |
| 126 // message is showing. | 148 // message is showing. |
| 127 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 149 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
| 128 EarlyCloseAfterSuccess) { | 150 EarlyCloseAfterSuccess) { |
| 129 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 151 ShowUI(true); |
| 130 test::GetMaskedServerCard(), | |
| 131 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 132 delegate()->GetWeakPtr()); | |
| 133 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), | 152 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), |
| 134 base::ASCIIToUTF16("10"), | 153 base::ASCIIToUTF16("10"), |
| 135 base::ASCIIToUTF16("19"), false); | 154 base::ASCIIToUTF16("19"), false); |
| 136 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); | 155 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); |
| 137 controller()->OnVerificationResult(AutofillClient::SUCCESS); | 156 controller()->OnVerificationResult(AutofillClient::SUCCESS); |
| 138 | 157 |
| 139 // Simulate the user clicking [x] before the "Success!" message disappears. | 158 // Simulate the user clicking [x] before the "Success!" message disappears. |
| 140 CardUnmaskPromptViewTester::For(controller()->view())->Close(); | 159 CardUnmaskPromptViewTester::For(controller()->view())->Close(); |
| 141 // Wait a little while; there should be no crash. | 160 // Wait a little while; there should be no crash. |
| 142 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 161 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 143 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, | 162 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, |
| 144 base::Unretained(runner_.get())), | 163 base::Unretained(runner_.get())), |
| 145 2 * controller()->GetSuccessMessageDuration()); | 164 2 * controller()->GetSuccessMessageDuration()); |
| 146 runner_->Run(); | 165 runner_->Run(); |
| 147 } | 166 } |
| 148 #endif | 167 #endif |
| 149 | 168 |
| 150 // Makes sure the tab can be closed while the dialog is showing. | 169 // Makes sure the tab can be closed while the dialog is showing. |
| 151 // https://crbug.com/484376 | 170 // https://crbug.com/484376 |
| 152 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 171 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
| 153 CloseTabWhileDialogShowing) { | 172 CloseTabWhileDialogShowing) { |
| 154 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 173 ShowUI(true); |
| 155 test::GetMaskedServerCard(), | |
| 156 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 157 delegate()->GetWeakPtr()); | |
| 158 // Simulate AutofillManager (the delegate in production code) being destroyed | 174 // Simulate AutofillManager (the delegate in production code) being destroyed |
| 159 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. | 175 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. |
| 160 FreeDelegate(); | 176 FreeDelegate(); |
| 161 browser()->tab_strip_model()->GetActiveWebContents()->Close(); | 177 browser()->tab_strip_model()->GetActiveWebContents()->Close(); |
| 162 | 178 |
| 163 content::RunAllPendingInMessageLoop(); | 179 content::RunAllPendingInMessageLoop(); |
| 164 } | 180 } |
| 165 | 181 |
| 166 } // namespace | 182 } // namespace |
| 167 | 183 |
| 168 } // namespace autofill | 184 } // namespace autofill |
| OLD | NEW |