| 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/command_line.h" |
| 6 #include "base/guid.h" | 7 #include "base/guid.h" |
| 7 #include "base/location.h" | 8 #include "base/location.h" |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h" | 14 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h" |
| 14 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" | 15 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" |
| 15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/invoke_ui_browser_test.h" |
| 18 #include "components/autofill/core/browser/autofill_test_utils.h" | 20 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 19 #include "components/autofill/core/browser/card_unmask_delegate.h" | 21 #include "components/autofill/core/browser/card_unmask_delegate.h" |
| 20 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" | 22 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" |
| 21 #include "components/user_prefs/user_prefs.h" | 23 #include "components/user_prefs/user_prefs.h" |
| 22 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 23 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/test/test_utils.h" | 26 #include "content/public/test/test_utils.h" |
| 25 | 27 |
| 26 namespace autofill { | 28 namespace autofill { |
| 27 | 29 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 90 |
| 89 ~CardUnmaskPromptViewBrowserTest() override {} | 91 ~CardUnmaskPromptViewBrowserTest() override {} |
| 90 | 92 |
| 91 void SetUpOnMainThread() override { | 93 void SetUpOnMainThread() override { |
| 92 runner_ = new content::MessageLoopRunner; | 94 runner_ = new content::MessageLoopRunner; |
| 93 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); | 95 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| 94 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); | 96 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); |
| 95 delegate_.reset(new TestCardUnmaskDelegate()); | 97 delegate_.reset(new TestCardUnmaskDelegate()); |
| 96 } | 98 } |
| 97 | 99 |
| 100 void ShowUI() { |
| 101 controller()->ShowPrompt( |
| 102 CreateCardUnmaskPromptView(controller(), contents()), |
| 103 test::GetMaskedServerCard(), AutofillClient::UNMASK_FOR_AUTOFILL, |
| 104 delegate()->GetWeakPtr()); |
| 105 } |
| 106 |
| 98 void FreeDelegate() { delegate_.reset(); } | 107 void FreeDelegate() { delegate_.reset(); } |
| 99 | 108 |
| 100 content::WebContents* contents() { return contents_; } | 109 content::WebContents* contents() { return contents_; } |
| 101 TestCardUnmaskPromptController* controller() { return controller_.get(); } | 110 TestCardUnmaskPromptController* controller() { return controller_.get(); } |
| 102 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } | 111 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } |
| 103 | 112 |
| 104 protected: | 113 protected: |
| 105 // This member must outlive the controller. | 114 // This member must outlive the controller. |
| 106 scoped_refptr<content::MessageLoopRunner> runner_; | 115 scoped_refptr<content::MessageLoopRunner> runner_; |
| 107 | 116 |
| 108 private: | 117 private: |
| 109 content::WebContents* contents_; | 118 content::WebContents* contents_; |
| 110 std::unique_ptr<TestCardUnmaskPromptController> controller_; | 119 std::unique_ptr<TestCardUnmaskPromptController> controller_; |
| 111 std::unique_ptr<TestCardUnmaskDelegate> delegate_; | 120 std::unique_ptr<TestCardUnmaskDelegate> delegate_; |
| 112 | 121 |
| 113 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); | 122 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); |
| 114 }; | 123 }; |
| 115 | 124 |
| 125 class InvokeCardUnmaskPromptViewBrowserTest |
| 126 : public CardUnmaskPromptViewBrowserTest, |
| 127 public InvokeUIBrowserTest { |
| 128 public: |
| 129 InvokeCardUnmaskPromptViewBrowserTest() |
| 130 : CardUnmaskPromptViewBrowserTest(), InvokeUIBrowserTest() {} |
| 131 |
| 132 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 133 SetCommandLineFlags(command_line); |
| 134 } |
| 135 |
| 136 void SetUp() override { |
| 137 BeforeSetUp(); |
| 138 CardUnmaskPromptViewBrowserTest::SetUp(); |
| 139 } |
| 140 |
| 141 void TearDownOnMainThread() override { |
| 142 BeforeTearDownOnMainThread(); |
| 143 CardUnmaskPromptViewBrowserTest::TearDownOnMainThread(); |
| 144 } |
| 145 |
| 146 private: |
| 147 DISALLOW_COPY_AND_ASSIGN(InvokeCardUnmaskPromptViewBrowserTest); |
| 148 }; |
| 149 |
| 150 IN_PROC_BROWSER_TEST_F(InvokeCardUnmaskPromptViewBrowserTest, DISABLED_Invoke) { |
| 151 ShowUI(); |
| 152 } |
| 153 |
| 116 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { | 154 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { |
| 117 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 155 ShowUI(); |
| 118 test::GetMaskedServerCard(), | |
| 119 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 120 delegate()->GetWeakPtr()); | |
| 121 } | 156 } |
| 122 | 157 |
| 123 // TODO(bondd): bring up on Mac. | 158 // TODO(bondd): bring up on Mac. |
| 124 #if !defined(OS_MACOSX) | 159 #if !defined(OS_MACOSX) |
| 125 // Makes sure the user can close the dialog while the verification success | 160 // Makes sure the user can close the dialog while the verification success |
| 126 // message is showing. | 161 // message is showing. |
| 127 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 162 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
| 128 EarlyCloseAfterSuccess) { | 163 EarlyCloseAfterSuccess) { |
| 129 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 164 ShowUI(); |
| 130 test::GetMaskedServerCard(), | |
| 131 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 132 delegate()->GetWeakPtr()); | |
| 133 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), | 165 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), |
| 134 base::ASCIIToUTF16("10"), | 166 base::ASCIIToUTF16("10"), |
| 135 base::ASCIIToUTF16("19"), false); | 167 base::ASCIIToUTF16("19"), false); |
| 136 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); | 168 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); |
| 137 controller()->OnVerificationResult(AutofillClient::SUCCESS); | 169 controller()->OnVerificationResult(AutofillClient::SUCCESS); |
| 138 | 170 |
| 139 // Simulate the user clicking [x] before the "Success!" message disappears. | 171 // Simulate the user clicking [x] before the "Success!" message disappears. |
| 140 CardUnmaskPromptViewTester::For(controller()->view())->Close(); | 172 CardUnmaskPromptViewTester::For(controller()->view())->Close(); |
| 141 // Wait a little while; there should be no crash. | 173 // Wait a little while; there should be no crash. |
| 142 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 174 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 143 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, | 175 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, |
| 144 base::Unretained(runner_.get())), | 176 base::Unretained(runner_.get())), |
| 145 2 * controller()->GetSuccessMessageDuration()); | 177 2 * controller()->GetSuccessMessageDuration()); |
| 146 runner_->Run(); | 178 runner_->Run(); |
| 147 } | 179 } |
| 148 #endif | 180 #endif |
| 149 | 181 |
| 150 // Makes sure the tab can be closed while the dialog is showing. | 182 // Makes sure the tab can be closed while the dialog is showing. |
| 151 // https://crbug.com/484376 | 183 // https://crbug.com/484376 |
| 152 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 184 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
| 153 CloseTabWhileDialogShowing) { | 185 CloseTabWhileDialogShowing) { |
| 154 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 186 ShowUI(); |
| 155 test::GetMaskedServerCard(), | |
| 156 AutofillClient::UNMASK_FOR_AUTOFILL, | |
| 157 delegate()->GetWeakPtr()); | |
| 158 // Simulate AutofillManager (the delegate in production code) being destroyed | 187 // Simulate AutofillManager (the delegate in production code) being destroyed |
| 159 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. | 188 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. |
| 160 FreeDelegate(); | 189 FreeDelegate(); |
| 161 browser()->tab_strip_model()->GetActiveWebContents()->Close(); | 190 browser()->tab_strip_model()->GetActiveWebContents()->Close(); |
| 162 | 191 |
| 163 content::RunAllPendingInMessageLoop(); | 192 content::RunAllPendingInMessageLoop(); |
| 164 } | 193 } |
| 165 | 194 |
| 166 } // namespace | 195 } // namespace |
| 167 | 196 |
| 168 } // namespace autofill | 197 } // namespace autofill |
| OLD | NEW |