This commit is contained in:
Christoph Diehl 2017-08-08 12:47:11 +02:00
commit c5824a4083
11 changed files with 76 additions and 24 deletions

View File

@ -61,7 +61,7 @@ var logger = (function () { // eslint-disable-line no-unused-vars
}
function comment (msg) {
dumpln('/* ' + msg + ' */')
dumpln('/*L*/ // ' + msg)
}
function separator () {

View File

@ -5,10 +5,13 @@
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))
let value = random.pick(fn)
if (value !== undefined) {
array.push(value)
}
}
return array

View File

@ -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,

View File

@ -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('')

View File

@ -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

16
lib/make/style.js Normal file
View File

@ -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'])
}
}

View File

@ -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()
}

14
lib/make/time.js Normal file
View File

@ -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()
}
}

View File

@ -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.length === undefined) {
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) {

View File

@ -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]')
}
})

View File

@ -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) {