Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/test/data/webui/settings/passwords_and_autofill_fake_data.js

Issue 1957043002: Separate the listeners and getters for the Autofill Private API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@autofill-lists.gitbr
Patch Set: update histogram.xml and test Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Used to create fake data for both passwords and autofill.
7 * These sections are related, so it made sense to share this.
8 */
9 function FakeDataMaker() {}
10 /**
11 * Creates a single item for the list of passwords.
12 * @param {string|undefined} url
13 * @param {string|undefined} username
14 * @param {number|undefined} passwordLength
15 * @return {chrome.passwordsPrivate.PasswordUiEntry}
16 */
17 FakeDataMaker.passwordEntry = function(url, username, passwordLength) {
18 // Generate fake data if param is undefined.
19 url = url || FakeDataMaker.patternMaker_('www.xxxxxx.com', 16);
20 username = username || FakeDataMaker.patternMaker_('user_xxxxx', 16);
21 passwordLength = passwordLength || Math.floor(Math.random() * 15) + 3;
22
23 return {
24 loginPair: {
25 originUrl: url,
26 username: username,
27 },
28 linkUrl: 'http://' + url + '/login',
29 numCharactersInPassword: passwordLength,
30 };
31 };
32
33 /**
34 * Creates a single item for the list of password exceptions.
35 * @param {string|undefined} url
36 * @return {chrome.passwordsPrivate.ExceptionPair}
37 */
38 FakeDataMaker.exceptionEntry = function(url) {
39 url = url || FakeDataMaker.patternMaker_('www.xxxxxx.com', 16);
40 return {
41 exceptionUrl: url,
42 linkUrl: 'http://' + url + '/login',
43 };
44 };
45
46 /**
47 * Creates a fake address entry for testing.
48 * @return {!chrome.autofillPrivate.AddressEntry}
49 */
50 FakeDataMaker.addressEntry = function() {
51 var ret = {};
52 ret.guid = FakeDataMaker.makeGuid_();
53 ret.fullNames = ['John', 'Doe'];
54 ret.companyName = 'Google';
55 ret.addressLines = FakeDataMaker.patternMaker_('xxxx Main St', 10);
56 ret.addressLevel1 = "CA";
57 ret.addressLevel2 = "Venice";
58 ret.postalCode = FakeDataMaker.patternMaker_('xxxxx', 10);
59 ret.countryCode = 'US';
60 ret.phoneNumbers = [FakeDataMaker.patternMaker_('(xxx) xxx-xxxx', 10)];
61 ret.emailAddresses = [FakeDataMaker.patternMaker_('userxxxx@gmail.com', 16)];
62 ret.languageCode = 'EN-US';
63 ret.metadata = {isLocal: true};
64 ret.metadata.summaryLabel = ret.fullNames[0];
65 ret.metadata.summarySublabel = ' ' + ret.addressLines;
66 return ret;
67 };
68
69 /**
70 * Creates a new random credit card entry for testing.
71 * @return {!chrome.autofillPrivate.CreditCardEntry}
72 */
73 FakeDataMaker.creditCardEntry = function() {
74 var ret = {};
75 ret.guid = FakeDataMaker.makeGuid_();
76 ret.name = 'Jane Doe';
77 ret.cardNumber = FakeDataMaker.patternMaker_('xxxx xxxx xxxx xxxx', 10);
78 ret.expirationMonth = Math.ceil(Math.random() * 11).toString();
79 ret.expirationYear = (2016 + Math.floor(Math.random() * 5)).toString();
80 ret.metadata = {isLocal: true};
81 var cards = ['Visa', 'Mastercard', 'Discover', 'Card'];
82 var card = cards[Math.floor(Math.random() * cards.length)];
83 ret.metadata.summaryLabel = card + ' ' + '****' + ret.cardNumber.substr(-4);
84 return ret;
85 };
86
87 /**
88 * Creates a new random GUID for testing.
89 * @return {!string}
90 * @private
91 */
92 FakeDataMaker.makeGuid_ = function() {
93 return FakeDataMaker.patternMaker_(
94 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 16);
95 };
96
97 /**
98 * Replaces any 'x' in a string with a random number of the base.
99 * @param {!string} pattern The pattern that should be used as an input.
100 * @param {!number} base The number base. ie: 16 for hex or 10 for decimal.
101 * @return {!string}
102 * @private
103 */
104 FakeDataMaker.patternMaker_ = function(pattern, base) {
105 return pattern.replace(/x/g, function() {
106 return Math.floor(Math.random() * base).toString(base);
107 });
108 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698