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

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

Issue 1138653003: Move card unmask interfaces and controller into the autofill component. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missing override declaration Created 5 years, 7 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
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/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/autofill/risk_util.h" 9 #include "chrome/browser/autofill/risk_util.h"
10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller_impl.h"
11 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h" 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_view_tester.h"
11 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "components/autofill/core/browser/autofill_test_utils.h" 15 #include "components/autofill/core/browser/autofill_test_utils.h"
16 #include "components/autofill/core/browser/card_unmask_delegate.h" 16 #include "components/autofill/core/browser/card_unmask_delegate.h"
17 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller_impl .h"
17 #include "components/user_prefs/user_prefs.h" 18 #include "components/user_prefs/user_prefs.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
20 21
21 namespace autofill { 22 namespace autofill {
22 23
23 namespace { 24 namespace {
24 25
25 class TestCardUnmaskDelegate : public CardUnmaskDelegate { 26 class TestCardUnmaskDelegate : public CardUnmaskDelegate {
26 public: 27 public:
(...skipping 19 matching lines...) Expand all
46 base::WeakPtrFactory<TestCardUnmaskDelegate> weak_factory_; 47 base::WeakPtrFactory<TestCardUnmaskDelegate> weak_factory_;
47 48
48 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskDelegate); 49 DISALLOW_COPY_AND_ASSIGN(TestCardUnmaskDelegate);
49 }; 50 };
50 51
51 class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl { 52 class TestCardUnmaskPromptController : public CardUnmaskPromptControllerImpl {
52 public: 53 public:
53 TestCardUnmaskPromptController( 54 TestCardUnmaskPromptController(
54 content::WebContents* contents, 55 content::WebContents* contents,
55 scoped_refptr<content::MessageLoopRunner> runner) 56 scoped_refptr<content::MessageLoopRunner> runner)
56 : CardUnmaskPromptControllerImpl(contents, 57 : CardUnmaskPromptControllerImpl(base::Bind(&LoadRiskData, 0, contents),
57 base::Bind(&LoadRiskData, 0, contents),
58 user_prefs::UserPrefs::Get(contents->GetBrowserContext()), false), 58 user_prefs::UserPrefs::Get(contents->GetBrowserContext()), false),
59 runner_(runner), 59 runner_(runner),
60 weak_factory_(this) {} 60 weak_factory_(this) {}
61 61
62 // CardUnmaskPromptControllerImpl implementation. 62 // CardUnmaskPromptControllerImpl implementation.
63 base::TimeDelta GetSuccessMessageDuration() const override { 63 base::TimeDelta GetSuccessMessageDuration() const override {
64 return base::TimeDelta::FromMilliseconds(10); 64 return base::TimeDelta::FromMilliseconds(10);
65 } 65 }
66 66
67 void LoadRiskFingerprint() override { 67 void LoadRiskFingerprint() override {
(...skipping 14 matching lines...) Expand all
82 }; 82 };
83 83
84 class CardUnmaskPromptViewBrowserTest : public InProcessBrowserTest { 84 class CardUnmaskPromptViewBrowserTest : public InProcessBrowserTest {
85 public: 85 public:
86 CardUnmaskPromptViewBrowserTest() : InProcessBrowserTest() {} 86 CardUnmaskPromptViewBrowserTest() : InProcessBrowserTest() {}
87 87
88 ~CardUnmaskPromptViewBrowserTest() override {} 88 ~CardUnmaskPromptViewBrowserTest() override {}
89 89
90 void SetUpOnMainThread() override { 90 void SetUpOnMainThread() override {
91 runner_ = new content::MessageLoopRunner; 91 runner_ = new content::MessageLoopRunner;
92 controller_.reset(new TestCardUnmaskPromptController( 92 contents_ = browser()->tab_strip_model()->GetActiveWebContents();
93 browser()->tab_strip_model()->GetActiveWebContents(), runner_)); 93 controller_.reset(new TestCardUnmaskPromptController(contents_, runner_));
94 delegate_.reset(new TestCardUnmaskDelegate()); 94 delegate_.reset(new TestCardUnmaskDelegate());
95 } 95 }
96 96
97 void FreeDelegate() { delegate_.reset(); } 97 void FreeDelegate() { delegate_.reset(); }
98 98
99 content::WebContents* contents() { return contents_; }
99 TestCardUnmaskPromptController* controller() { return controller_.get(); } 100 TestCardUnmaskPromptController* controller() { return controller_.get(); }
100 TestCardUnmaskDelegate* delegate() { return delegate_.get(); } 101 TestCardUnmaskDelegate* delegate() { return delegate_.get(); }
101 102
102 protected: 103 protected:
103 // This member must outlive the controller. 104 // This member must outlive the controller.
104 scoped_refptr<content::MessageLoopRunner> runner_; 105 scoped_refptr<content::MessageLoopRunner> runner_;
105 106
106 private: 107 private:
108 content::WebContents* contents_;
107 scoped_ptr<TestCardUnmaskPromptController> controller_; 109 scoped_ptr<TestCardUnmaskPromptController> controller_;
108 scoped_ptr<TestCardUnmaskDelegate> delegate_; 110 scoped_ptr<TestCardUnmaskDelegate> delegate_;
109 111
110 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest); 112 DISALLOW_COPY_AND_ASSIGN(CardUnmaskPromptViewBrowserTest);
111 }; 113 };
112 114
113 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) { 115 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, DisplayUI) {
114 controller()->ShowPrompt(test::GetMaskedServerCard(), 116 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()),
117 test::GetMaskedServerCard(),
115 delegate()->GetWeakPtr()); 118 delegate()->GetWeakPtr());
116 } 119 }
117 120
118 // TODO(bondd): bring up on Mac. 121 // TODO(bondd): bring up on Mac.
119 #if !defined(OS_MACOSX) 122 #if !defined(OS_MACOSX)
120 // Makes sure the user can close the dialog while the verification success 123 // Makes sure the user can close the dialog while the verification success
121 // message is showing. 124 // message is showing.
122 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, 125 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest,
123 EarlyCloseAfterSuccess) { 126 EarlyCloseAfterSuccess) {
124 controller()->ShowPrompt(test::GetMaskedServerCard(), 127 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()),
128 test::GetMaskedServerCard(),
125 delegate()->GetWeakPtr()); 129 delegate()->GetWeakPtr());
126 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"), 130 controller()->OnUnmaskResponse(base::ASCIIToUTF16("123"),
127 base::ASCIIToUTF16("10"), 131 base::ASCIIToUTF16("10"),
128 base::ASCIIToUTF16("19"), false); 132 base::ASCIIToUTF16("19"), false);
129 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc); 133 EXPECT_EQ(base::ASCIIToUTF16("123"), delegate()->response().cvc);
130 controller()->OnVerificationResult(AutofillClient::SUCCESS); 134 controller()->OnVerificationResult(AutofillClient::SUCCESS);
131 135
132 // Simulate the user clicking [x] before the "Success!" message disappears. 136 // Simulate the user clicking [x] before the "Success!" message disappears.
133 CardUnmaskPromptViewTester::For(controller()->view())->Close(); 137 CardUnmaskPromptViewTester::For(controller()->view())->Close();
134 // Wait a little while; there should be no crash. 138 // Wait a little while; there should be no crash.
135 base::MessageLoop::current()->PostDelayedTask( 139 base::MessageLoop::current()->PostDelayedTask(
136 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit, 140 FROM_HERE, base::Bind(&content::MessageLoopRunner::Quit,
137 base::Unretained(runner_.get())), 141 base::Unretained(runner_.get())),
138 2 * controller()->GetSuccessMessageDuration()); 142 2 * controller()->GetSuccessMessageDuration());
139 runner_->Run(); 143 runner_->Run();
140 } 144 }
141 #endif 145 #endif
142 146
143 // Makes sure the tab can be closed while the dialog is showing. 147 // Makes sure the tab can be closed while the dialog is showing.
144 // https://crbug.com/484376 148 // https://crbug.com/484376
145 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest, 149 IN_PROC_BROWSER_TEST_F(CardUnmaskPromptViewBrowserTest,
146 CloseTabWhileDialogShowing) { 150 CloseTabWhileDialogShowing) {
147 controller()->ShowPrompt(test::GetMaskedServerCard(), 151 controller()->ShowPrompt(CreateCardUnmaskPromptView(controller(), contents()),
152 test::GetMaskedServerCard(),
148 delegate()->GetWeakPtr()); 153 delegate()->GetWeakPtr());
149 // Simulate AutofillManager (the delegate in production code) being destroyed 154 // Simulate AutofillManager (the delegate in production code) being destroyed
150 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called. 155 // before CardUnmaskPromptViewBridge::OnConstrainedWindowClosed() is called.
151 FreeDelegate(); 156 FreeDelegate();
152 browser()->tab_strip_model()->GetActiveWebContents()->Close(); 157 browser()->tab_strip_model()->GetActiveWebContents()->Close();
153 158
154 content::RunAllPendingInMessageLoop(); 159 content::RunAllPendingInMessageLoop();
155 } 160 }
156 161
157 } // namespace 162 } // namespace
158 163
159 } // namespace autofill 164 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/card_unmask_prompt_view.h ('k') | chrome/browser/ui/autofill/chrome_autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698