| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.--> | |
| <title>inline-style-allowed-while-cloning-objects</title> | |
| <script src="/resources/testharness.js"></script> | |
| <script src="/resources/testharnessreport.js"></script> | |
| <script src="../support/logTest.sub.js?logs=[]"></script> | |
| <script src="../support/alertAssert.sub.js?alerts=[]"></script> | |
| <!-- enforcing policy: | |
| style-src 'self'; script-src 'self' 'unsafe-inline'; connect-src 'self'; | |
| --> | |
| <script> | |
| window.onload = function() { | |
| window.nodes = document.getElementById('nodes'); | |
| window.node1 = document.getElementById('node1'); | |
| window.node1.style.background = "yellow"; | |
| window.node1.style.color = "red"; | |
| window.node2 = document.getElementById('node1').cloneNode(true); | |
| window.node2.id = "node2"; | |
| window.node3 = document.getElementById('node3'); | |
| window.node3.style.background = "blue"; | |
| window.node3.style.color = "green"; | |
| window.node4 = document.getElementById('node3').cloneNode(false); | |
| window.node4.id = "node4"; | |
| window.node4.innerHTML = "Node #4"; | |
| nodes.appendChild(node1); | |
| nodes.appendChild(node2); | |
| nodes.appendChild(node3); | |
| nodes.appendChild(node4); | |
| test(function() { | |
| assert_equals(node1.style.backgroundColor.match(/rgb\(255, 255, 0\)/)[0], "rgb(255, 255, 0)") | |
| }); | |
| test(function() { | |
| assert_equals(node2.style.backgroundColor.match(/rgb\(255, 255, 0\)/)[0], "rgb(255, 255, 0)") | |
| }); | |
| test(function() { | |
| assert_equals(node3.style.backgroundColor.match(/rgb\(0, 0, 255\)/)[0], "rgb(0, 0, 255)") | |
| }); | |
| test(function() { | |
| assert_equals(node4.style.backgroundColor.match(/rgb\(0, 0, 255\)/)[0], "rgb(0, 0, 255)") | |
| }); | |
| test(function() { | |
| assert_equals(node1.style.color.match(/rgb\(255, 0, 0\)/)[0], "rgb(255, 0, 0)") | |
| }); | |
| test(function() { | |
| assert_equals(node2.style.color.match(/rgb\(255, 0, 0\)/)[0], "rgb(255, 0, 0)") | |
| }); | |
| test(function() { | |
| assert_equals(node3.style.color.match(/rgb\(0, 128, 0\)/)[0], "rgb(0, 128, 0)") | |
| }); | |
| test(function() { | |
| assert_equals(node4.style.color.match(/rgb\(0, 128, 0\)/)[0], "rgb(0, 128, 0)") | |
| }); | |
| test(function() { | |
| assert_equals(window.getComputedStyle(node1).backgroundColor, window.getComputedStyle(node2).backgroundColor) | |
| }); | |
| test(function() { | |
| assert_equals(window.getComputedStyle(node3).backgroundColor, window.getComputedStyle(node4).backgroundColor) | |
| }); | |
| test(function() { | |
| assert_equals(window.getComputedStyle(node1).color, window.getComputedStyle(node2).color) | |
| }); | |
| test(function() { | |
| assert_equals(window.getComputedStyle(node3).color, window.getComputedStyle(node4).color) | |
| }); | |
| window.ops = document.getElementById('ops'); | |
| ops.style.color = 'red'; | |
| window.clonedOps = ops.cloneNode(true); | |
| window.violetOps = document.getElementById('violetOps'); | |
| violetOps.style.background = 'rgb(238, 130, 238)'; | |
| document.getElementsByTagName('body')[0].appendChild(clonedOps); | |
| test(function() { | |
| assert_equals(ops.style.backgroundColor, "") | |
| }); | |
| test(function() { | |
| assert_equals(ops.style.color.match(/rgb\(255, 0, 0\)/)[0], "rgb(255, 0, 0)") | |
| }); | |
| test(function() { | |
| assert_equals(clonedOps.style.backgroundColor, "") | |
| }); | |
| test(function() { | |
| assert_equals(violetOps.style.backgroundColor.match(/rgb\(238, 130, 238\)/)[0], "rgb(238, 130, 238)") | |
| }); | |
| test(function() { | |
| assert_equals(window.getComputedStyle(clonedOps).backgroundColor, window.getComputedStyle(ops).backgroundColor) | |
| }); | |
| test(function() { | |
| assert_equals(window.getComputedStyle(clonedOps).color, window.getComputedStyle(ops).color) | |
| }); | |
| test(function() { | |
| assert_not_equals(window.getComputedStyle(ops).backgroundColor, window.getComputedStyle(violetOps).backgroundColor) | |
| }); | |
| test(function() { | |
| assert_not_equals(window.getComputedStyle(clonedOps).backgroundColor, window.getComputedStyle(violetOps).backgroundColor) | |
| }); | |
| test(function() { | |
| assert_equals(ops.id, "ops") | |
| }); | |
| test(function() { | |
| assert_equals(ops.id, clonedOps.id) | |
| }); | |
| }; | |
| </script> | |
| </head> | |
| <body> | |
| <p> | |
| This test ensures that styles can be set by object.cloneNode() | |
| </p> | |
| <div id="nodes"> | |
| This is a div (nodes) | |
| <div id="node1"> This is a div. (node 1 or 2)</div> | |
| <div id="node3"> This is a div. (node 3 or 4)</div> | |
| </div> | |
| <div id="ops" style="background: rgb(238, 130, 238)"> | |
| Yet another div. | |
| </div> | |
| <div id="violetOps"> | |
| Yet another div. | |
| </div> | |
| <div id="log"></div> | |
| <script async defer src="../support/checkReport.sub.js?reportExists=true&reportField=violated-directive&reportValue=style-src%20'self'"></script> | |
| </body> | |
| </html> |