| 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 "components/autofill/core/browser/autofill_save_card_infobar_delegate_m
obile.h" | 5 #include "components/autofill/core/browser/autofill_save_card_infobar_delegate_m
obile.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| 11 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 11 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 12 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" | 12 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.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/personal_data_manager.h" | 16 #include "components/autofill/core/browser/personal_data_manager.h" |
| 17 #include "components/autofill/core/common/autofill_pref_names.h" |
| 17 #include "components/infobars/core/confirm_infobar_delegate.h" | 18 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 19 #include "components/prefs/pref_service.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| 21 using testing::_; | 23 using testing::_; |
| 22 | 24 |
| 23 namespace autofill { | 25 namespace autofill { |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 class TestPersonalDataManager : public PersonalDataManager { | 29 class TestPersonalDataManager : public PersonalDataManager { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 47 class AutofillSaveCardInfoBarDelegateMobileTest | 49 class AutofillSaveCardInfoBarDelegateMobileTest |
| 48 : public ChromeRenderViewHostTestHarness { | 50 : public ChromeRenderViewHostTestHarness { |
| 49 public: | 51 public: |
| 50 AutofillSaveCardInfoBarDelegateMobileTest(); | 52 AutofillSaveCardInfoBarDelegateMobileTest(); |
| 51 ~AutofillSaveCardInfoBarDelegateMobileTest() override; | 53 ~AutofillSaveCardInfoBarDelegateMobileTest() override; |
| 52 | 54 |
| 53 void SetUp() override; | 55 void SetUp() override; |
| 54 void TearDown() override; | 56 void TearDown() override; |
| 55 | 57 |
| 56 protected: | 58 protected: |
| 57 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate(bool is_uploading); | 59 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
| 60 bool is_uploading, |
| 61 prefs::PreviousSaveCreditCardPromptUserDecision |
| 62 previous_save_credit_card_prompt_user_decision); |
| 58 | 63 |
| 59 std::unique_ptr<TestPersonalDataManager> personal_data_; | 64 std::unique_ptr<TestPersonalDataManager> personal_data_; |
| 60 | 65 |
| 61 private: | 66 private: |
| 62 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); | 67 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); |
| 63 }; | 68 }; |
| 64 | 69 |
| 65 AutofillSaveCardInfoBarDelegateMobileTest:: | 70 AutofillSaveCardInfoBarDelegateMobileTest:: |
| 66 AutofillSaveCardInfoBarDelegateMobileTest() {} | 71 AutofillSaveCardInfoBarDelegateMobileTest() {} |
| 67 | 72 |
| 68 AutofillSaveCardInfoBarDelegateMobileTest:: | 73 AutofillSaveCardInfoBarDelegateMobileTest:: |
| 69 ~AutofillSaveCardInfoBarDelegateMobileTest() {} | 74 ~AutofillSaveCardInfoBarDelegateMobileTest() {} |
| 70 | 75 |
| 71 void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() { | 76 void AutofillSaveCardInfoBarDelegateMobileTest::SetUp() { |
| 72 ChromeRenderViewHostTestHarness::SetUp(); | 77 ChromeRenderViewHostTestHarness::SetUp(); |
| 73 | 78 |
| 74 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); | 79 PersonalDataManagerFactory::GetInstance()->SetTestingFactory(profile(), NULL); |
| 75 | 80 |
| 76 ChromeAutofillClient::CreateForWebContents(web_contents()); | 81 ChromeAutofillClient::CreateForWebContents(web_contents()); |
| 77 ChromeAutofillClient* autofill_client = | 82 ChromeAutofillClient* autofill_client = |
| 78 ChromeAutofillClient::FromWebContents(web_contents()); | 83 ChromeAutofillClient::FromWebContents(web_contents()); |
| 79 | 84 |
| 80 personal_data_.reset(new TestPersonalDataManager()); | 85 personal_data_.reset(new TestPersonalDataManager()); |
| 81 personal_data_->set_database(autofill_client->GetDatabase()); | 86 personal_data_->set_database(autofill_client->GetDatabase()); |
| 82 personal_data_->SetPrefService(profile()->GetPrefs()); | 87 personal_data_->SetPrefService(profile()->GetPrefs()); |
| 88 |
| 89 profile()->GetPrefs()->SetInteger( |
| 90 prefs::kAutofillAcceptSaveCreditCardPromptState, |
| 91 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE); |
| 83 } | 92 } |
| 84 | 93 |
| 85 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { | 94 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { |
| 86 personal_data_.reset(); | 95 personal_data_.reset(); |
| 87 ChromeRenderViewHostTestHarness::TearDown(); | 96 ChromeRenderViewHostTestHarness::TearDown(); |
| 88 } | 97 } |
| 89 | 98 |
| 90 std::unique_ptr<ConfirmInfoBarDelegate> | 99 std::unique_ptr<ConfirmInfoBarDelegate> |
| 91 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate(bool is_uploading) { | 100 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate( |
| 101 bool is_uploading, |
| 102 prefs::PreviousSaveCreditCardPromptUserDecision |
| 103 previous_save_credit_card_prompt_user_decision) { |
| 92 base::HistogramTester histogram_tester; | 104 base::HistogramTester histogram_tester; |
| 93 CreditCard credit_card; | 105 CreditCard credit_card; |
| 94 std::unique_ptr<base::DictionaryValue> legal_message; | 106 std::unique_ptr<base::DictionaryValue> legal_message; |
| 95 std::unique_ptr<ConfirmInfoBarDelegate> delegate( | 107 std::unique_ptr<ConfirmInfoBarDelegate> delegate( |
| 96 new AutofillSaveCardInfoBarDelegateMobile( | 108 new AutofillSaveCardInfoBarDelegateMobile( |
| 97 is_uploading, credit_card, std::move(legal_message), | 109 is_uploading, credit_card, std::move(legal_message), |
| 98 base::Bind(base::IgnoreResult( | 110 base::Bind(base::IgnoreResult( |
| 99 &TestPersonalDataManager::SaveImportedCreditCard), | 111 &TestPersonalDataManager::SaveImportedCreditCard), |
| 100 base::Unretained(personal_data_.get()), credit_card))); | 112 base::Unretained(personal_data_.get()), credit_card), |
| 113 profile()->GetPrefs())); |
| 101 std::string destination = is_uploading ? ".Server" : ".Local"; | 114 std::string destination = is_uploading ? ".Server" : ".Local"; |
| 102 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar" | 115 std::string previous_response; |
| 103 + destination, | 116 switch (previous_save_credit_card_prompt_user_decision) { |
| 104 AutofillMetrics::INFOBAR_SHOWN, 1); | 117 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED: |
| 118 previous_response = ".PreviouslyAccepted"; |
| 119 break; |
| 120 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED: |
| 121 previous_response = ".PreviouslyDenied"; |
| 122 break; |
| 123 default: |
| 124 EXPECT_EQ(previous_save_credit_card_prompt_user_decision, |
| 125 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE); |
| 126 break; |
| 127 } |
| 128 histogram_tester.ExpectUniqueSample( |
| 129 "Autofill.CreditCardInfoBar" + destination + previous_response, |
| 130 AutofillMetrics::INFOBAR_SHOWN, 1); |
| 105 return delegate; | 131 return delegate; |
| 106 } | 132 } |
| 107 | 133 |
| 108 // Test that local credit card save infobar metrics are logged correctly. | 134 // Test that local credit card save infobar metrics are logged correctly. |
| 109 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { | 135 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { |
| 110 ::testing::InSequence dummy; | 136 ::testing::InSequence dummy; |
| 111 | 137 |
| 112 // Accept the infobar. | 138 // Accept the infobar. |
| 113 { | 139 { |
| 114 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 140 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 115 CreateDelegate(/* is_uploading= */ false)); | 141 /* is_uploading= */ false, |
| 142 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); |
| 116 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 143 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
| 117 | 144 |
| 118 base::HistogramTester histogram_tester; | 145 base::HistogramTester histogram_tester; |
| 119 EXPECT_TRUE(infobar->Accept()); | 146 EXPECT_TRUE(infobar->Accept()); |
| 120 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", | 147 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", |
| 121 AutofillMetrics::INFOBAR_ACCEPTED, 1); | 148 AutofillMetrics::INFOBAR_ACCEPTED, 1); |
| 122 } | 149 } |
| 123 | 150 |
| 124 // Cancel the infobar. | 151 // Cancel the infobar. |
| 125 { | 152 { |
| 126 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 153 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 127 CreateDelegate(/* is_uploading= */ false)); | 154 /* is_uploading= */ false, |
| 155 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); |
| 128 | 156 |
| 129 base::HistogramTester histogram_tester; | 157 base::HistogramTester histogram_tester; |
| 130 EXPECT_TRUE(infobar->Cancel()); | 158 EXPECT_TRUE(infobar->Cancel()); |
| 131 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", | 159 histogram_tester.ExpectUniqueSample( |
| 132 AutofillMetrics::INFOBAR_DENIED, 1); | 160 "Autofill.CreditCardInfoBar.Local.PreviouslyAccepted", |
| 161 AutofillMetrics::INFOBAR_DENIED, 1); |
| 133 } | 162 } |
| 134 | 163 |
| 135 // Dismiss the infobar. | 164 // Dismiss the infobar. |
| 136 { | 165 { |
| 137 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 166 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 138 CreateDelegate(/* is_uploading= */ false)); | 167 /* is_uploading= */ false, |
| 168 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
| 139 | 169 |
| 140 base::HistogramTester histogram_tester; | 170 base::HistogramTester histogram_tester; |
| 141 infobar->InfoBarDismissed(); | 171 infobar->InfoBarDismissed(); |
| 142 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", | 172 histogram_tester.ExpectUniqueSample( |
| 143 AutofillMetrics::INFOBAR_DENIED, 1); | 173 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
| 174 AutofillMetrics::INFOBAR_DENIED, 1); |
| 144 } | 175 } |
| 145 | 176 |
| 146 // Ignore the infobar. | 177 // Ignore the infobar. |
| 147 { | 178 { |
| 148 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 179 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 149 CreateDelegate(/* is_uploading= */ false)); | 180 /* is_uploading= */ false, |
| 181 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
| 150 | 182 |
| 151 base::HistogramTester histogram_tester; | 183 base::HistogramTester histogram_tester; |
| 152 infobar.reset(); | 184 infobar.reset(); |
| 153 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", | 185 histogram_tester.ExpectUniqueSample( |
| 154 AutofillMetrics::INFOBAR_IGNORED, 1); | 186 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
| 187 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 155 } | 188 } |
| 156 } | 189 } |
| 157 | 190 |
| 158 // Test that server credit card save infobar metrics are logged correctly. | 191 // Test that server credit card save infobar metrics are logged correctly. |
| 159 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { | 192 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { |
| 160 ::testing::InSequence dummy; | 193 ::testing::InSequence dummy; |
| 161 | 194 |
| 162 // Accept the infobar. | 195 // Accept the infobar. |
| 163 { | 196 { |
| 164 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 197 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 165 CreateDelegate(/* is_uploading= */ true)); | 198 /* is_uploading= */ true, |
| 199 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); |
| 166 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 200 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
| 167 | 201 |
| 168 base::HistogramTester histogram_tester; | 202 base::HistogramTester histogram_tester; |
| 169 EXPECT_TRUE(infobar->Accept()); | 203 EXPECT_TRUE(infobar->Accept()); |
| 170 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", | 204 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", |
| 171 AutofillMetrics::INFOBAR_ACCEPTED, 1); | 205 AutofillMetrics::INFOBAR_ACCEPTED, 1); |
| 172 } | 206 } |
| 173 | 207 |
| 174 // Cancel the infobar. | 208 // Cancel the infobar. |
| 175 { | 209 { |
| 176 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 210 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 177 CreateDelegate(/* is_uploading= */ true)); | 211 /* is_uploading= */ true, |
| 212 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); |
| 178 | 213 |
| 179 base::HistogramTester histogram_tester; | 214 base::HistogramTester histogram_tester; |
| 180 EXPECT_TRUE(infobar->Cancel()); | 215 EXPECT_TRUE(infobar->Cancel()); |
| 181 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", | 216 histogram_tester.ExpectUniqueSample( |
| 182 AutofillMetrics::INFOBAR_DENIED, 1); | 217 "Autofill.CreditCardInfoBar.Server.PreviouslyAccepted", |
| 218 AutofillMetrics::INFOBAR_DENIED, 1); |
| 183 } | 219 } |
| 184 | 220 |
| 185 // Dismiss the infobar. | 221 // Dismiss the infobar. |
| 186 { | 222 { |
| 187 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 223 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 188 CreateDelegate(/* is_uploading= */ true)); | 224 /* is_uploading= */ true, |
| 225 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
| 189 | 226 |
| 190 base::HistogramTester histogram_tester; | 227 base::HistogramTester histogram_tester; |
| 191 infobar->InfoBarDismissed(); | 228 infobar->InfoBarDismissed(); |
| 192 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", | 229 histogram_tester.ExpectUniqueSample( |
| 193 AutofillMetrics::INFOBAR_DENIED, 1); | 230 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
| 231 AutofillMetrics::INFOBAR_DENIED, 1); |
| 194 } | 232 } |
| 195 | 233 |
| 196 // Ignore the infobar. | 234 // Ignore the infobar. |
| 197 { | 235 { |
| 198 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | 236 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 199 CreateDelegate(/* is_uploading= */ true)); | 237 /* is_uploading= */ true, |
| 238 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
| 200 | 239 |
| 201 base::HistogramTester histogram_tester; | 240 base::HistogramTester histogram_tester; |
| 202 infobar.reset(); | 241 infobar.reset(); |
| 203 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", | 242 histogram_tester.ExpectUniqueSample( |
| 204 AutofillMetrics::INFOBAR_IGNORED, 1); | 243 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
| 244 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 205 } | 245 } |
| 206 } | 246 } |
| 207 | 247 |
| 208 } // namespace autofill | 248 } // namespace autofill |
| OLD | NEW |