Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / paint / invalidation / spv2 / resources / paint-invalidation-test.js
blobf1e1c8d331ed87bafcde90ea426cf66cbe27a508
1 // Asynchronous tests should manually call finishPaintInvalidationTest at the appropriate time.
2 window.testIsAsync = false;
4 // All paint invalidation tests are asynchronous from test-runner's point of view.
5 if (window.testRunner)
6 testRunner.waitUntilDone();
8 function runPaintInvalidationTest()
10 if (!window.testRunner || !window.internals) {
11 setTimeout(paintInvalidationTest, 500);
12 return;
15 // TODO(enne): this is a workaround for multiple svg onload events.
16 // See: http://crbug.com/372946
17 if (window.hasRunPaintInvalidationTest)
18 return;
19 window.hasRunPaintInvalidationTest = true;
21 testRunner.layoutAndPaintAsyncThen(function()
23 window.internals.startTrackingPaintInvalidationObjects();
24 paintInvalidationTest();
25 if (!window.testIsAsync)
26 finishPaintInvalidationTest();
27 });
30 function removeAllChildren(element)
32 while (element.firstChild)
33 element.removeChild(element.firstChild);
36 function finishPaintInvalidationTest()
38 if (!window.testRunner || !window.internals)
39 return;
41 testRunner.layoutAndPaintAsyncThen(function()
43 var paintInvalidationObjects = JSON.stringify(internals.trackedPaintInvalidationObjects());
44 var expectedPaintInvalidationObjects = JSON.stringify(window.expectedPaintInvalidationObjects);
45 internals.stopTrackingPaintInvalidationObjects();
47 if (paintInvalidationObjects != expectedPaintInvalidationObjects) {
48 testRunner.logToStderr('Paint invalidation objects mismatch.'
49 + '\nExpected:\n' + expectedPaintInvalidationObjects.replace(/","/g, '",\n "')
50 + '\nActual:\n' + paintInvalidationObjects.replace(/","/g, '",\n "'));
52 if (document.rootElement && document.rootElement.nodeName == "svg") {
53 var svgns = "http://www.w3.org/2000/svg"
54 var rect = document.createElementNS(svgns, 'rect');
55 rect.setAttribute('width', '45%');
56 rect.setAttribute('height', '10%');
57 rect.setAttribute('x', '55%');
58 rect.setAttribute('fill', 'white');
59 rect.setAttribute('stroke', 'black');
60 rect.setAttribute('stroke-width', '1px');
61 document.documentElement.appendChild(rect);
62 var text = document.createElementNS(svgns, 'text');
63 text.setAttribute('x', '100%');
64 text.setAttribute('y', '5%');
65 text.setAttribute('text-anchor', 'end');
66 text.textContent = "Paint invalidation objects mismatch. See stderr for details.";
67 document.documentElement.appendChild(text);
68 } else {
69 var div = document.createElement('div');
70 div.style.zIndex = '2147483647';
71 div.style.visibility = 'visible';
72 div.style.position = 'fixed';
73 div.style.top = '0';
74 div.style.right = '0';
75 div.style.width = '350px';
76 div.style.height = '16px';
77 div.style.color = 'black';
78 div.style.fontSize = '12px';
79 div.style.lineHeight = '14px';
80 div.style.fontFamily = 'Arial';
81 div.style.border = '1px solid black';
82 div.style.background = 'white';
83 div.appendChild(document.createTextNode('Paint invalidation objects mismatch. See stderr for details.'));
84 document.body.appendChild(div);
88 testRunner.notifyDone();
89 });