OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
6 | 6 |
7 import android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
8 | 8 |
9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
10 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 10 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 | 363 |
364 mHelper.setCreditCard(card1); | 364 mHelper.setCreditCard(card1); |
365 mHelper.addServerCreditCard(card2); | 365 mHelper.addServerCreditCard(card2); |
366 | 366 |
367 // Only one card should be suggested to the user since the two are ident
ical. | 367 // Only one card should be suggested to the user since the two are ident
ical. |
368 assertEquals(1, mHelper.getNumberOfCreditCardsToSuggest()); | 368 assertEquals(1, mHelper.getNumberOfCreditCardsToSuggest()); |
369 | 369 |
370 // Both cards should be seen in the settings even if they are identical. | 370 // Both cards should be seen in the settings even if they are identical. |
371 assertEquals(2, mHelper.getNumberOfCreditCardsForSettings()); | 371 assertEquals(2, mHelper.getNumberOfCreditCardsForSettings()); |
372 } | 372 } |
| 373 |
| 374 @SmallTest |
| 375 @Feature({"Autofill"}) |
| 376 public void testProfileUseStatsSettingAndGetting() throws InterruptedExcepti
on, |
| 377 ExecutionException { |
| 378 String guid = mHelper.setProfile( |
| 379 new AutofillProfile("" /* guid */, "https://www.example.com" /*
origin */, |
| 380 "Jasper Lundgren", "", "1500 Second Ave", "California",
"Hollywood", "", |
| 381 "90068", "", "US", "555 123-9876", "jasperl@example.com"
, "")); |
| 382 |
| 383 // Make sure the profile does not have the specific use stats form the s
tart. |
| 384 assertTrue(1234 != mHelper.getProfileUseCountForTesting(guid)); |
| 385 assertTrue(1234 != mHelper.getProfileUseDateForTesting(guid)); |
| 386 |
| 387 // Set specific use stats for the profile. |
| 388 mHelper.setProfileUseStatsForTesting(guid, 1234, 1234); |
| 389 |
| 390 // Make sure the specific use stats were set for the profile. |
| 391 assertEquals(1234, mHelper.getProfileUseCountForTesting(guid)); |
| 392 assertEquals(1234, mHelper.getProfileUseDateForTesting(guid)); |
| 393 } |
| 394 |
| 395 |
| 396 @SmallTest |
| 397 @Feature({"Autofill"}) |
| 398 public void testCreditCardUseStatsSettingAndGetting() throws InterruptedExce
ption, |
| 399 ExecutionException { |
| 400 String guid = mHelper.setCreditCard( |
| 401 new CreditCard("" /* guid */, "https://www.example.com" /* origi
n */, |
| 402 true /* isLocal */, false /* isCached */, "John Doe", "12341
23412341234", "", |
| 403 "5", "2020", "Visa", 0 /* issuerIconDrawableId */, "" /* bil
lingAddressId */)); |
| 404 |
| 405 // Make sure the credit card does not have the specific use stats form t
he start. |
| 406 assertTrue(1234 != mHelper.getCreditCardUseCountForTesting(guid)); |
| 407 assertTrue(1234 != mHelper.getCreditCardUseDateForTesting(guid)); |
| 408 |
| 409 // Set specific use stats for the credit card. |
| 410 mHelper.setCreditCardUseStatsForTesting(guid, 1234, 1234); |
| 411 |
| 412 // Make sure the specific use stats were set for the credit card. |
| 413 assertEquals(1234, mHelper.getCreditCardUseCountForTesting(guid)); |
| 414 assertEquals(1234, mHelper.getCreditCardUseDateForTesting(guid)); |
| 415 } |
| 416 |
| 417 @SmallTest |
| 418 @Feature({"Autofill"}) |
| 419 public void testRecordAndLogProfileUse() throws InterruptedException, Execut
ionException { |
| 420 String guid = mHelper.setProfile( |
| 421 new AutofillProfile("" /* guid */, "https://www.example.com" /*
origin */, |
| 422 "Jasper Lundgren", "", "1500 Second Ave", "California",
"Hollywood", "", |
| 423 "90068", "", "US", "555 123-9876", "jasperl@example.com"
, "")); |
| 424 |
| 425 // Set specific use stats for the profile. |
| 426 mHelper.setProfileUseStatsForTesting(guid, 1234, 1234); |
| 427 |
| 428 // Get the current date value just before the call to record and log. |
| 429 long timeBeforeRecord = mHelper.getCurrentDateForTesting(); |
| 430 |
| 431 // Record and log use of the profile. |
| 432 mHelper.recordAndLogProfileUse(guid); |
| 433 |
| 434 // Get the current date value just after the call to record and log. |
| 435 long timeAfterRecord = mHelper.getCurrentDateForTesting(); |
| 436 |
| 437 // Make sure the use stats of the profile were updated. |
| 438 assertEquals(1235, mHelper.getProfileUseCountForTesting(guid)); |
| 439 assertTrue(timeBeforeRecord <= mHelper.getProfileUseDateForTesting(guid)
); |
| 440 assertTrue(timeAfterRecord >= mHelper.getProfileUseDateForTesting(guid))
; |
| 441 } |
| 442 |
| 443 |
| 444 @SmallTest |
| 445 @Feature({"Autofill"}) |
| 446 public void testRecordAndLogCreditCardUse() throws InterruptedException, Exe
cutionException { |
| 447 String guid = mHelper.setCreditCard( |
| 448 new CreditCard("" /* guid */, "https://www.example.com" /* o
rigin */, |
| 449 true /* isLocal */, false /* isCached */, "John Doe"
, |
| 450 "1234123412341234", "", "5", "2020", "Visa", |
| 451 0 /* issuerIconDrawableId */, "" /* billingAddressId
*/)); |
| 452 |
| 453 // Set specific use stats for the credit card. |
| 454 mHelper.setCreditCardUseStatsForTesting(guid, 1234, 1234); |
| 455 |
| 456 // Get the current date value just before the call to record and log. |
| 457 long timeBeforeRecord = mHelper.getCurrentDateForTesting(); |
| 458 |
| 459 // Record and log use of the credit card. |
| 460 mHelper.recordAndLogCreditCardUse(guid); |
| 461 |
| 462 // Get the current date value just after the call to record and log. |
| 463 long timeAfterRecord = mHelper.getCurrentDateForTesting(); |
| 464 |
| 465 // Make sure the use stats of the credit card were updated. |
| 466 assertEquals(1235, mHelper.getCreditCardUseCountForTesting(guid)); |
| 467 assertTrue(timeBeforeRecord <= mHelper.getCreditCardUseDateForTesting(gu
id)); |
| 468 assertTrue(timeAfterRecord >= mHelper.getCreditCardUseDateForTesting(gui
d)); |
| 469 } |
373 } | 470 } |
OLD | NEW |