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

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: Addressing code review comments 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) {
Evan Stade 2017/04/10 18:32:09 you can give this a default value
Jared Saul 2017/04/11 00:53:06 Done.
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) {
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 22 matching lines...) Expand all
127 }; 130 };
128 131
129 static void SaveCardCallback() {} 132 static void SaveCardCallback() {}
130 133
131 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImplTest); 134 DISALLOW_COPY_AND_ASSIGN(SaveCardBubbleControllerImplTest);
132 }; 135 };
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(false /* should_cvc_be_requested */);
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(false /* should_cvc_be_requested */);
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(false /* should_cvc_be_requested */);
170 186
171 EXPECT_THAT( 187 EXPECT_THAT(
172 histogram_tester.GetAllSamples( 188 histogram_tester.GetAllSamples(
189 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"),
190 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
191 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1)));
192 }
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(
173 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), 201 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"),
174 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), 202 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
175 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1))); 203 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1)));
176 } 204 }
177 205
178 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_Reshows_ShowBubble) { 206 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_Reshows_ShowBubble) {
179 ShowUploadBubble(); 207 ShowUploadBubble(false /* should_cvc_be_requested */);
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),
188 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1))); 216 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1)));
189 } 217 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // Fake-navigate after bubble has been visible for a long time. 321 // Fake-navigate after bubble has been visible for a long time.
294 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); 322 controller()->set_elapsed(base::TimeDelta::FromMinutes(1));
295 controller()->SimulateNavigation(); 323 controller()->SimulateNavigation();
296 324
297 histogram_tester.ExpectUniqueSample( 325 histogram_tester.ExpectUniqueSample(
298 "Autofill.SaveCreditCardPrompt.Local.Reshows", 326 "Autofill.SaveCreditCardPrompt.Local.Reshows",
299 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, 1); 327 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, 1);
300 } 328 }
301 329
302 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_FirstShow_LearnMore) { 330 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_FirstShow_LearnMore) {
303 ShowUploadBubble(); 331 ShowUploadBubble(false /* should_cvc_be_requested */);
304 332
305 base::HistogramTester histogram_tester; 333 base::HistogramTester histogram_tester;
306 controller()->OnLearnMoreClicked(); 334 controller()->OnLearnMoreClicked();
307 335
308 histogram_tester.ExpectUniqueSample( 336 histogram_tester.ExpectUniqueSample(
309 "Autofill.SaveCreditCardPrompt.Upload.FirstShow", 337 "Autofill.SaveCreditCardPrompt.Upload.FirstShow",
310 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, 1); 338 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, 1);
311 } 339 }
312 340
313 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_Reshows_LearnMore) { 341 TEST_F(SaveCardBubbleControllerImplTest, Metrics_Upload_Reshows_LearnMore) {
314 ShowUploadBubble(); 342 ShowUploadBubble(false /* should_cvc_be_requested */);
315 CloseAndReshowBubble(); 343 CloseAndReshowBubble();
316 344
317 base::HistogramTester histogram_tester; 345 base::HistogramTester histogram_tester;
318 controller()->OnLearnMoreClicked(); 346 controller()->OnLearnMoreClicked();
319 347
320 histogram_tester.ExpectUniqueSample( 348 histogram_tester.ExpectUniqueSample(
321 "Autofill.SaveCreditCardPrompt.Upload.Reshows", 349 "Autofill.SaveCreditCardPrompt.Upload.Reshows",
322 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, 1); 350 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, 1);
323 } 351 }
324 352
325 TEST_F(SaveCardBubbleControllerImplTest, 353 TEST_F(SaveCardBubbleControllerImplTest,
326 Metrics_Upload_FirstShow_LegalMessageLink) { 354 Metrics_Upload_FirstShow_LegalMessageLink) {
327 ShowUploadBubble(); 355 ShowUploadBubble(false /* should_cvc_be_requested */);
328 356
329 base::HistogramTester histogram_tester; 357 base::HistogramTester histogram_tester;
330 controller()->OnLegalMessageLinkClicked(GURL("http://www.example.com")); 358 controller()->OnLegalMessageLinkClicked(GURL("http://www.example.com"));
331 359
332 histogram_tester.ExpectUniqueSample( 360 histogram_tester.ExpectUniqueSample(
333 "Autofill.SaveCreditCardPrompt.Upload.FirstShow", 361 "Autofill.SaveCreditCardPrompt.Upload.FirstShow",
334 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, 1); 362 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, 1);
335 } 363 }
336 364
337 TEST_F(SaveCardBubbleControllerImplTest, 365 TEST_F(SaveCardBubbleControllerImplTest,
338 Metrics_Upload_Reshows_LegalMessageLink) { 366 Metrics_Upload_Reshows_LegalMessageLink) {
339 ShowUploadBubble(); 367 ShowUploadBubble(false /* should_cvc_be_requested */);
340 CloseAndReshowBubble(); 368 CloseAndReshowBubble();
341 369
342 base::HistogramTester histogram_tester; 370 base::HistogramTester histogram_tester;
343 controller()->OnLegalMessageLinkClicked(GURL("http://www.example.com")); 371 controller()->OnLegalMessageLinkClicked(GURL("http://www.example.com"));
344 372
345 histogram_tester.ExpectUniqueSample( 373 histogram_tester.ExpectUniqueSample(
346 "Autofill.SaveCreditCardPrompt.Upload.Reshows", 374 "Autofill.SaveCreditCardPrompt.Upload.Reshows",
347 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, 1); 375 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, 1);
348 } 376 }
349 377
350 // SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE is only possible for 378 // SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE is only possible for
351 // Upload.FirstShow. 379 // Upload.FirstShow.
352 TEST_F(SaveCardBubbleControllerImplTest, 380 TEST_F(SaveCardBubbleControllerImplTest,
353 Metrics_Upload_FirstShow_InvalidLegalMessage) { 381 Metrics_Upload_FirstShow_InvalidLegalMessage) {
354 base::HistogramTester histogram_tester; 382 base::HistogramTester histogram_tester;
355 383
356 // Legal message is invalid because it's missing the url. 384 // Legal message is invalid because it's missing the url.
357 SetLegalMessage( 385 SetLegalMessage(
358 "{" 386 "{"
359 " \"line\" : [ {" 387 " \"line\" : [ {"
360 " \"template\": \"Panda {0}.\"," 388 " \"template\": \"Panda {0}.\","
361 " \"template_parameter\": [ {" 389 " \"template_parameter\": [ {"
362 " \"display_text\": \"bear\"" 390 " \"display_text\": \"bear\""
363 " } ]" 391 " } ]"
364 " } ]" 392 " } ]"
365 "}"); 393 "}",
394 false /* should_cvc_be_requested */);
366 395
367 EXPECT_THAT( 396 EXPECT_THAT(
368 histogram_tester.GetAllSamples( 397 histogram_tester.GetAllSamples(
369 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), 398 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"),
370 ElementsAre( 399 ElementsAre(
371 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), 400 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1),
372 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, 401 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE,
373 1))); 402 1)));
374 } 403 }
375 404
376 } // namespace autofill 405 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698