| 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 expirationMonth = now.getMonth() + 1; |
| 76 var ret = {}; |
| 77 ret.expirationMonth = expirationMonth.toString() |
| 78 ret.expirationYear = now.getFullYear().toString(); |
| 79 return ret; |
| 80 }; |
| 81 |
| 82 /** |
| 70 * Creates a new random credit card entry for testing. | 83 * Creates a new random credit card entry for testing. |
| 71 * @return {!chrome.autofillPrivate.CreditCardEntry} | 84 * @return {!chrome.autofillPrivate.CreditCardEntry} |
| 72 */ | 85 */ |
| 73 FakeDataMaker.creditCardEntry = function() { | 86 FakeDataMaker.creditCardEntry = function() { |
| 74 var ret = {}; | 87 var ret = {}; |
| 75 ret.guid = FakeDataMaker.makeGuid_(); | 88 ret.guid = FakeDataMaker.makeGuid_(); |
| 76 ret.name = 'Jane Doe'; | 89 ret.name = 'Jane Doe'; |
| 77 ret.cardNumber = FakeDataMaker.patternMaker_('xxxx xxxx xxxx xxxx', 10); | 90 ret.cardNumber = FakeDataMaker.patternMaker_('xxxx xxxx xxxx xxxx', 10); |
| 78 ret.expirationMonth = Math.ceil(Math.random() * 11).toString(); | 91 ret.expirationMonth = Math.ceil(Math.random() * 11).toString(); |
| 79 ret.expirationYear = (2016 + Math.floor(Math.random() * 5)).toString(); | 92 ret.expirationYear = (2016 + Math.floor(Math.random() * 5)).toString(); |
| 80 ret.metadata = {isLocal: true}; | 93 ret.metadata = {isLocal: true}; |
| 81 var cards = ['Visa', 'Mastercard', 'Discover', 'Card']; | 94 var cards = ['Visa', 'Mastercard', 'Discover', 'Card']; |
| 82 var card = cards[Math.floor(Math.random() * cards.length)]; | 95 var card = cards[Math.floor(Math.random() * cards.length)]; |
| 83 ret.metadata.summaryLabel = card + ' ' + '****' + ret.cardNumber.substr(-4); | 96 ret.metadata.summaryLabel = card + ' ' + '****' + ret.cardNumber.substr(-4); |
| 84 return ret; | 97 return ret; |
| 85 }; | 98 }; |
| 86 | 99 |
| 87 /** | 100 /** |
| 88 * Creates a new random GUID for testing. | 101 * Creates a new random GUID for testing. |
| 89 * @return {!string} | 102 * @return {string} |
| 90 * @private | 103 * @private |
| 91 */ | 104 */ |
| 92 FakeDataMaker.makeGuid_ = function() { | 105 FakeDataMaker.makeGuid_ = function() { |
| 93 return FakeDataMaker.patternMaker_( | 106 return FakeDataMaker.patternMaker_( |
| 94 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 16); | 107 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 16); |
| 95 }; | 108 }; |
| 96 | 109 |
| 97 /** | 110 /** |
| 98 * Replaces any 'x' in a string with a random number of the base. | 111 * 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. | 112 * @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. | 113 * @param {number} base The number base. ie: 16 for hex or 10 for decimal. |
| 101 * @return {!string} | 114 * @return {string} |
| 102 * @private | 115 * @private |
| 103 */ | 116 */ |
| 104 FakeDataMaker.patternMaker_ = function(pattern, base) { | 117 FakeDataMaker.patternMaker_ = function(pattern, base) { |
| 105 return pattern.replace(/x/g, function() { | 118 return pattern.replace(/x/g, function() { |
| 106 return Math.floor(Math.random() * base).toString(base); | 119 return Math.floor(Math.random() * base).toString(base); |
| 107 }); | 120 }); |
| 108 }; | 121 }; |
| OLD | NEW |