Chromium Code Reviews| 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/json/json_reader.h" | |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 11 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 12 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 12 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" | 13 #include "chrome/browser/ui/autofill/chrome_autofill_client.h" |
| 13 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 14 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 15 #include "components/autofill/core/browser/autofill_test_utils.h" | 16 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 16 #include "components/autofill/core/browser/personal_data_manager.h" | 17 #include "components/autofill/core/browser/personal_data_manager.h" |
| 17 #include "components/autofill/core/common/autofill_pref_names.h" | 18 #include "components/autofill/core/common/autofill_pref_names.h" |
| 18 #include "components/infobars/core/confirm_infobar_delegate.h" | 19 #include "components/infobars/core/confirm_infobar_delegate.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 ~AutofillSaveCardInfoBarDelegateMobileTest() override; | 54 ~AutofillSaveCardInfoBarDelegateMobileTest() override; |
| 54 | 55 |
| 55 void SetUp() override; | 56 void SetUp() override; |
| 56 void TearDown() override; | 57 void TearDown() override; |
| 57 | 58 |
| 58 protected: | 59 protected: |
| 59 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate( | 60 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegate( |
| 60 bool is_uploading, | 61 bool is_uploading, |
| 61 prefs::PreviousSaveCreditCardPromptUserDecision | 62 prefs::PreviousSaveCreditCardPromptUserDecision |
| 62 previous_save_credit_card_prompt_user_decision); | 63 previous_save_credit_card_prompt_user_decision); |
| 64 std::unique_ptr<ConfirmInfoBarDelegate> CreateDelegateWithLegalMessage( | |
| 65 bool is_uploading, | |
| 66 std::string& legal_message_string, | |
| 67 prefs::PreviousSaveCreditCardPromptUserDecision | |
| 68 previous_save_credit_card_prompt_user_decision); | |
| 63 | 69 |
| 64 std::unique_ptr<TestPersonalDataManager> personal_data_; | 70 std::unique_ptr<TestPersonalDataManager> personal_data_; |
| 65 | 71 |
| 66 private: | 72 private: |
| 67 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); | 73 DISALLOW_COPY_AND_ASSIGN(AutofillSaveCardInfoBarDelegateMobileTest); |
| 68 }; | 74 }; |
| 69 | 75 |
| 70 AutofillSaveCardInfoBarDelegateMobileTest:: | 76 AutofillSaveCardInfoBarDelegateMobileTest:: |
| 71 AutofillSaveCardInfoBarDelegateMobileTest() {} | 77 AutofillSaveCardInfoBarDelegateMobileTest() {} |
| 72 | 78 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 94 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { | 100 void AutofillSaveCardInfoBarDelegateMobileTest::TearDown() { |
| 95 personal_data_.reset(); | 101 personal_data_.reset(); |
| 96 ChromeRenderViewHostTestHarness::TearDown(); | 102 ChromeRenderViewHostTestHarness::TearDown(); |
| 97 } | 103 } |
| 98 | 104 |
| 99 std::unique_ptr<ConfirmInfoBarDelegate> | 105 std::unique_ptr<ConfirmInfoBarDelegate> |
| 100 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate( | 106 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegate( |
| 101 bool is_uploading, | 107 bool is_uploading, |
| 102 prefs::PreviousSaveCreditCardPromptUserDecision | 108 prefs::PreviousSaveCreditCardPromptUserDecision |
| 103 previous_save_credit_card_prompt_user_decision) { | 109 previous_save_credit_card_prompt_user_decision) { |
| 104 base::HistogramTester histogram_tester; | 110 std::string legal_message_string = ""; |
| 111 return CreateDelegateWithLegalMessage( | |
| 112 is_uploading, legal_message_string, | |
|
Mathieu
2017/06/20 00:36:20
here you could pass "" if you apply my comment bel
Jared Saul
2017/06/20 20:51:27
Done.
| |
| 113 previous_save_credit_card_prompt_user_decision); | |
| 114 } | |
| 115 | |
| 116 std::unique_ptr<ConfirmInfoBarDelegate> | |
| 117 AutofillSaveCardInfoBarDelegateMobileTest::CreateDelegateWithLegalMessage( | |
| 118 bool is_uploading, | |
| 119 std::string& legal_message_string, | |
|
Mathieu
2017/06/20 00:36:20
Any reason you are using a ref? For this test, std
Jared Saul
2017/06/20 20:51:27
Done, thank you.
| |
| 120 prefs::PreviousSaveCreditCardPromptUserDecision | |
| 121 previous_save_credit_card_prompt_user_decision) { | |
| 105 CreditCard credit_card; | 122 CreditCard credit_card; |
| 106 std::unique_ptr<base::DictionaryValue> legal_message; | 123 std::unique_ptr<base::DictionaryValue> legal_message; |
| 124 if (!legal_message_string.empty()) { | |
| 125 std::unique_ptr<base::Value> value( | |
| 126 base::JSONReader::Read(legal_message_string)); | |
| 127 EXPECT_TRUE(value); | |
| 128 base::DictionaryValue* dictionary; | |
| 129 EXPECT_TRUE(value->GetAsDictionary(&dictionary)); | |
| 130 legal_message = dictionary->CreateDeepCopy(); | |
| 131 } | |
| 107 std::unique_ptr<ConfirmInfoBarDelegate> delegate( | 132 std::unique_ptr<ConfirmInfoBarDelegate> delegate( |
| 108 new AutofillSaveCardInfoBarDelegateMobile( | 133 new AutofillSaveCardInfoBarDelegateMobile( |
| 109 is_uploading, credit_card, std::move(legal_message), | 134 is_uploading, credit_card, std::move(legal_message), |
| 110 base::Bind(base::IgnoreResult( | 135 base::Bind(base::IgnoreResult( |
| 111 &TestPersonalDataManager::SaveImportedCreditCard), | 136 &TestPersonalDataManager::SaveImportedCreditCard), |
| 112 base::Unretained(personal_data_.get()), credit_card), | 137 base::Unretained(personal_data_.get()), credit_card), |
| 113 profile()->GetPrefs())); | 138 profile()->GetPrefs())); |
| 114 std::string destination = is_uploading ? ".Server" : ".Local"; | 139 std::string destination = is_uploading ? ".Server" : ".Local"; |
| 115 std::string previous_response; | 140 std::string previous_response; |
| 116 switch (previous_save_credit_card_prompt_user_decision) { | 141 switch (previous_save_credit_card_prompt_user_decision) { |
| 117 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED: | 142 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED: |
| 118 previous_response = ".PreviouslyAccepted"; | 143 previous_response = ".PreviouslyAccepted"; |
| 119 break; | 144 break; |
| 120 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED: | 145 case prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED: |
| 121 previous_response = ".PreviouslyDenied"; | 146 previous_response = ".PreviouslyDenied"; |
| 122 break; | 147 break; |
| 123 default: | 148 default: |
| 124 EXPECT_EQ(previous_save_credit_card_prompt_user_decision, | 149 EXPECT_EQ(previous_save_credit_card_prompt_user_decision, |
| 125 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE); | 150 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE); |
| 126 break; | 151 break; |
| 127 } | 152 } |
| 128 histogram_tester.ExpectUniqueSample( | |
| 129 "Autofill.CreditCardInfoBar" + destination + previous_response, | |
| 130 AutofillMetrics::INFOBAR_SHOWN, 1); | |
| 131 return delegate; | 153 return delegate; |
| 132 } | 154 } |
| 133 | 155 |
| 134 // Test that local credit card save infobar metrics are logged correctly. | 156 // Test that local credit card save infobar metrics are logged correctly. |
| 135 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { | 157 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Local) { |
| 136 ::testing::InSequence dummy; | 158 ::testing::InSequence dummy; |
| 137 | 159 |
| 160 // Infobar is shown. | |
| 161 { | |
| 162 base::HistogramTester histogram_tester; | |
| 163 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | |
| 164 /* is_uploading= */ false, | |
| 165 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); | |
| 166 | |
| 167 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", | |
| 168 AutofillMetrics::INFOBAR_SHOWN, 1); | |
| 169 } | |
| 170 | |
| 138 // Accept the infobar. | 171 // Accept the infobar. |
| 139 { | 172 { |
| 140 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 173 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 141 /* is_uploading= */ false, | 174 /* is_uploading= */ false, |
| 142 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); | 175 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); |
| 143 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 176 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
| 144 | 177 |
| 145 base::HistogramTester histogram_tester; | 178 base::HistogramTester histogram_tester; |
| 146 EXPECT_TRUE(infobar->Accept()); | 179 EXPECT_TRUE(infobar->Accept()); |
| 147 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Local", | 180 histogram_tester.ExpectUniqueSample( |
| 148 AutofillMetrics::INFOBAR_ACCEPTED, 1); | 181 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
| 182 AutofillMetrics::INFOBAR_ACCEPTED, 1); | |
| 149 } | 183 } |
| 150 | 184 |
| 151 // Cancel the infobar. | 185 // Cancel the infobar. |
| 152 { | 186 { |
| 153 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 187 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 154 /* is_uploading= */ false, | 188 /* is_uploading= */ false, |
| 155 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); | 189 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); |
| 156 | 190 |
| 157 base::HistogramTester histogram_tester; | 191 base::HistogramTester histogram_tester; |
| 158 EXPECT_TRUE(infobar->Cancel()); | 192 EXPECT_TRUE(infobar->Cancel()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 185 histogram_tester.ExpectUniqueSample( | 219 histogram_tester.ExpectUniqueSample( |
| 186 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", | 220 "Autofill.CreditCardInfoBar.Local.PreviouslyDenied", |
| 187 AutofillMetrics::INFOBAR_IGNORED, 1); | 221 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 188 } | 222 } |
| 189 } | 223 } |
| 190 | 224 |
| 191 // Test that server credit card save infobar metrics are logged correctly. | 225 // Test that server credit card save infobar metrics are logged correctly. |
| 192 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { | 226 TEST_F(AutofillSaveCardInfoBarDelegateMobileTest, Metrics_Server) { |
| 193 ::testing::InSequence dummy; | 227 ::testing::InSequence dummy; |
| 194 | 228 |
| 229 // Infobar is shown. | |
| 230 { | |
| 231 base::HistogramTester histogram_tester; | |
| 232 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | |
| 233 /* is_uploading= */ true, | |
| 234 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); | |
| 235 | |
| 236 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", | |
| 237 AutofillMetrics::INFOBAR_SHOWN, 1); | |
| 238 } | |
| 239 | |
| 240 // Infobar is still shown when the legal message is successfully parsed. | |
| 241 { | |
| 242 base::HistogramTester histogram_tester; | |
| 243 std::string good_legal_message = | |
| 244 "{" | |
| 245 " \"line\" : [ {" | |
| 246 " \"template\": \"This is the entire message.\"" | |
| 247 " } ]" | |
| 248 "}"; | |
| 249 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | |
| 250 CreateDelegateWithLegalMessage( | |
| 251 /* is_uploading= */ true, good_legal_message, | |
|
Mathieu
2017/06/20 00:36:20
with my proposed change you can std::move(good_leg
Jared Saul
2017/06/20 20:51:27
Done.
| |
| 252 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); | |
| 253 | |
| 254 histogram_tester.ExpectUniqueSample( | |
| 255 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", | |
| 256 AutofillMetrics::INFOBAR_SHOWN, 1); | |
| 257 } | |
| 258 | |
| 259 // Infobar is not shown because the provided legal message is invalid. | |
| 260 { | |
| 261 base::HistogramTester histogram_tester; | |
| 262 // Legal message is invalid because it's missing the url. | |
| 263 std::string bad_legal_message = | |
| 264 "{" | |
| 265 " \"line\" : [ {" | |
| 266 " \"template\": \"Panda {0}.\"," | |
| 267 " \"template_parameter\": [ {" | |
| 268 " \"display_text\": \"bear\"" | |
| 269 " } ]" | |
| 270 " } ]" | |
| 271 "}"; | |
| 272 std::unique_ptr<ConfirmInfoBarDelegate> infobar( | |
| 273 CreateDelegateWithLegalMessage( | |
| 274 /* is_uploading= */ true, bad_legal_message, | |
| 275 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED)); | |
| 276 | |
| 277 histogram_tester.ExpectUniqueSample( | |
| 278 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", | |
| 279 AutofillMetrics::INFOBAR_NOT_SHOWN_INVALID_LEGAL_MESSAGE, 1); | |
| 280 } | |
| 281 | |
| 195 // Accept the infobar. | 282 // Accept the infobar. |
| 196 { | 283 { |
| 197 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 284 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 198 /* is_uploading= */ true, | 285 /* is_uploading= */ true, |
| 199 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); | 286 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_NONE)); |
| 200 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); | 287 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_)); |
| 201 | 288 |
| 202 base::HistogramTester histogram_tester; | 289 base::HistogramTester histogram_tester; |
| 203 EXPECT_TRUE(infobar->Accept()); | 290 EXPECT_TRUE(infobar->Accept()); |
| 204 histogram_tester.ExpectUniqueSample("Autofill.CreditCardInfoBar.Server", | 291 histogram_tester.ExpectUniqueSample( |
| 205 AutofillMetrics::INFOBAR_ACCEPTED, 1); | 292 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
| 293 AutofillMetrics::INFOBAR_ACCEPTED, 1); | |
| 206 } | 294 } |
| 207 | 295 |
| 208 // Cancel the infobar. | 296 // Cancel the infobar. |
| 209 { | 297 { |
| 210 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( | 298 std::unique_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate( |
| 211 /* is_uploading= */ true, | 299 /* is_uploading= */ true, |
| 212 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); | 300 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED)); |
| 213 | 301 |
| 214 base::HistogramTester histogram_tester; | 302 base::HistogramTester histogram_tester; |
| 215 EXPECT_TRUE(infobar->Cancel()); | 303 EXPECT_TRUE(infobar->Cancel()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 239 | 327 |
| 240 base::HistogramTester histogram_tester; | 328 base::HistogramTester histogram_tester; |
| 241 infobar.reset(); | 329 infobar.reset(); |
| 242 histogram_tester.ExpectUniqueSample( | 330 histogram_tester.ExpectUniqueSample( |
| 243 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", | 331 "Autofill.CreditCardInfoBar.Server.PreviouslyDenied", |
| 244 AutofillMetrics::INFOBAR_IGNORED, 1); | 332 AutofillMetrics::INFOBAR_IGNORED, 1); |
| 245 } | 333 } |
| 246 } | 334 } |
| 247 | 335 |
| 248 } // namespace autofill | 336 } // namespace autofill |
| OLD | NEW |