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 |
| 31 enum class CreditCardExpiry : uint8_t { EXPIRED, VALID }; | |
|
Ilya Sherman
2016/10/20 07:38:08
Optional nit: Probably no need to specify uint8_t
| |
| 32 | |
| 30 class TestCardUnmaskDelegate : public CardUnmaskDelegate { | 33 class TestCardUnmaskDelegate : public CardUnmaskDelegate { |
| 31 public: | 34 public: |
| 32 TestCardUnmaskDelegate() : weak_factory_(this) {} | 35 TestCardUnmaskDelegate() : weak_factory_(this) {} |
| 33 | 36 |
| 34 virtual ~TestCardUnmaskDelegate() {} | 37 virtual ~TestCardUnmaskDelegate() {} |
| 35 | 38 |
| 36 // CardUnmaskDelegate implementation. | 39 // CardUnmaskDelegate implementation. |
| 37 void OnUnmaskResponse(const UnmaskResponse& response) override { | 40 void OnUnmaskResponse(const UnmaskResponse& response) override { |
| 38 response_ = response; | 41 response_ = response; |
| 39 } | 42 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 | 91 |
| 89 ~CardUnmaskPromptViewBrowserTest() override {} | 92 ~CardUnmaskPromptViewBrowserTest() override {} |
| 90 | 93 |
| 91 void SetUpOnMainThread() override { | 94 void SetUpOnMainThread() override { |
| 92 runner_ = new content::MessageLoopRunner; | 95 runner_ = new content::MessageLoopRunner; |
| 93 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); | 96 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| 94 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); | 97 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); |
| 95 delegate_.reset(new TestCardUnmaskDelegate()); | 98 delegate_.reset(new TestCardUnmaskDelegate()); |
| 96 } | 99 } |
| 97 | 100 |
| 101 void ShowUI(CreditCardExpiry expired) { | |
| 102 CardUnmaskPromptView* dialog = | |
| 103 CreateCardUnmaskPromptView(controller(), contents()); | |
| 104 CreditCard card = (expired == CreditCardExpiry::EXPIRED) | |
| 105 ? test::GetMaskedServerCard() | |
| 106 : test::GetMaskedServerCardAmex(); | |
| 107 controller()->ShowPrompt(dialog, card, AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 108 delegate()->GetWeakPtr()); | |
| 109 } | |
| 110 | |
| 98 void FreeDelegate() { delegate_.reset(); } | 111 void FreeDelegate() { delegate_.reset(); } |
| 99 | 112 |
| 100 content::WebContents* contents() { return contents_; } | 113 content::WebContents* contents() { return contents_; } |
| 101 TestCardUnmaskPromptController* controller() { return controller_.get(); } | 114 TestCardUnmaskPromptController* controller() { return controller_.get(); } |
| 102 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } | 115 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } |
| 103 | 116 |
| 104 protected: | 117 protected: |
| 105 // This member must outlive the controller. | 118 // This member must outlive the controller. |
| 106 scoped_refptr<content::MessageLoopRunner> runner_; | 119 scoped_refptr<content::MessageLoopRunner> runner_; |
| 107 | 120 |
| 108 private: | 121 private: |
| 109 content::WebContents* contents_; | 122 content::WebContents* contents_; |
| 110 std::unique_ptr<TestCardUnmaskPromptController> controller_; | 123 std::unique_ptr<TestCardUnmaskPromptController> controller_; |
| 111 std::unique_ptr<TestCardUnmaskDelegate> delegate_; | 124 std::unique_ptr<TestCardUnmaskDelegate> delegate_; |
| 112 | 125 |
| 113 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); | 126 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); |
| 114 }; | 127 }; |
| 115 | 128 |
| 129 // Permanently disabled test used to invoke the UI for the card unmask prompt | |
| 130 // with an expired credit card, which shows additional month/year controls. | |
| 131 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | |
| 132 DISABLED_InvokeExpired) { | |
| 133 ShowUI(CreditCardExpiry::EXPIRED); | |
| 134 ::test::RunTestInteractively(); | |
| 135 } | |
| 136 | |
| 137 // Permanently disabled test used to invoke the UI for the card unmask prompt | |
| 138 // with a valid credit card, which only shows the CCV Textfield. | |
| 139 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DISABLED_InvokeValid) { | |
| 140 ShowUI(CreditCardExpiry::VALID); | |
| 141 ::test::RunTestInteractively(); | |
| 142 } | |
| 143 | |
| 116 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { | 144 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { |
| 117 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 145 ShowUI(CreditCardExpiry::EXPIRED); |
| 118 test::GetMaskedServerCard(), | |
| 119 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 120 delegate()->GetWeakPtr()); | |
| 121 } | 146 } |
| 122 | 147 |
| 123 // TODO(bondd): bring up on Mac. | 148 // TODO(bondd): bring up on Mac. |
| 124 #if !defined(OS_MACOSX) | 149 #if !defined(OS_MACOSX) |
| 125 // Makes sure the user can close the dialog while the verification success | 150 // Makes sure the user can close the dialog while the verification success |
| 126 // message is showing. | 151 // message is showing. |
| 127 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 152 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
| 128 EarlyCloseAfterSuccess) { | 153 EarlyCloseAfterSuccess) { |
| 129 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 154 ShowUI(CreditCardExpiry::EXPIRED); |
| 130 test::GetMaskedServerCard(), | |
| 131 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 132 delegate()->GetWeakPtr()); | |
| 133 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), | 155 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), |
| 134 base::ASCIIToUTF16("10"), | 156 base::ASCIIToUTF16("10"), |
| 135 base::ASCIIToUTF16("19"), false); | 157 base::ASCIIToUTF16("19"), false); |
| 136 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); | 158 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); |
| 137 controller()->OnVerificationResult(AutofillClient::SUCCESS); | 159 controller()->OnVerificationResult(AutofillClient::SUCCESS); |
| 138 | 160 |
| 139 // Simulate the user clicking [x] before the "Success!" message disappears. | 161 // Simulate the user clicking [x] before the "Success!" message disappears. |
| 140 CardUnmaskPromptViewTester::For(controller()->view())->Close(); | 162 CardUnmaskPromptViewTester::For(controller()->view())->Close(); |
| 141 // Wait a little while; there should be no crash. | 163 // Wait a little while; there should be no crash. |
| 142 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 164 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 143 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, | 165 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, |
| 144 base::Unretained(runner_.get())), | 166 base::Unretained(runner_.get())), |
| 145 2 * controller()->GetSuccessMessageDuration()); | 167 2 * controller()->GetSuccessMessageDuration()); |
| 146 runner_->Run(); | 168 runner_->Run(); |
| 147 } | 169 } |
| 148 #endif | 170 #endif |
| 149 | 171 |
| 150 // Makes sure the tab can be closed while the dialog is showing. | 172 // Makes sure the tab can be closed while the dialog is showing. |
| 151 // https://crbug.com/484376 | 173 // https://crbug.com/484376 |
| 152 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 174 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
| 153 CloseTabWhileDialogShowing) { | 175 CloseTabWhileDialogShowing) { |
| 154 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 176 ShowUI(CreditCardExpiry::EXPIRED); |
| 155 test::GetMaskedServerCard(), | |
| 156 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 157 delegate()->GetWeakPtr()); | |
| 158 // Simulate AutofillManager (the delegate in production code) being destroyed | 177 // Simulate AutofillManager (the delegate in production code) being destroyed |
| 159 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. | 178 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. |
| 160 FreeDelegate(); | 179 FreeDelegate(); |
| 161 browser()->tab_strip_model()->GetActiveWebContents()->Close(); | 180 browser()->tab_strip_model()->GetActiveWebContents()->Close(); |
| 162 | 181 |
| 163 content::RunAllPendingInMessageLoop(); | 182 content::RunAllPendingInMessageLoop(); |
| 164 } | 183 } |
| 165 | 184 |
| 166 } // namespace | 185 } // namespace |
| 167 | 186 |
| 168 } // namespace autofill | 187 } // namespace autofill |
| OLD | NEW |