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/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 class CreditCardExpiry { | |
33 EXPIRED, // Shows additional month/year controls. | |
34 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 Loading... | |
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 // InProcessBrowserTest: | |
Peter Kasting
2016/12/15 00:28:54
Nit: You don't directly subclass InProcessBrowserT
tapted
2016/12/15 06:08:21
Done.
| |
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 |
106 // TestDialogInterface: | |
107 void ShowDialog(int index) override { | |
108 ShowUI(static_cast<CreditCardExpiry>(index)); | |
Peter Kasting
2016/12/15 00:28:54
I've been trying to think of ways to simplify the
tapted
2016/12/15 06:08:22
I agree that the mapping in ShowDialog feels a bit
| |
109 } | |
110 | |
111 static std::vector<std::string> NameProvider() { | |
112 return {"Expired", "Valid"}; | |
113 } | |
114 | |
101 void ShowUI(CreditCardExpiry expired) { | 115 void ShowUI(CreditCardExpiry expired) { |
102 CardUnmaskPromptView* dialog = | 116 CardUnmaskPromptView* dialog = |
103 CreateCardUnmaskPromptView(controller(), contents()); | 117 CreateCardUnmaskPromptView(controller(), contents()); |
104 CreditCard card = (expired == CreditCardExpiry::EXPIRED) | 118 CreditCard card = (expired == CreditCardExpiry::EXPIRED) |
105 ? test::GetMaskedServerCard() | 119 ? test::GetMaskedServerCard() |
106 : test::GetMaskedServerCardAmex(); | 120 : test::GetMaskedServerCardAmex(); |
107 controller()->ShowPrompt(dialog, card, AutofillClient::UNMASK_FOR_AUTOFILL, | 121 controller()->ShowPrompt(dialog, card, AutofillClient::UNMASK_FOR_AUTOFILL, |
108 delegate()->GetWeakPtr()); | 122 delegate()->GetWeakPtr()); |
109 } | 123 } |
110 | 124 |
111 void FreeDelegate() { delegate_.reset(); } | 125 void FreeDelegate() { delegate_.reset(); } |
112 | 126 |
113 content::WebContents* contents() { return contents_; } | 127 content::WebContents* contents() { return contents_; } |
114 TestCardUnmaskPromptController* controller() { return controller_.get(); } | 128 TestCardUnmaskPromptController* controller() { return controller_.get(); } |
115 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } | 129 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } |
116 | 130 |
117 protected: | 131 protected: |
118 // This member must outlive the controller. | 132 // This member must outlive the controller. |
119 scoped_refptr<content::MessageLoopRunner> runner_; | 133 scoped_refptr<content::MessageLoopRunner> runner_; |
120 | 134 |
121 private: | 135 private: |
122 content::WebContents* contents_; | 136 content::WebContents* contents_; |
123 std::unique_ptr<TestCardUnmaskPromptController> controller_; | 137 std::unique_ptr<TestCardUnmaskPromptController> controller_; |
124 std::unique_ptr<TestCardUnmaskDelegate> delegate_; | 138 std::unique_ptr<TestCardUnmaskDelegate> delegate_; |
125 | 139 |
126 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); | 140 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); |
127 }; | 141 }; |
128 | 142 |
129 // Permanently disabled test used to invoke the UI for the card unmask prompt | 143 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 | 144 |
144 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { | 145 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { |
145 ShowUI(CreditCardExpiry::EXPIRED); | 146 ShowUI(CreditCardExpiry::EXPIRED); |
146 } | 147 } |
147 | 148 |
148 // TODO(bondd): bring up on Mac. | 149 // TODO(bondd): bring up on Mac. |
149 #if !defined(OS_MACOSX) | 150 #if !defined(OS_MACOSX) |
150 // Makes sure the user can close the dialog while the verification success | 151 // Makes sure the user can close the dialog while the verification success |
151 // message is showing. | 152 // message is showing. |
152 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, | 153 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, |
(...skipping 25 matching lines...) Expand all Loading... | |
178 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. | 179 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. |
179 FreeDelegate(); | 180 FreeDelegate(); |
180 browser()->tab_strip_model()->GetActiveWebContents()->Close(); | 181 browser()->tab_strip_model()->GetActiveWebContents()->Close(); |
181 | 182 |
182 content::RunAllPendingInMessageLoop(); | 183 content::RunAllPendingInMessageLoop(); |
183 } | 184 } |
184 | 185 |
185 } // namespace | 186 } // namespace |
186 | 187 |
187 } // namespace autofill | 188 } // namespace autofill |
OLD | NEW |