| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 @Override | 27 @Override |
| 28 public void setUp() throws Exception { | 28 public void setUp() throws Exception { |
| 29 super.setUp(); | 29 super.setUp(); |
| 30 ApplicationData.clearAppData(getInstrumentation().getTargetContext()); | 30 ApplicationData.clearAppData(getInstrumentation().getTargetContext()); |
| 31 loadNativeLibraryAndInitBrowserProcess(); | 31 loadNativeLibraryAndInitBrowserProcess(); |
| 32 | 32 |
| 33 mHelper = new AutofillTestHelper(); | 33 mHelper = new AutofillTestHelper(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 private AutofillProfile createTestProfile() { |
| 37 return new AutofillProfile("" /* guid */, "https://www.example.com" /* o
rigin */, |
| 38 "John Major", "Acme Inc.", "123 Main", "California", "Los Angele
s", "", "90210", "", |
| 39 "US", "555 123-4567", "jm@example.com", ""); |
| 40 } |
| 41 |
| 36 @SmallTest | 42 @SmallTest |
| 37 @Feature({"Autofill"}) | 43 @Feature({"Autofill"}) |
| 38 public void testAddAndEditProfiles() throws InterruptedException, ExecutionE
xception, | 44 public void testAddAndEditProfiles() throws InterruptedException, ExecutionE
xception, |
| 39 TimeoutException { | 45 TimeoutException { |
| 40 AutofillProfile profile = new AutofillProfile( | 46 AutofillProfile profile = new AutofillProfile( |
| 41 "" /* guid */, "https://www.example.com" /* origin */, | 47 "" /* guid */, "https://www.example.com" /* origin */, |
| 42 "John Smith", "Acme Inc.", | 48 "John Smith", "Acme Inc.", |
| 43 "1 Main\nApt A", "CA", "San Francisco", "", | 49 "1 Main\nApt A", "CA", "San Francisco", "", |
| 44 "94102", "", | 50 "94102", "", |
| 45 "US", "4158889999", "john@acme.inc", ""); | 51 "US", "4158889999", "john@acme.inc", ""); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 assertEquals("en", storedProfile2.getLanguageCode()); | 103 assertEquals("en", storedProfile2.getLanguageCode()); |
| 98 assertEquals("US", storedProfile2.getCountryCode()); | 104 assertEquals("US", storedProfile2.getCountryCode()); |
| 99 assertEquals("San Francisco", storedProfile2.getLocality()); | 105 assertEquals("San Francisco", storedProfile2.getLocality()); |
| 100 assertEquals("https://www.example.com", storedProfile2.getOrigin()); | 106 assertEquals("https://www.example.com", storedProfile2.getOrigin()); |
| 101 } | 107 } |
| 102 | 108 |
| 103 @SmallTest | 109 @SmallTest |
| 104 @Feature({"Autofill"}) | 110 @Feature({"Autofill"}) |
| 105 public void testAddAndDeleteProfile() throws InterruptedException, Execution
Exception, | 111 public void testAddAndDeleteProfile() throws InterruptedException, Execution
Exception, |
| 106 TimeoutException { | 112 TimeoutException { |
| 107 AutofillProfile profile = new AutofillProfile( | 113 String profileOneGUID = mHelper.setProfile(createTestProfile()); |
| 108 "" /* guid */, "Chrome settings" /* origin */, | |
| 109 "John Smith", "Acme Inc.", | |
| 110 "1 Main\nApt A", "CA", "San Francisco", "", | |
| 111 "94102", "", | |
| 112 "US", "4158889999", "john@acme.inc", ""); | |
| 113 String profileOneGUID = mHelper.setProfile(profile); | |
| 114 assertEquals(1, mHelper.getNumberOfProfilesForSettings()); | 114 assertEquals(1, mHelper.getNumberOfProfilesForSettings()); |
| 115 | 115 |
| 116 mHelper.deleteProfile(profileOneGUID); | 116 mHelper.deleteProfile(profileOneGUID); |
| 117 assertEquals(0, mHelper.getNumberOfProfilesForSettings()); | 117 assertEquals(0, mHelper.getNumberOfProfilesForSettings()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 @SmallTest | 120 @SmallTest |
| 121 @Feature({"Autofill"}) | 121 @Feature({"Autofill"}) |
| 122 public void testAddAndEditCreditCards() throws InterruptedException, Executi
onException, | 122 public void testAddAndEditCreditCards() throws InterruptedException, Executi
onException, |
| 123 TimeoutException { | 123 TimeoutException { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // The first profile has a lower use count than the two other profiles.
It also has an older | 311 // The first profile has a lower use count than the two other profiles.
It also has an older |
| 312 // use date that the second profile and the same use date as the third.
It should be last. | 312 // use date that the second profile and the same use date as the third.
It should be last. |
| 313 mHelper.setProfileUseStatsForTesting(guid1, 3, 5000); | 313 mHelper.setProfileUseStatsForTesting(guid1, 3, 5000); |
| 314 // The second profile has the same use count as the third but a more rec
ent use date. It | 314 // The second profile has the same use count as the third but a more rec
ent use date. It |
| 315 // also has a bigger use count that the first profile. It should be firs
t. | 315 // also has a bigger use count that the first profile. It should be firs
t. |
| 316 mHelper.setProfileUseStatsForTesting(guid2, 6, 5001); | 316 mHelper.setProfileUseStatsForTesting(guid2, 6, 5001); |
| 317 // The third profile has the same use count as the second but an older u
se date. It also has | 317 // The third profile has the same use count as the second but an older u
se date. It also has |
| 318 // a bigger use count that the first profile. It should be second. | 318 // a bigger use count that the first profile. It should be second. |
| 319 mHelper.setProfileUseStatsForTesting(guid3, 6, 5000); | 319 mHelper.setProfileUseStatsForTesting(guid3, 6, 5000); |
| 320 | 320 |
| 321 List<AutofillProfile> profiles = mHelper.getProfilesToSuggest(); | 321 List<AutofillProfile> profiles = mHelper.getProfilesToSuggest(false /* i
ncludeName */); |
| 322 assertEquals(3, profiles.size()); | 322 assertEquals(3, profiles.size()); |
| 323 assertTrue("Profile2 should be ranked first", guid2.equals(profiles.get(
0).getGUID())); | 323 assertTrue("Profile2 should be ranked first", guid2.equals(profiles.get(
0).getGUID())); |
| 324 assertTrue("Profile3 should be ranked second", guid3.equals(profiles.get
(1).getGUID())); | 324 assertTrue("Profile3 should be ranked second", guid3.equals(profiles.get
(1).getGUID())); |
| 325 assertTrue("Profile1 should be ranked third", guid1.equals(profiles.get(
2).getGUID())); | 325 assertTrue("Profile1 should be ranked third", guid1.equals(profiles.get(
2).getGUID())); |
| 326 } | 326 } |
| 327 | 327 |
| 328 @SmallTest | 328 @SmallTest |
| 329 @Feature({"Autofill"}) | 329 @Feature({"Autofill"}) |
| 330 public void testCreditCardsFrecency() throws InterruptedException, Execution
Exception, | 330 public void testCreditCardsFrecency() throws InterruptedException, Execution
Exception, |
| 331 TimeoutException { | 331 TimeoutException { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 assertEquals(1, mHelper.getNumberOfCreditCardsToSuggest()); | 382 assertEquals(1, mHelper.getNumberOfCreditCardsToSuggest()); |
| 383 | 383 |
| 384 // Both cards should be seen in the settings even if they are identical. | 384 // Both cards should be seen in the settings even if they are identical. |
| 385 assertEquals(2, mHelper.getNumberOfCreditCardsForSettings()); | 385 assertEquals(2, mHelper.getNumberOfCreditCardsForSettings()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 @SmallTest | 388 @SmallTest |
| 389 @Feature({"Autofill"}) | 389 @Feature({"Autofill"}) |
| 390 public void testProfileUseStatsSettingAndGetting() throws InterruptedExcepti
on, | 390 public void testProfileUseStatsSettingAndGetting() throws InterruptedExcepti
on, |
| 391 ExecutionException, TimeoutException { | 391 ExecutionException, TimeoutException { |
| 392 String guid = mHelper.setProfile( | 392 String guid = mHelper.setProfile(createTestProfile()); |
| 393 new AutofillProfile("" /* guid */, "https://www.example.com" /*
origin */, | |
| 394 "Jasper Lundgren", "", "1500 Second Ave", "California",
"Hollywood", "", | |
| 395 "90068", "", "US", "555 123-9876", "jasperl@example.com"
, "")); | |
| 396 | 393 |
| 397 // Make sure the profile does not have the specific use stats form the s
tart. | 394 // Make sure the profile does not have the specific use stats form the s
tart. |
| 398 assertTrue(1234 != mHelper.getProfileUseCountForTesting(guid)); | 395 assertTrue(1234 != mHelper.getProfileUseCountForTesting(guid)); |
| 399 assertTrue(1234 != mHelper.getProfileUseDateForTesting(guid)); | 396 assertTrue(1234 != mHelper.getProfileUseDateForTesting(guid)); |
| 400 | 397 |
| 401 // Set specific use stats for the profile. | 398 // Set specific use stats for the profile. |
| 402 mHelper.setProfileUseStatsForTesting(guid, 1234, 1234); | 399 mHelper.setProfileUseStatsForTesting(guid, 1234, 1234); |
| 403 | 400 |
| 404 // Make sure the specific use stats were set for the profile. | 401 // Make sure the specific use stats were set for the profile. |
| 405 assertEquals(1234, mHelper.getProfileUseCountForTesting(guid)); | 402 assertEquals(1234, mHelper.getProfileUseCountForTesting(guid)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 426 | 423 |
| 427 // Make sure the specific use stats were set for the credit card. | 424 // Make sure the specific use stats were set for the credit card. |
| 428 assertEquals(1234, mHelper.getCreditCardUseCountForTesting(guid)); | 425 assertEquals(1234, mHelper.getCreditCardUseCountForTesting(guid)); |
| 429 assertEquals(1234, mHelper.getCreditCardUseDateForTesting(guid)); | 426 assertEquals(1234, mHelper.getCreditCardUseDateForTesting(guid)); |
| 430 } | 427 } |
| 431 | 428 |
| 432 @SmallTest | 429 @SmallTest |
| 433 @Feature({"Autofill"}) | 430 @Feature({"Autofill"}) |
| 434 public void testRecordAndLogProfileUse() throws InterruptedException, Execut
ionException, | 431 public void testRecordAndLogProfileUse() throws InterruptedException, Execut
ionException, |
| 435 TimeoutException { | 432 TimeoutException { |
| 436 String guid = mHelper.setProfile( | 433 String guid = mHelper.setProfile(createTestProfile()); |
| 437 new AutofillProfile("" /* guid */, "https://www.example.com" /*
origin */, | |
| 438 "Jasper Lundgren", "", "1500 Second Ave", "California",
"Hollywood", "", | |
| 439 "90068", "", "US", "555 123-9876", "jasperl@example.com"
, "")); | |
| 440 | 434 |
| 441 // Set specific use stats for the profile. | 435 // Set specific use stats for the profile. |
| 442 mHelper.setProfileUseStatsForTesting(guid, 1234, 1234); | 436 mHelper.setProfileUseStatsForTesting(guid, 1234, 1234); |
| 443 | 437 |
| 444 // Get the current date value just before the call to record and log. | 438 // Get the current date value just before the call to record and log. |
| 445 long timeBeforeRecord = mHelper.getCurrentDateForTesting(); | 439 long timeBeforeRecord = mHelper.getCurrentDateForTesting(); |
| 446 | 440 |
| 447 // Record and log use of the profile. | 441 // Record and log use of the profile. |
| 448 mHelper.recordAndLogProfileUse(guid); | 442 mHelper.recordAndLogProfileUse(guid); |
| 449 | 443 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 478 mHelper.recordAndLogCreditCardUse(guid); | 472 mHelper.recordAndLogCreditCardUse(guid); |
| 479 | 473 |
| 480 // Get the current date value just after the call to record and log. | 474 // Get the current date value just after the call to record and log. |
| 481 long timeAfterRecord = mHelper.getCurrentDateForTesting(); | 475 long timeAfterRecord = mHelper.getCurrentDateForTesting(); |
| 482 | 476 |
| 483 // Make sure the use stats of the credit card were updated. | 477 // Make sure the use stats of the credit card were updated. |
| 484 assertEquals(1235, mHelper.getCreditCardUseCountForTesting(guid)); | 478 assertEquals(1235, mHelper.getCreditCardUseCountForTesting(guid)); |
| 485 assertTrue(timeBeforeRecord <= mHelper.getCreditCardUseDateForTesting(gu
id)); | 479 assertTrue(timeBeforeRecord <= mHelper.getCreditCardUseDateForTesting(gu
id)); |
| 486 assertTrue(timeAfterRecord >= mHelper.getCreditCardUseDateForTesting(gui
d)); | 480 assertTrue(timeAfterRecord >= mHelper.getCreditCardUseDateForTesting(gui
d)); |
| 487 } | 481 } |
| 482 |
| 483 @SmallTest |
| 484 @Feature({"Autofill"}) |
| 485 public void testGetProfilesToSuggest_NoName() throws InterruptedException, E
xecutionException, |
| 486 TimeoutException { |
| 487 mHelper.setProfile(createTestProfile()); |
| 488 |
| 489 List<AutofillProfile> profiles = mHelper.getProfilesToSuggest(false /* i
ncludeName */); |
| 490 assertEquals("Acme Inc., 123 Main, Los Angeles, California 90210, United
States", |
| 491 profiles.get(0).getLabel()); |
| 492 } |
| 493 |
| 494 @SmallTest |
| 495 @Feature({"Autofill"}) |
| 496 public void testGetProfilesToSuggest_WithName() throws InterruptedException,
ExecutionException, |
| 497 TimeoutException { |
| 498 mHelper.setProfile(createTestProfile()); |
| 499 |
| 500 List<AutofillProfile> profiles = mHelper.getProfilesToSuggest(true /* in
cludeName */); |
| 501 assertEquals("John Major, Acme Inc., 123 Main, Los Angeles, California 9
0210, " |
| 502 + "United States", profiles.get(0).getLabel()); |
| 503 } |
| 488 } | 504 } |
| OLD | NEW |