OLD | NEW |
(Empty) | |
| 1 (async function(testRunner) { |
| 2 let {page, session, dp} = await testRunner.startBlank(``); |
| 3 |
| 4 // A helper function that dumps object properties and internal properties in s
orted order. |
| 5 function logGetPropertiesResult(title, protocolResult) { |
| 6 function hasGetterSetter(property, fieldName) { |
| 7 var v = property[fieldName]; |
| 8 if (!v) |
| 9 return false; |
| 10 return v.type !== 'undefined'; |
| 11 } |
| 12 |
| 13 testRunner.log('Properties of ' + title); |
| 14 var propertyArray = protocolResult.result; |
| 15 propertyArray.sort(NamedThingComparator); |
| 16 for (var p of propertyArray) { |
| 17 var v = p.value; |
| 18 var own = p.isOwn ? 'own' : 'inherited'; |
| 19 if (v) { |
| 20 testRunner.log(' ' + p.name + ' ' + own + ' ' + v.type + ' ' + v.value)
; |
| 21 } else { |
| 22 testRunner.log(' ' + p.name + ' ' + own + ' no value' + |
| 23 (hasGetterSetter(p, 'get') ? ', getter' : '') + (hasGetterSetter(p,
'set') ? ', setter' : '')); |
| 24 } |
| 25 } |
| 26 var internalPropertyArray = protocolResult.internalProperties; |
| 27 if (internalPropertyArray) { |
| 28 testRunner.log('Internal properties'); |
| 29 internalPropertyArray.sort(NamedThingComparator); |
| 30 for (var p of internalPropertyArray) { |
| 31 var v = p.value; |
| 32 testRunner.log(' ' + p.name + ' ' + v.type + ' ' + v.value); |
| 33 } |
| 34 } |
| 35 |
| 36 function NamedThingComparator(o1, o2) { |
| 37 return o1.name === o2.name ? 0 : (o1.name < o2.name ? -1 : 1); |
| 38 } |
| 39 } |
| 40 |
| 41 async function testExpression(title, expression, ownProperties, accessorProper
tiesOnly) { |
| 42 var response = await dp.Runtime.evaluate({expression}); |
| 43 var id = response.result.result.objectId; |
| 44 response = await dp.Runtime.getProperties({objectId: id, ownProperties, acce
ssorPropertiesOnly}); |
| 45 logGetPropertiesResult(title, response.result); |
| 46 } |
| 47 |
| 48 // 'Object5' section -- check properties of '5' wrapped as object (has an int
ernal property). |
| 49 // Create an wrapper object with additional property. |
| 50 await testExpression( |
| 51 'Object(5)', |
| 52 `(function(){var r = Object(5); r.foo = 'cat';return r;})()`, |
| 53 true); |
| 54 |
| 55 // 'Not own' section -- check all properties of the object, including ones fro
m it prototype chain. |
| 56 // Create an wrapper object with additional property. |
| 57 await testExpression( |
| 58 'Not own properties', |
| 59 `({ a: 2, set b(_) {}, get b() {return 5;}, __proto__: { a: 3, c: 4, get d
() {return 6;} }})`, |
| 60 false); |
| 61 |
| 62 // 'Accessors only' section -- check only accessor properties of the object. |
| 63 // Create an wrapper object with additional property. |
| 64 await testExpression( |
| 65 'Accessor only properties', |
| 66 `({ a: 2, set b(_) {}, get b() {return 5;}, c: 'c', set d(_){} })`, |
| 67 true, |
| 68 true); |
| 69 |
| 70 // 'Array' section -- check properties of an array. |
| 71 await testExpression( |
| 72 'array', |
| 73 `['red', 'green', 'blue']`, |
| 74 true); |
| 75 |
| 76 // 'Bound' section -- check properties of a bound function (has a bunch of int
ernal properties). |
| 77 await testExpression( |
| 78 'Bound function', |
| 79 `Number.bind({}, 5)`, |
| 80 true); |
| 81 |
| 82 await testExpression( |
| 83 'Event with user defined property', |
| 84 `var e = document.createEvent('Event'); Object.defineProperty(e, 'eventPha
se', { get: function() { return 239; } })`, |
| 85 true); |
| 86 |
| 87 testRunner.completeTest(); |
| 88 }) |
OLD | NEW |