OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
6 * Used to create fake data for both passwords and autofill. | 6 * Used to create fake data for both passwords and autofill. |
7 * These sections are related, so it made sense to share this. | 7 * These sections are related, so it made sense to share this. |
8 */ | 8 */ |
9 function FakeDataMaker() {} | 9 function FakeDataMaker() {} |
10 /** | 10 /** |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 ret.phoneNumbers = [FakeDataMaker.patternMaker_('(xxx) xxx-xxxx', 10)]; | 60 ret.phoneNumbers = [FakeDataMaker.patternMaker_('(xxx) xxx-xxxx', 10)]; |
61 ret.emailAddresses = [FakeDataMaker.patternMaker_('userxxxx@gmail.com', 16)]; | 61 ret.emailAddresses = [FakeDataMaker.patternMaker_('userxxxx@gmail.com', 16)]; |
62 ret.languageCode = 'EN-US'; | 62 ret.languageCode = 'EN-US'; |
63 ret.metadata = {isLocal: true}; | 63 ret.metadata = {isLocal: true}; |
64 ret.metadata.summaryLabel = ret.fullNames[0]; | 64 ret.metadata.summaryLabel = ret.fullNames[0]; |
65 ret.metadata.summarySublabel = ' ' + ret.addressLines; | 65 ret.metadata.summarySublabel = ' ' + ret.addressLines; |
66 return ret; | 66 return ret; |
67 }; | 67 }; |
68 | 68 |
69 /** | 69 /** |
70 * Creates a new empty credit card entry for testing. | |
71 * @return {!chrome.autofillPrivate.CreditCardEntry} | |
72 */ | |
73 FakeDataMaker.emptyCreditCardEntry = function() { | |
74 var now = new Date(); | |
75 var ret = {}; | |
76 ret.expirationMonth = now.getMonth() + 1; | |
michaelpg
2016/05/27 17:57:08
strings?
hcarmona
2016/05/31 21:14:06
Done.
| |
77 ret.expirationYear = now.getFullYear(); | |
78 return ret; | |
79 }; | |
80 | |
81 /** | |
70 * Creates a new random credit card entry for testing. | 82 * Creates a new random credit card entry for testing. |
71 * @return {!chrome.autofillPrivate.CreditCardEntry} | 83 * @return {!chrome.autofillPrivate.CreditCardEntry} |
72 */ | 84 */ |
73 FakeDataMaker.creditCardEntry = function() { | 85 FakeDataMaker.creditCardEntry = function() { |
74 var ret = {}; | 86 var ret = {}; |
75 ret.guid = FakeDataMaker.makeGuid_(); | 87 ret.guid = FakeDataMaker.makeGuid_(); |
76 ret.name = 'Jane Doe'; | 88 ret.name = 'Jane Doe'; |
77 ret.cardNumber = FakeDataMaker.patternMaker_('xxxx xxxx xxxx xxxx', 10); | 89 ret.cardNumber = FakeDataMaker.patternMaker_('xxxx xxxx xxxx xxxx', 10); |
78 ret.expirationMonth = Math.ceil(Math.random() * 11).toString(); | 90 ret.expirationMonth = Math.ceil(Math.random() * 11).toString(); |
79 ret.expirationYear = (2016 + Math.floor(Math.random() * 5)).toString(); | 91 ret.expirationYear = (2016 + Math.floor(Math.random() * 5)).toString(); |
80 ret.metadata = {isLocal: true}; | 92 ret.metadata = {isLocal: true}; |
81 var cards = ['Visa', 'Mastercard', 'Discover', 'Card']; | 93 var cards = ['Visa', 'Mastercard', 'Discover', 'Card']; |
82 var card = cards[Math.floor(Math.random() * cards.length)]; | 94 var card = cards[Math.floor(Math.random() * cards.length)]; |
83 ret.metadata.summaryLabel = card + ' ' + '****' + ret.cardNumber.substr(-4); | 95 ret.metadata.summaryLabel = card + ' ' + '****' + ret.cardNumber.substr(-4); |
84 return ret; | 96 return ret; |
85 }; | 97 }; |
86 | 98 |
87 /** | 99 /** |
88 * Creates a new random GUID for testing. | 100 * Creates a new random GUID for testing. |
89 * @return {!string} | 101 * @return {string} |
90 * @private | 102 * @private |
91 */ | 103 */ |
92 FakeDataMaker.makeGuid_ = function() { | 104 FakeDataMaker.makeGuid_ = function() { |
93 return FakeDataMaker.patternMaker_( | 105 return FakeDataMaker.patternMaker_( |
94 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 16); | 106 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 16); |
95 }; | 107 }; |
96 | 108 |
97 /** | 109 /** |
98 * Replaces any 'x' in a string with a random number of the base. | 110 * 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. | 111 * @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. | 112 * @param {number} base The number base. ie: 16 for hex or 10 for decimal. |
101 * @return {!string} | 113 * @return {string} |
102 * @private | 114 * @private |
103 */ | 115 */ |
104 FakeDataMaker.patternMaker_ = function(pattern, base) { | 116 FakeDataMaker.patternMaker_ = function(pattern, base) { |
105 return pattern.replace(/x/g, function() { | 117 return pattern.replace(/x/g, function() { |
106 return Math.floor(Math.random() * base).toString(base); | 118 return Math.floor(Math.random() * base).toString(base); |
107 }); | 119 }); |
108 }; | 120 }; |
OLD | NEW |