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

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

Issue 2532793002: Add a TestBrowserDialog helper class for testing browser dialogs in a consistent way. (Closed)
Patch Set: constexpr const it is Created 4 years 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
OLDNEW
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/browser/ui/test/test_browser_dialog.h"
17 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
18 #include "components/autofill/core/browser/autofill_test_utils.h" 19 #include "components/autofill/core/browser/autofill_test_utils.h"
19 #include "components/autofill/core/browser/card_unmask_delegate.h" 20 #include "components/autofill/core/browser/card_unmask_delegate.h"
20 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl .h" 21 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl .h"
21 #include "components/user_prefs/user_prefs.h" 22 #include "components/user_prefs/user_prefs.h"
22 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
24 #include "content/public/test/test_utils.h" 25 #include "content/public/test/test_utils.h"
25 #include "ui/base/test/user_interactive_test_case.h"
26 26
27 namespace autofill { 27 namespace autofill {
28 28
29 namespace { 29 namespace {
30 30
31 enum class CreditCardExpiry : uint8_t { EXPIRED, VALID }; 31 // Forms of the dialog that can be invoked.
32 enum {
33 CARD_EXPIRY_EXPIRED, // Shows additional month/year controls.
34 CARD_EXPIRY_VALID, // Shows only the CCV Textfield.
35 };
32 36
33 class TestCardUnmaskDelegate : public CardUnmaskDelegate { 37 class TestCardUnmaskDelegate : public CardUnmaskDelegate {
34 public: 38 public:
35 TestCardUnmaskDelegate() : weak_factory_(this) {} 39 TestCardUnmaskDelegate() : weak_factory_(this) {}
36 40
37 virtual ~TestCardUnmaskDelegate() {} 41 virtual ~TestCardUnmaskDelegate() {}
38 42
39 // CardUnmaskDelegate implementation. 43 // CardUnmaskDelegate implementation.
40 void OnUnmaskResponse(const UnmaskResponse& response) override { 44 void OnUnmaskResponse(const UnmaskResponse& response) override {
41 response_ = response; 45 response_ = response;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 82
79 using CardUnmaskPromptControllerImpl::view; 83 using CardUnmaskPromptControllerImpl::view;
80 84
81 private: 85 private:
82 scoped_refptr<content::MessageLoopRunner> runner_; 86 scoped_refptr<content::MessageLoopRunner> runner_;
83 base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_; 87 base::WeakPtrFactory<TestCardUnmaskPromptController> weak_factory_;
84 88
85 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController); 89 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskPromptController);
86 }; 90 };
87 91
88 class CardUnmaskPromptViewBrowserTest : public InProcessBrowserTest { 92 class CardUnmaskPromptViewBrowserTest : public DialogBrowserTest {
89 public: 93 public:
90 CardUnmaskPromptViewBrowserTest() : InProcessBrowserTest() {} 94 CardUnmaskPromptViewBrowserTest() {}
91 95
92 ~CardUnmaskPromptViewBrowserTest() override {} 96 ~CardUnmaskPromptViewBrowserTest() override {}
93 97
98 // DialogBrowserTest:
94 void SetUpOnMainThread() override { 99 void SetUpOnMainThread() override {
95 runner_ = new content::MessageLoopRunner; 100 runner_ = new content::MessageLoopRunner;
96 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); 101 contents_ = browser()->tab_strip_model()->GetActiveWebContents();
97 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); 102 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_));
98 delegate_.reset(new TestCardUnmaskDelegate()); 103 delegate_.reset(new TestCardUnmaskDelegate());
99 } 104 }
100 105
101 void ShowUI(CreditCardExpiry expired) { 106 void ShowDialog(int index) override {
102 CardUnmaskPromptView* dialog = 107 CardUnmaskPromptView* dialog =
103 CreateCardUnmaskPromptView(controller(), contents()); 108 CreateCardUnmaskPromptView(controller(), contents());
104 CreditCard card = (expired == CreditCardExpiry::EXPIRED) 109 CreditCard card = (index == CARD_EXPIRY_EXPIRED)
105 ? test::GetMaskedServerCard() 110 ? test::GetMaskedServerCard()
106 : test::GetMaskedServerCardAmex(); 111 : test::GetMaskedServerCardAmex();
107 controller()->ShowPrompt(dialog, card, AutofillClient::UNMASK_FOR_AUTOFILL, 112 controller()->ShowPrompt(dialog, card, AutofillClient::UNMASK_FOR_AUTOFILL,
108 delegate()->GetWeakPtr()); 113 delegate()->GetWeakPtr());
109 } 114 }
110 115
116 static std::vector<std::string> NameProvider() {
117 return {"Expired", "Valid"};
118 }
119
111 void FreeDelegate() { delegate_.reset(); } 120 void FreeDelegate() { delegate_.reset(); }
112 121
113 content::WebContents* contents() { return contents_; } 122 content::WebContents* contents() { return contents_; }
114 TestCardUnmaskPromptController* controller() { return controller_.get(); } 123 TestCardUnmaskPromptController* controller() { return controller_.get(); }
115 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } 124 TestCardUnmaskDelegate* delegate() { return delegate_.get(); }
116 125
117 protected: 126 protected:
118 // This member must outlive the controller. 127 // This member must outlive the controller.
119 scoped_refptr<content::MessageLoopRunner> runner_; 128 scoped_refptr<content::MessageLoopRunner> runner_;
120 129
121 private: 130 private:
122 content::WebContents* contents_; 131 content::WebContents* contents_;
123 std::unique_ptr<TestCardUnmaskPromptController> controller_; 132 std::unique_ptr<TestCardUnmaskPromptController> controller_;
124 std::unique_ptr<TestCardUnmaskDelegate> delegate_; 133 std::unique_ptr<TestCardUnmaskDelegate> delegate_;
125 134
126 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); 135 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest);
127 }; 136 };
128 137
129 // Permanently disabled test used to invoke the UI for the card unmask prompt 138 TEST_BROWSER_DIALOG(CardUnmaskPromptViewBrowserTest);
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 139
144 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { 140 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) {
145 ShowUI(CreditCardExpiry::EXPIRED); 141 ShowDialog(CARD_EXPIRY_EXPIRED);
146 } 142 }
147 143
148 // TODO(bondd): bring up on Mac. 144 // TODO(bondd): bring up on Mac.
149 #if !defined(OS_MACOSX) 145 #if !defined(OS_MACOSX)
150 // Makes sure the user can close the dialog while the verification success 146 // Makes sure the user can close the dialog while the verification success
151 // message is showing. 147 // message is showing.
152 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, 148 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest,
153 EarlyCloseAfterSuccess) { 149 EarlyCloseAfterSuccess) {
154 ShowUI(CreditCardExpiry::EXPIRED); 150 ShowDialog(CARD_EXPIRY_EXPIRED);
155 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), 151 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"),
156 base::ASCIIToUTF16("10"), 152 base::ASCIIToUTF16("10"),
157 base::ASCIIToUTF16("19"), false); 153 base::ASCIIToUTF16("19"), false);
158 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); 154 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc);
159 controller()->OnVerificationResult(AutofillClient::SUCCESS); 155 controller()->OnVerificationResult(AutofillClient::SUCCESS);
160 156
161 // Simulate the user clicking [x] before the "Success!" message disappears. 157 // Simulate the user clicking [x] before the "Success!" message disappears.
162 CardUnmaskPromptViewTester::For(controller()->view())->Close(); 158 CardUnmaskPromptViewTester::For(controller()->view())->Close();
163 // Wait a little while; there should be no crash. 159 // Wait a little while; there should be no crash.
164 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 160 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
165 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, 161 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit,
166 base::Unretained(runner_.get())), 162 base::Unretained(runner_.get())),
167 2 * controller()->GetSuccessMessageDuration()); 163 2 * controller()->GetSuccessMessageDuration());
168 runner_->Run(); 164 runner_->Run();
169 } 165 }
170 #endif 166 #endif
171 167
172 // Makes sure the tab can be closed while the dialog is showing. 168 // Makes sure the tab can be closed while the dialog is showing.
173 // https://crbug.com/484376 169 // https://crbug.com/484376
174 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, 170 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest,
175 CloseTabWhileDialogShowing) { 171 CloseTabWhileDialogShowing) {
176 ShowUI(CreditCardExpiry::EXPIRED); 172 ShowDialog(CARD_EXPIRY_EXPIRED);
177 // Simulate AutofillManager (the delegate in production code) being destroyed 173 // Simulate AutofillManager (the delegate in production code) being destroyed
178 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. 174 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called.
179 FreeDelegate(); 175 FreeDelegate();
180 browser()->tab_strip_model()->GetActiveWebContents()->Close(); 176 browser()->tab_strip_model()->GetActiveWebContents()->Close();
181 177
182 content::RunAllPendingInMessageLoop(); 178 content::RunAllPendingInMessageLoop();
183 } 179 }
184 180
185 } // namespace 181 } // namespace
186 182
187 } // namespace autofill 183 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698