OLD | NEW |
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" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" | 15 #include "chrome/browser/ui/autofill/save_card_bubble_view.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/browser_with_test_window_test.h" | 17 #include "chrome/test/base/browser_with_test_window_test.h" |
18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
19 #include "components/autofill/core/browser/autofill_metrics.h" | 19 #include "components/autofill/core/browser/autofill_metrics.h" |
20 #include "components/autofill/core/browser/credit_card.h" | 20 #include "components/autofill/core/browser/credit_card.h" |
| 21 #include "components/autofill/core/common/autofill_pref_names.h" |
| 22 #include "components/user_prefs/user_prefs.h" |
21 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
24 | 26 |
25 using base::Bucket; | 27 using base::Bucket; |
26 using testing::ElementsAre; | 28 using testing::ElementsAre; |
27 | 29 |
28 namespace autofill { | 30 namespace autofill { |
29 | 31 |
30 class TestSaveCardBubbleControllerImpl : public SaveCardBubbleControllerImpl { | 32 class TestSaveCardBubbleControllerImpl : public SaveCardBubbleControllerImpl { |
(...skipping 23 matching lines...) Expand all Loading... |
54 base::TimeDelta elapsed_; | 56 base::TimeDelta elapsed_; |
55 }; | 57 }; |
56 | 58 |
57 class SaveCardBubbleControllerImplTest : public BrowserWithTestWindowTest { | 59 class SaveCardBubbleControllerImplTest : public BrowserWithTestWindowTest { |
58 public: | 60 public: |
59 SaveCardBubbleControllerImplTest() {} | 61 SaveCardBubbleControllerImplTest() {} |
60 | 62 |
61 void SetUp() override { | 63 void SetUp() override { |
62 BrowserWithTestWindowTest::SetUp(); | 64 BrowserWithTestWindowTest::SetUp(); |
63 AddTab(browser(), GURL("about:blank")); | 65 AddTab(browser(), GURL("about:blank")); |
64 TestSaveCardBubbleControllerImpl::CreateForTesting( | 66 content::WebContents* web_contents = |
65 browser()->tab_strip_model()->GetActiveWebContents()); | 67 browser()->tab_strip_model()->GetActiveWebContents(); |
| 68 TestSaveCardBubbleControllerImpl::CreateForTesting(web_contents); |
| 69 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()) |
| 70 ->SetInteger( |
| 71 prefs::kAutofillAcceptSaveCreditCardPromptState, |
| 72 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE); |
66 } | 73 } |
67 | 74 |
68 BrowserWindow* CreateBrowserWindow() override { | 75 BrowserWindow* CreateBrowserWindow() override { |
69 return new SaveCardBubbleTestBrowserWindow(); | 76 return new SaveCardBubbleTestBrowserWindow(); |
70 } | 77 } |
71 | 78 |
72 void SetLegalMessage(const std::string& message_json, | 79 void SetLegalMessage(const std::string& message_json, |
73 bool should_cvc_be_requested = false) { | 80 bool should_cvc_be_requested = false) { |
74 std::unique_ptr<base::Value> value(base::JSONReader::Read(message_json)); | 81 std::unique_ptr<base::Value> value(base::JSONReader::Read(message_json)); |
75 ASSERT_TRUE(value); | 82 ASSERT_TRUE(value); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 base::HistogramTester histogram_tester; | 267 base::HistogramTester histogram_tester; |
261 controller()->OnCancelButton(); | 268 controller()->OnCancelButton(); |
262 controller()->OnBubbleClosed(); | 269 controller()->OnBubbleClosed(); |
263 | 270 |
264 histogram_tester.ExpectUniqueSample( | 271 histogram_tester.ExpectUniqueSample( |
265 "Autofill.SaveCreditCardPrompt.Local.Reshows", | 272 "Autofill.SaveCreditCardPrompt.Local.Reshows", |
266 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1); | 273 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1); |
267 } | 274 } |
268 | 275 |
269 TEST_F(SaveCardBubbleControllerImplTest, | 276 TEST_F(SaveCardBubbleControllerImplTest, |
| 277 Metrics_Local_FirstShow_CancelButton_FirstShow) { |
| 278 base::HistogramTester histogram_tester; |
| 279 ShowLocalBubble(); |
| 280 controller()->OnCancelButton(); |
| 281 controller()->OnBubbleClosed(); |
| 282 |
| 283 ShowLocalBubble(); |
| 284 controller()->OnCancelButton(); |
| 285 controller()->OnBubbleClosed(); |
| 286 |
| 287 EXPECT_THAT( |
| 288 histogram_tester.GetAllSamples( |
| 289 "Autofill.SaveCreditCardPrompt.Local.FirstShow"), |
| 290 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), |
| 291 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1), |
| 292 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1))); |
| 293 EXPECT_THAT( |
| 294 histogram_tester.GetAllSamples( |
| 295 "Autofill.SaveCreditCardPrompt.Local.FirstShow.PreviouslyDenied"), |
| 296 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), |
| 297 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1), |
| 298 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1))); |
| 299 } |
| 300 |
| 301 TEST_F(SaveCardBubbleControllerImplTest, |
| 302 Metrics_Local_FirstShow_CancelButton_FirstShow_SaveButton_FirstShow) { |
| 303 base::HistogramTester histogram_tester; |
| 304 ShowLocalBubble(); |
| 305 controller()->OnCancelButton(); |
| 306 controller()->OnBubbleClosed(); |
| 307 |
| 308 ShowLocalBubble(); |
| 309 controller()->OnSaveButton(); |
| 310 controller()->OnBubbleClosed(); |
| 311 |
| 312 ShowLocalBubble(); |
| 313 |
| 314 EXPECT_THAT( |
| 315 histogram_tester.GetAllSamples( |
| 316 "Autofill.SaveCreditCardPrompt.Local.FirstShow"), |
| 317 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), |
| 318 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1), |
| 319 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, 1))); |
| 320 EXPECT_THAT( |
| 321 histogram_tester.GetAllSamples( |
| 322 "Autofill.SaveCreditCardPrompt.Local.FirstShow.PreviouslyAccepted"), |
| 323 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), |
| 324 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1))); |
| 325 EXPECT_THAT( |
| 326 histogram_tester.GetAllSamples( |
| 327 "Autofill.SaveCreditCardPrompt.Local.FirstShow.PreviouslyDenied"), |
| 328 ElementsAre(Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), |
| 329 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, 1), |
| 330 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, 1))); |
| 331 } |
| 332 |
| 333 TEST_F(SaveCardBubbleControllerImplTest, |
270 Metrics_Local_FirstShow_NavigateWhileShowing) { | 334 Metrics_Local_FirstShow_NavigateWhileShowing) { |
271 ShowLocalBubble(); | 335 ShowLocalBubble(); |
272 | 336 |
273 base::HistogramTester histogram_tester; | 337 base::HistogramTester histogram_tester; |
274 // Fake-navigate after bubble has been visible for a long time. | 338 // Fake-navigate after bubble has been visible for a long time. |
275 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); | 339 controller()->set_elapsed(base::TimeDelta::FromMinutes(1)); |
276 | 340 |
277 controller()->SimulateNavigation(); | 341 controller()->SimulateNavigation(); |
278 | 342 |
279 histogram_tester.ExpectUniqueSample( | 343 histogram_tester.ExpectUniqueSample( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 EXPECT_THAT( | 459 EXPECT_THAT( |
396 histogram_tester.GetAllSamples( | 460 histogram_tester.GetAllSamples( |
397 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), | 461 "Autofill.SaveCreditCardPrompt.Upload.FirstShow"), |
398 ElementsAre( | 462 ElementsAre( |
399 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), | 463 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, 1), |
400 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, | 464 Bucket(AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, |
401 1))); | 465 1))); |
402 } | 466 } |
403 | 467 |
404 } // namespace autofill | 468 } // namespace autofill |
OLD | NEW |