From b9c6fa0e421c1c0a9f619ec16ad50a30ae4e483e Mon Sep 17 00:00:00 2001 From: pyoor Date: Fri, 30 Jun 2017 13:17:22 -0700 Subject: [PATCH 01/14] Prefix logger.comment with /*L*/ --- lib/logging/console.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logging/console.js b/lib/logging/console.js index 76dd9c8..2778b92 100644 --- a/lib/logging/console.js +++ b/lib/logging/console.js @@ -61,7 +61,7 @@ var logger = (function () { // eslint-disable-line no-unused-vars } function comment (msg) { - dumpln('/* ' + msg + ' */') + dumpln('/*L*/ /* ' + msg + ' */') } function separator () { From 272a6b614c95e8f2958f9dd00322dc13cfd91013 Mon Sep 17 00:00:00 2001 From: pyoor Date: Fri, 30 Jun 2017 13:19:03 -0700 Subject: [PATCH 02/14] Add URL object generators to make.network --- lib/make/network.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/make/network.js b/lib/make/network.js index c6a42da..37ce283 100644 --- a/lib/make/network.js +++ b/lib/make/network.js @@ -77,6 +77,24 @@ make.network = { '2001:db8::1:1:1:1:1' ] }, + 'hostname': function () { + return random.pick([this.randomIPv4, this.randomIPv6, this.goodHostnames, this.badHostnames]) + }, + 'port': function () { + return random.pick([80, 443, 21, 23, 9310]) + }, + 'hash': function () { + return random.pick(['', '#', '#main-content', function () { return '#' + make.text.any() }]) + }, + 'path': function () { + return random.pick(['', '/', '/index.html', function () { return '/' + make.text.any() }]) + }, + 'protocol': function () { + return random.pick(['http:', 'https:', 'ftp:', 'telnet:', 'chrome:', 'resource:']) + }, + 'search': function () { + return random.pick(['', '?', '?foo=bar', function () { return '?' + make.text.any() }]) + }, randomBitmask: function (list) { if (list.length <= 1) { return list.join('') From 236ccfeddb7dc5cbabdc68961698e5219459cb28 Mon Sep 17 00:00:00 2001 From: pyoor Date: Fri, 30 Jun 2017 13:19:31 -0700 Subject: [PATCH 03/14] Reduce generated string size --- lib/make/text.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/make/text.js b/lib/make/text.js index 9ebf77f..f243322 100644 --- a/lib/make/text.js +++ b/lib/make/text.js @@ -216,7 +216,7 @@ make.text = { // This might be too slow to used for all 'texts' uses let s = '' // TODO: Len calculation take from DOMFuzz - maybe we should revise this? - let len = random.number(1000) * random.number(10) + random.number(10) + let len = random.pick([make.number.tiny, make.number.range]) for (let i = 0; i < len; i++) { s += make.text.chars() } From 3a44c6065bf03f7a03b24759637981a6a75e1faa Mon Sep 17 00:00:00 2001 From: pyoor Date: Fri, 30 Jun 2017 13:21:23 -0700 Subject: [PATCH 04/14] Don't quote object properties --- lib/make/network.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/make/network.js b/lib/make/network.js index 37ce283..32973cd 100644 --- a/lib/make/network.js +++ b/lib/make/network.js @@ -77,22 +77,22 @@ make.network = { '2001:db8::1:1:1:1:1' ] }, - 'hostname': function () { + hostname: function () { return random.pick([this.randomIPv4, this.randomIPv6, this.goodHostnames, this.badHostnames]) }, - 'port': function () { + port: function () { return random.pick([80, 443, 21, 23, 9310]) }, - 'hash': function () { + hash: function () { return random.pick(['', '#', '#main-content', function () { return '#' + make.text.any() }]) }, - 'path': function () { + path: function () { return random.pick(['', '/', '/index.html', function () { return '/' + make.text.any() }]) }, - 'protocol': function () { + protocol: function () { return random.pick(['http:', 'https:', 'ftp:', 'telnet:', 'chrome:', 'resource:']) }, - 'search': function () { + search: function () { return random.pick(['', '?', '?foo=bar', function () { return '?' + make.text.any() }]) }, randomBitmask: function (list) { From 9cc22a99de896493bd34a0c773c986c27552edb5 Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 6 Jul 2017 10:18:04 -0400 Subject: [PATCH 05/14] Multiple bugfixes --- lib/make/command.js | 24 ++++++++++++------------ lib/make/time.js | 0 2 files changed, 12 insertions(+), 12 deletions(-) create mode 100644 lib/make/time.js diff --git a/lib/make/command.js b/lib/make/command.js index c92b2e3..c75cda6 100644 --- a/lib/make/command.js +++ b/lib/make/command.js @@ -6,32 +6,32 @@ make.command = { _data: { 'backcolor': function () { return make.colors.any() }, 'bold': null, - 'contentReadOnly': function () { random.bool() }, + 'contentReadOnly': function () { return random.bool() }, 'copy': null, - 'createlink': function () { make.uri.any() }, + 'createlink': function () { return make.uri.any() }, 'cut': null, 'decreasefontsize': null, 'delete': null, - 'enableInlineTableEditing': function () { random.bool() }, - 'enableObjectResizing': function () { random.bool() }, - 'fontname': function () { make.font.family() }, - 'fontsize': function () { make.font.relativeSize() }, + 'enableInlineTableEditing': function () { return random.bool() }, + 'enableObjectResizing': function () { return random.bool() }, + 'fontname': function () { return make.font.family() }, + 'fontsize': function () { return make.font.relativeSize() }, 'formatblock': ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address', 'blockquote', 'dl', 'div'], 'forwarddelete': null, - 'forecolor': function () { make.colors.any() }, + 'forecolor': function () { return make.colors.any() }, 'gethtml': null, 'heading': null, - 'hilitecolor': function () { make.colors.any() }, + 'hilitecolor': function () { return make.colors.any() }, 'increasefontsize': null, 'indent': null, - 'insertBrOnReturn': function () { random.bool() }, + 'insertBrOnReturn': function () { return random.bool() }, 'inserthorizontalrule': null, // 'inserthtml': function () { }, 'insertlinebreak': null, - 'insertimage': function () { make.uri.any() }, + 'insertimage': function () { return make.uri.any() }, 'insertorderedlist': null, 'insertparagraph': null, - 'inserttext': function () { make.text.any() }, + 'inserttext': function () { return make.text.any() }, 'insertunorderedlist': null, 'italic': null, 'justifycenter': null, @@ -44,7 +44,7 @@ make.command = { 'removeformat': null, 'selectall': null, 'strikethrough': null, - 'styleWithCSS': function () { random.bool() }, + 'styleWithCSS': function () { return random.bool() }, 'subscript': null, 'superscript': null, 'underline': null, diff --git a/lib/make/time.js b/lib/make/time.js new file mode 100644 index 0000000..e69de29 From c9a8cbf7e7cbd40888ddc3e0f94f22b5ad5876a8 Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 6 Jul 2017 10:18:22 -0400 Subject: [PATCH 06/14] Initial commit --- lib/make/time.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/make/time.js b/lib/make/time.js index e69de29..bf553e8 100644 --- a/lib/make/time.js +++ b/lib/make/time.js @@ -0,0 +1,14 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +make.time = { + unit: function () { + return random.pick([ + 's', 'ms' + ]) + }, + any: function () { + return make.number.any() + make.time.unit() + } +} From 5c6593b973ed7b061f2997e4a8be3a98ff75841e Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 6 Jul 2017 10:18:45 -0400 Subject: [PATCH 07/14] Fix eslint issue --- lib/utils/prototypes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils/prototypes.js b/lib/utils/prototypes.js index 014449e..e50d95c 100644 --- a/lib/utils/prototypes.js +++ b/lib/utils/prototypes.js @@ -69,7 +69,7 @@ Object.defineProperty(Array.prototype, 'extend', { Object.defineProperty(Object, 'isObject', { value: function (obj) { - return (obj != null && typeof obj === 'object' && + return (obj !== null && typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]') } }) From d167b49fbae195338a244094d95df804eadc63ef Mon Sep 17 00:00:00 2001 From: pyoor Date: Fri, 7 Jul 2017 11:24:09 -0400 Subject: [PATCH 08/14] Use single line comment --- lib/logging/console.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logging/console.js b/lib/logging/console.js index 2778b92..7888977 100644 --- a/lib/logging/console.js +++ b/lib/logging/console.js @@ -61,7 +61,7 @@ var logger = (function () { // eslint-disable-line no-unused-vars } function comment (msg) { - dumpln('/*L*/ /* ' + msg + ' */') + dumpln('/*L*/ // ' + msg) } function separator () { From 44d74b09bf398dba07926d04862849631813d663 Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 20 Jul 2017 10:24:57 -0400 Subject: [PATCH 09/14] Minor bug fix in creating filled arrays without a limit --- lib/make/arrays.js | 2 +- lib/make/style.js | 0 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 lib/make/style.js diff --git a/lib/make/arrays.js b/lib/make/arrays.js index c7c8dae..4590caf 100644 --- a/lib/make/arrays.js +++ b/lib/make/arrays.js @@ -5,7 +5,7 @@ make.arrays = { filledArray: function (fn, limit) { let array = [] - let size = limit || random.number(make.number.tiny) + let size = limit || random.number(make.number.tiny()) + 1 for (let i = 0; i < size; i++) { array.push(random.pick(fn)) diff --git a/lib/make/style.js b/lib/make/style.js new file mode 100644 index 0000000..e69de29 From 28254a80de578e97522074765c48b728bba44e5e Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 20 Jul 2017 15:29:37 -0400 Subject: [PATCH 10/14] Modify random.item to work with array-like objects and update tests --- lib/random/random.js | 5 +++-- tests/random/random.js | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/random/random.js b/lib/random/random.js index cac4191..9e482c1 100644 --- a/lib/random/random.js +++ b/lib/random/random.js @@ -50,10 +50,11 @@ var random = { // eslint-disable-line no-unused-vars return Math.exp(this.float() * Math.log(limit)) }, item: function (list) { - if (!(Array.isArray(list) || (list !== undefined && typeof list !== 'string' && list.hasOwnProperty('length')))) { + if (list === undefined || typeof list === 'string' || !list.hasOwnProperty('length')) { logger.traceback() - throw new TypeError('this.item() received a non array type: \'' + list + '\'') + throw new TypeError('random.item() received an invalid object: \'' + list + '\'') } + return list[this.number(list.length)] }, key: function (obj) { diff --git a/tests/random/random.js b/tests/random/random.js index b0bedc5..bc0a4eb 100644 --- a/tests/random/random.js +++ b/tests/random/random.js @@ -179,10 +179,10 @@ QUnit.test("random.ludOneTo() distribution", function(assert) { }); QUnit.test("random.item() exception cases", function(assert) { - assert.throws(random.item, /non array type/); - assert.throws(function(){ return random.item(1); }, /non array type/); - assert.throws(function(){ return random.item("1"); }, /non array type/); - assert.throws(function(){ return random.item({}); }, /non array type/); + assert.throws(random.item, /received an invalid object/); + assert.throws(function(){ return random.item(1); }, /received an invalid object/); + assert.throws(function(){ return random.item("1"); }, /received an invalid object/); + assert.throws(function(){ return random.item({}); }, /received an invalid object/); }); QUnit.test("random.item() distribution with list", function(assert) { From fa4546d8b60bc6402bdf9750257cd565223dede4 Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 20 Jul 2017 15:29:52 -0400 Subject: [PATCH 11/14] Initial commit of make.style --- lib/make/style.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/make/style.js b/lib/make/style.js index e69de29..ad24b1c 100644 --- a/lib/make/style.js +++ b/lib/make/style.js @@ -0,0 +1,16 @@ +make.style = { + pseudoElement: function () { + return random.item([ + '::after', + '::before', + '::cue', + '::first-letter', + '::first-line', + '::selection', + '::backdrop', + '::placeholder', + '::marker', + '::spelling-error', + '::grammar-error']) + } +} From a1aab622560b1d11215518c80b8c76d00eb280d7 Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 20 Jul 2017 15:30:11 -0400 Subject: [PATCH 12/14] Favor lower numbers in make.number.any() --- lib/make/numbers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/make/numbers.js b/lib/make/numbers.js index f7dfded..63c35bb 100644 --- a/lib/make/numbers.js +++ b/lib/make/numbers.js @@ -41,7 +41,7 @@ make.number = { if (random.chance(2)) { return Math.abs(make.number.any()) } - return Math.pow(2, random.number(65)) + random.number(3) - 1 + return Math.pow(2, random.number(random.number(65))) + random.number(3) - 1 }, even: function (number) { return number % 2 === 1 ? ++number : number From 2d36bb0739ba9128c69350c940336e251e58300f Mon Sep 17 00:00:00 2001 From: pyoor Date: Thu, 20 Jul 2017 15:37:20 -0400 Subject: [PATCH 13/14] Fix random.item to accomodate DOMStringList --- lib/random/random.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/random/random.js b/lib/random/random.js index 9e482c1..3811eef 100644 --- a/lib/random/random.js +++ b/lib/random/random.js @@ -50,7 +50,7 @@ var random = { // eslint-disable-line no-unused-vars return Math.exp(this.float() * Math.log(limit)) }, item: function (list) { - if (list === undefined || typeof list === 'string' || !list.hasOwnProperty('length')) { + if (list === undefined || typeof list === 'string' || list.length === undefined) { logger.traceback() throw new TypeError('random.item() received an invalid object: \'' + list + '\'') } From bbb579b2b9e2849e52f1bd43ab2a700e12f0b958 Mon Sep 17 00:00:00 2001 From: pyoor Date: Fri, 21 Jul 2017 14:05:40 -0400 Subject: [PATCH 14/14] Check for undefined values when making filled arrays --- lib/make/arrays.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/make/arrays.js b/lib/make/arrays.js index 4590caf..50a25a6 100644 --- a/lib/make/arrays.js +++ b/lib/make/arrays.js @@ -8,7 +8,10 @@ make.arrays = { let size = limit || random.number(make.number.tiny()) + 1 for (let i = 0; i < size; i++) { - array.push(random.pick(fn)) + let value = random.pick(fn) + if (value !== undefined) { + array.push(value) + } } return array