| 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/message_loop/message_loop.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/thread_task_runner_handle.h" |
| 9 #include "chrome/browser/autofill/risk_util.h" | 11 #include "chrome/browser/autofill/risk_util.h" |
| 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h" | 12 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h" |
| 11 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" | 13 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "components/autofill/core/browser/autofill_test_utils.h" | 17 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 16 #include "components/autofill/core/browser/card_unmask_delegate.h" | 18 #include "components/autofill/core/browser/card_unmask_delegate.h" |
| 17 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" | 19 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl
.h" |
| 18 #include "components/user_prefs/user_prefs.h" | 20 #include "components/user_prefs/user_prefs.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 delegate()->GetWeakPtr()); | 131 delegate()->GetWeakPtr()); |
| 130 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), | 132 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), |
| 131 base::ASCIIToUTF16("10"), | 133 base::ASCIIToUTF16("10"), |
| 132 base::ASCIIToUTF16("19"), false); | 134 base::ASCIIToUTF16("19"), false); |
| 133 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); | 135 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); |
| 134 controller()->OnVerificationResult(AutofillClient::SUCCESS); | 136 controller()->OnVerificationResult(AutofillClient::SUCCESS); |
| 135 | 137 |
| 136 // Simulate the user clicking [x] before the "Success!" message disappears. | 138 // Simulate the user clicking [x] before the "Success!" message disappears. |
| 137 CardUnmaskPromptViewTester::For(controller()->view())->Close(); | 139 CardUnmaskPromptViewTester::For(controller()->view())->Close(); |
| 138 // Wait a little while; there should be no crash. | 140 // Wait a little while; there should be no crash. |
| 139 base::MessageLoop::current()->PostDelayedTask( | 141 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 140 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, | 142 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, |
| 141 base::Unretained(runner_.get())), | 143 base::Unretained(runner_.get())), |
| 142 2 * controller()->GetSuccessMessageDuration()); | 144 2 * controller()->GetSuccessMessageDuration()); |
| 143 runner_->Run(); | 145 runner_->Run(); |
| 144 } | 146 } |
| 145 #endif | 147 #endif |
| 146 | 148 |
| 147 // Makes sure the tab can be closed while the dialog is showing. | 149 // Makes sure the tab can be closed while the dialog is showing. |
| 148 // https://crbug.com/484376 | 150 // https://crbug.com/484376 |
| 149 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 151 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
| 150 CloseTabWhileDialogShowing) { | 152 CloseTabWhileDialogShowing) { |
| 151 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), | 153 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), |
| 152 test::GetMaskedServerCard(), | 154 test::GetMaskedServerCard(), |
| 153 delegate()->GetWeakPtr()); | 155 delegate()->GetWeakPtr()); |
| 154 // Simulate AutofillManager (the delegate in production code) being destroyed | 156 // Simulate AutofillManager (the delegate in production code) being destroyed |
| 155 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. | 157 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. |
| 156 FreeDelegate(); | 158 FreeDelegate(); |
| 157 browser()->tab_strip_model()->GetActiveWebContents()->Close(); | 159 browser()->tab_strip_model()->GetActiveWebContents()->Close(); |
| 158 | 160 |
| 159 content::RunAllPendingInMessageLoop(); | 161 content::RunAllPendingInMessageLoop(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 } // namespace | 164 } // namespace |
| 163 | 165 |
| 164 } // namespace autofill | 166 } // namespace autofill |
| OLD | NEW |