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

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

Issue 2789843004: [Payments] Upload card UI now has a CVC prompt (Closed)
Patch Set: Address code review comment Created 3 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" 5 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 BrowserWithTestWindowTest::SetUp(); 62 BrowserWithTestWindowTest::SetUp();
63 AddTab(browser(), GURL("about:blank")); 63 AddTab(browser(), GURL("about:blank"));
64 TestSaveCardBubbleControllerImpl::CreateForTesting( 64 TestSaveCardBubbleControllerImpl::CreateForTesting(
65 browser()->tab_strip_model()->GetActiveWebContents()); 65 browser()->tab_strip_model()->GetActiveWebContents());
66 } 66 }
67 67
68 BrowserWindow* CreateBrowserWindow() override { 68 BrowserWindow* CreateBrowserWindow() override {
69 return new SaveCardBubbleTestBrowserWindow(); 69 return new SaveCardBubbleTestBrowserWindow();
70 } 70 }
71 71
72 void SetLegalMessage(const std::string& message_json) { 72 void SetLegalMessage(const std::string& message_json,
73 bool should_cvc_be_requested = false) {
73 std::unique_ptr<base::Value> value(base::JSONReader::Read(message_json)); 74 std::unique_ptr<base::Value> value(base::JSONReader::Read(message_json));
74 ASSERT_TRUE(value); 75 ASSERT_TRUE(value);
75 base::DictionaryValue* dictionary; 76 base::DictionaryValue* dictionary;
76 ASSERT_TRUE(value->GetAsDictionary(&dictionary)); 77 ASSERT_TRUE(value->GetAsDictionary(&dictionary));
77 std::unique_ptr<base::DictionaryValue> legal_message = 78 std::unique_ptr<base::DictionaryValue> legal_message =
78 dictionary->CreateDeepCopy(); 79 dictionary->CreateDeepCopy();
79 controller()->ShowBubbleForUpload(CreditCard(), std::move(legal_message), 80 controller()->ShowBubbleForUpload(CreditCard(), std::move(legal_message),
81 should_cvc_be_requested,
80 base::Bind(&SaveCardCallback)); 82 base::Bind(&SaveCardCallback));
81 } 83 }
82 84
83 void ShowLocalBubble() { 85 void ShowLocalBubble() {
84 controller()->ShowBubbleForLocalSave(CreditCard(), 86 controller()->ShowBubbleForLocalSave(CreditCard(),
85 base::Bind(&SaveCardCallback)); 87 base::Bind(&SaveCardCallback));
86 } 88 }
87 89
88 void ShowUploadBubble() { 90 void ShowUploadBubble(bool should_cvc_be_requested = false) {
89 SetLegalMessage( 91 SetLegalMessage(
90 "{" 92 "{"
91 " \"line\" : [ {" 93 " \"line\" : [ {"
92 " \"template\": \"This is the entire message.\"" 94 " \"template\": \"This is the entire message.\""
93 " } ]" 95 " } ]"
94 "}"); 96 "}",
97 should_cvc_be_requested);
95 } 98 }
96 99
97 void CloseAndReshowBubble() { 100 void CloseAndReshowBubble() {
98 controller()->OnBubbleClosed(); 101 controller()->OnBubbleClosed();
99 controller()->ReshowBubble(); 102 controller()->ReshowBubble();
100 } 103 }
101 104
102 protected: 105 protected:
103 TestSaveCardBubbleControllerImpl* controller() { 106 TestSaveCardBubbleControllerImpl* controller() {
104 return static_cast<TestSaveCardBubbleControllerImpl*>( 107 return static_cast<TestSaveCardBubbleControllerImpl*>(
(...skipping 28 matching lines...) Expand all
133 136
134 // Tests that the legal message lines vector is empty when doing a local save so 137 // Tests that the legal message lines vector is empty when doing a local save so
135 // that no legal messages will be shown to the user in that case. 138 // that no legal messages will be shown to the user in that case.
136 TEST_F(SaveCardBubbleControllerImplTest, LegalMessageLinesEmptyOnLocalSave) { 139 TEST_F(SaveCardBubbleControllerImplTest, LegalMessageLinesEmptyOnLocalSave) {
137 ShowUploadBubble(); 140 ShowUploadBubble();
138 controller()->OnBubbleClosed(); 141 controller()->OnBubbleClosed();
139 ShowLocalBubble(); 142 ShowLocalBubble();
140 EXPECT_TRUE(controller()->GetLegalMessageLines().empty()); 143 EXPECT_TRUE(controller()->GetLegalMessageLines().empty());
141 } 144 }
142 145
146 TEST_F(SaveCardBubbleControllerImplTest,
147 PropagateShouldRequestCvcFromUserWhenFalse) {
148 ShowUploadBubble();
149 EXPECT_FALSE(controller()->ShouldRequestCvcFromUser());
150 }
151
152 TEST_F(SaveCardBubbleControllerImplTest,
153 PropagateShouldRequestCvcFromUserWhenTrue) {
154 ShowUploadBubble(true /* should_cvc_be_requested */);
155 EXPECT_TRUE(controller()->ShouldRequestCvcFromUser());
156 }
157
143 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Local_FirstShow_ShowBubble) { 158 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Local_FirstShow_ShowBubble) {
144 base::HistogramTester histogram_tester; 159 base::HistogramTester histogram_tester;
145 ShowLocalBubble(); 160 ShowLocalBubble();
146 161
147 EXPECT_THAT( 162 EXPECT_THAT(
148 histogram_tester.GetAllSamples( 163 histogram_tester.GetAllSamples(
149 "Autofill.SaveCreditCardPrompt.Local.FirstShow"), 164 "Autofill.SaveCreditCardPrompt.Local.FirstShow"),
150 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), 165 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
151 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1))); 166 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1)));
152 } 167 }
153 168
154 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Local_Reshows_ShowBubble) { 169 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Local_Reshows_ShowBubble) {
155 ShowLocalBubble(); 170 ShowLocalBubble();
156 171
157 base::HistogramTester histogram_tester; 172 base::HistogramTester histogram_tester;
158 CloseAndReshowBubble(); 173 CloseAndReshowBubble();
159 174
160 EXPECT_THAT( 175 EXPECT_THAT(
161 histogram_tester.GetAllSamples( 176 histogram_tester.GetAllSamples(
162 "Autofill.SaveCreditCardPrompt.Local.Reshows"), 177 "Autofill.SaveCreditCardPrompt.Local.Reshows"),
163 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), 178 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
164 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1))); 179 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1)));
165 } 180 }
166 181
167 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_FirstShow_ShowBubble) { 182 TEST_F(SaveCardBubbleControllerImplTest,
183 Metrics_Upload_FirstShow_ShowBubble_NotRequestCvc) {
168 base::HistogramTester histogram_tester; 184 base::HistogramTester histogram_tester;
169 ShowUploadBubble(); 185 ShowUploadBubble();
170 186
171 EXPECT_THAT( 187 EXPECT_THAT(
172 histogram_tester.GetAllSamples( 188 histogram_tester.GetAllSamples(
173 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), 189 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"),
174 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), 190 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
175 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1))); 191 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1)));
176 } 192 }
177 193
194 TEST_F(SaveCardBubbleControllerImplTest,
195 Metrics_Upload_FirstShow_ShowBubble_RequestCvc) {
196 base::HistogramTester histogram_tester;
197 ShowUploadBubble(true /* should_cvc_be_requested */);
198
199 EXPECT_THAT(
200 histogram_tester.GetAllSamples(
201 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"),
202 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
203 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1)));
204 }
205
178 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_Reshows_ShowBubble) { 206 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_Reshows_ShowBubble) {
179 ShowUploadBubble(); 207 ShowUploadBubble();
180 208
181 base::HistogramTester histogram_tester; 209 base::HistogramTester histogram_tester;
182 CloseAndReshowBubble(); 210 CloseAndReshowBubble();
183 211
184 EXPECT_THAT( 212 EXPECT_THAT(
185 histogram_tester.GetAllSamples( 213 histogram_tester.GetAllSamples(
186 "Autofill.SaveCreditCardPrompt.Upload.Reshows"), 214 "Autofill.SaveCreditCardPrompt.Upload.Reshows"),
187 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), 215 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 EXPECT_THAT( 395 EXPECT_THAT(
368 histogram_tester.GetAllSamples( 396 histogram_tester.GetAllSamples(
369 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), 397 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"),
370 ElementsAre( 398 ElementsAre(
371 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), 399 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
372 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, 400 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE,
373 1))); 401 1)));
374 } 402 }
375 403
376 } // namespace autofill 404 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698