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

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

Issue 2382963002: Views: Add two disabled tests for invoking the CC unmask prompt dialog. (Closed)
Patch Set: Rebase? Created 4 years, 2 months 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
« no previous file with comments | « no previous file | ui/base/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
26
27 namespace {
28
29 enum CreditCardExpiry { EXPIRED, VALID };
Ilya Sherman 2016/10/20 01:13:35 nit: Please use enum class, since that seems to be
Patti Lor 2016/10/20 04:56:02 Oops, thanks for catching these in time! Fixed.
30
31 } // namespace
Ilya Sherman 2016/10/20 01:13:35 nit: There's already an anonymous namespace below
Patti Lor 2016/10/20 04:56:02 Done.
25 32
26 namespace autofill { 33 namespace autofill {
27 34
28 namespace { 35 namespace {
29 36
30 class TestCardUnmaskDelegate : public CardUnmaskDelegate { 37 class TestCardUnmaskDelegate : public CardUnmaskDelegate {
31 public: 38 public:
32 TestCardUnmaskDelegate() : weak_factory_(this) {} 39 TestCardUnmaskDelegate() : weak_factory_(this) {}
33 40
34 virtual ~TestCardUnmaskDelegate() {} 41 virtual ~TestCardUnmaskDelegate() {}
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 95
89 ~CardUnmaskPromptViewBrowserTest() override {} 96 ~CardUnmaskPromptViewBrowserTest() override {}
90 97
91 void SetUpOnMainThread() override { 98 void SetUpOnMainThread() override {
92 runner_ = new content::MessageLoopRunner; 99 runner_ = new content::MessageLoopRunner;
93 contents_ = browser()->tab_strip_model()->GetActiveWebContents(); 100 contents_ = browser()->tab_strip_model()->GetActiveWebContents();
94 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_)); 101 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_));
95 delegate_.reset(new TestCardUnmaskDelegate()); 102 delegate_.reset(new TestCardUnmaskDelegate());
96 } 103 }
97 104
105 void ShowUI(CreditCardExpiry expired) {
106 CardUnmaskPromptView* dialog =
107 CreateCardUnmaskPromptView(controller(), contents());
108 CreditCard card = (expired == CreditCardExpiry::EXPIRED)
109 ? test::GetMaskedServerCard()
110 : test::GetMaskedServerCardAmex();
111 controller()->ShowPrompt(dialog, card, AutofillClient::UNMASK_FOR_AUTOFILL,
112 delegate()->GetWeakPtr());
113 }
114
98 void FreeDelegate() { delegate_.reset(); } 115 void FreeDelegate() { delegate_.reset(); }
99 116
100 content::WebContents* contents() { return contents_; } 117 content::WebContents* contents() { return contents_; }
101 TestCardUnmaskPromptController* controller() { return controller_.get(); } 118 TestCardUnmaskPromptController* controller() { return controller_.get(); }
102 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } 119 TestCardUnmaskDelegate* delegate() { return delegate_.get(); }
103 120
104 protected: 121 protected:
105 // This member must outlive the controller. 122 // This member must outlive the controller.
106 scoped_refptr<content::MessageLoopRunner> runner_; 123 scoped_refptr<content::MessageLoopRunner> runner_;
107 124
108 private: 125 private:
109 content::WebContents* contents_; 126 content::WebContents* contents_;
110 std::unique_ptr<TestCardUnmaskPromptController> controller_; 127 std::unique_ptr<TestCardUnmaskPromptController> controller_;
111 std::unique_ptr<TestCardUnmaskDelegate> delegate_; 128 std::unique_ptr<TestCardUnmaskDelegate> delegate_;
112 129
113 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); 130 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest);
114 }; 131 };
115 132
133 // Permanently disabled test used to invoke the UI for the card unmask prompt
134 // with an expired credit card, which shows additional month/year controls.
135 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest,
136 DISABLED_InvokeExpired) {
137 ShowUI(CreditCardExpiry::EXPIRED);
138 ::test::RunTestInteractively();
139 }
140
141 // Permanently disabled test used to invoke the UI for the card unmask prompt
142 // with a valid credit card, which only shows the CCV Textfield.
143 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DISABLED_InvokeValid) {
144 ShowUI(CreditCardExpiry::VALID);
145 ::test::RunTestInteractively();
146 }
147
116 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { 148 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) {
117 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), 149 ShowUI(CreditCardExpiry::EXPIRED);
118 test::GetMaskedServerCard(),
119 AutofillClient::UNMASK_FOR_AUTOFILL,
120 delegate()->GetWeakPtr());
121 } 150 }
122 151
123 // TODO(bondd): bring up on Mac. 152 // TODO(bondd): bring up on Mac.
124 #if !defined(OS_MACOSX) 153 #if !defined(OS_MACOSX)
125 // Makes sure the user can close the dialog while the verification success 154 // Makes sure the user can close the dialog while the verification success
126 // message is showing. 155 // message is showing.
127 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, 156 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest,
128 EarlyCloseAfterSuccess) { 157 EarlyCloseAfterSuccess) {
129 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), 158 ShowUI(CreditCardExpiry::EXPIRED);
130 test::GetMaskedServerCard(),
131 AutofillClient::UNMASK_FOR_AUTOFILL,
132 delegate()->GetWeakPtr());
133 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), 159 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"),
134 base::ASCIIToUTF16("10"), 160 base::ASCIIToUTF16("10"),
135 base::ASCIIToUTF16("19"), false); 161 base::ASCIIToUTF16("19"), false);
136 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); 162 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc);
137 controller()->OnVerificationResult(AutofillClient::SUCCESS); 163 controller()->OnVerificationResult(AutofillClient::SUCCESS);
138 164
139 // Simulate the user clicking [x] before the "Success!" message disappears. 165 // Simulate the user clicking [x] before the "Success!" message disappears.
140 CardUnmaskPromptViewTester::For(controller()->view())->Close(); 166 CardUnmaskPromptViewTester::For(controller()->view())->Close();
141 // Wait a little while; there should be no crash. 167 // Wait a little while; there should be no crash.
142 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 168 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
143 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, 169 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit,
144 base::Unretained(runner_.get())), 170 base::Unretained(runner_.get())),
145 2 * controller()->GetSuccessMessageDuration()); 171 2 * controller()->GetSuccessMessageDuration());
146 runner_->Run(); 172 runner_->Run();
147 } 173 }
148 #endif 174 #endif
149 175
150 // Makes sure the tab can be closed while the dialog is showing. 176 // Makes sure the tab can be closed while the dialog is showing.
151 // https://crbug.com/484376 177 // https://crbug.com/484376
152 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, 178 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest,
153 CloseTabWhileDialogShowing) { 179 CloseTabWhileDialogShowing) {
154 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()), 180 ShowUI(CreditCardExpiry::EXPIRED);
155 test::GetMaskedServerCard(),
156 AutofillClient::UNMASK_FOR_AUTOFILL,
157 delegate()->GetWeakPtr());
158 // Simulate AutofillManager (the delegate in production code) being destroyed 181 // Simulate AutofillManager (the delegate in production code) being destroyed
159 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. 182 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called.
160 FreeDelegate(); 183 FreeDelegate();
161 browser()->tab_strip_model()->GetActiveWebContents()->Close(); 184 browser()->tab_strip_model()->GetActiveWebContents()->Close();
162 185
163 content::RunAllPendingInMessageLoop(); 186 content::RunAllPendingInMessageLoop();
164 } 187 }
165 188
166 } // namespace 189 } // namespace
167 190
168 } // namespace autofill 191 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | ui/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698