OLD | NEW |
1 // Test runner for the paint worklet. | 1 // Test runner for the paint worklet. |
2 // | 2 // |
3 // Calls a given function with a newly created element, and prints the expected | 3 // Calls a given function with a newly created element, and prints the expected |
4 // geometry to the console. | 4 // geometry to the console. |
5 // | 5 // |
6 // Runs each test sequentially after a layout and a paint. | 6 // Runs each test sequentially after a layout and a paint. |
7 // | 7 // |
8 // Usage: | 8 // Usage: |
9 // testRunnerGeometryLogging([{ | 9 // testRunnerGeometryLogging([{ |
10 // func: function(el) { | 10 // func: function(el) { |
11 // el.style.width = '100px'; | 11 // el.style.width = '100px'; |
12 // el.style.height = '100px'; | 12 // el.style.height = '100px'; |
13 // }, | 13 // }, |
14 // expected: {width: 100, height: 100}, | 14 // expected: {width: 100, height: 100}, |
15 // ]); | 15 // ]); |
16 | 16 |
17 function testRunnerGeometryLogging(tests, workletCode) { | 17 function testRunnerGeometryLogging(tests, workletCode) { |
18 if (window.testRunner) { | 18 if (window.testRunner) { |
19 testRunner.waitUntilDone(); | 19 testRunner.waitUntilDone(); |
20 testRunner.dumpAsText(); | 20 testRunner.dumpAsText(); |
21 } | 21 } |
22 | 22 |
23 paintWorklet.import('resources/paint-logging-green.js').then(function() { | 23 paintWorklet.addModule('resources/paint-logging-green.js').then(function() { |
24 tests.reduce(function(chain, obj) { | 24 tests.reduce(function(chain, obj) { |
25 return chain.then(function() { | 25 return chain.then(function() { |
26 console.log('The worklet should log: \'width: ' + obj.expected.w
idth + ', height: ' + obj.expected.height + '\''); | 26 console.log('The worklet should log: \'width: ' + obj.expected.w
idth + ', height: ' + obj.expected.height + '\''); |
27 var el = document.createElement('div'); | 27 var el = document.createElement('div'); |
28 document.body.appendChild(el); | 28 document.body.appendChild(el); |
29 obj.func(el); | 29 obj.func(el); |
30 return new Promise(function(resolve) { | 30 return new Promise(function(resolve) { |
31 runAfterLayoutAndPaint(function() { | 31 runAfterLayoutAndPaint(function() { |
32 document.body.removeChild(el); | 32 document.body.removeChild(el); |
33 resolve(); | 33 resolve(); |
34 }); | 34 }); |
35 }); | 35 }); |
36 }); | 36 }); |
37 }, Promise.resolve()).then(function() { | 37 }, Promise.resolve()).then(function() { |
38 if (window.testRunner) { | 38 if (window.testRunner) { |
39 testRunner.notifyDone(); | 39 testRunner.notifyDone(); |
40 } | 40 } |
41 }); | 41 }); |
42 }); | 42 }); |
43 } | 43 } |
OLD | NEW |