stylesheet-same-origin.sub.html (3893B)
1 <!doctype html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>CSSOM - CSSStylesheet should support origins</title> 6 <link rel="help" href="https://drafts.csswg.org/cssom/#the-cssstylesheet-interface"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 10 <link id="crossorigin" href="http://www1.{{host}}:{{ports[http][1]}}/css/cssom/stylesheet-same-origin.css" rel="stylesheet"> 11 <link id="sameorigin" href="stylesheet-same-origin.css" rel="stylesheet"> 12 <link id="sameorigindata" href="data:text/css,.green-text{color:rgb(0, 255, 0)}" rel="stylesheet"> 13 <link id="redirect-sameorigin-to-crossorigin" 14 href="/common/redirect.py?location=http://www1.{{host}}:{{ports[http][1]}}/css/cssom/stylesheet-same-origin.css" 15 rel="stylesheet"> 16 <link id="redirect-crossorigin-to-sameorigin" 17 href="http://www1.{{host}}:{{ports[http][1]}}/common/redirect.py?location=http://{{host}}:{{ports[http][0]}}/css/cssom/stylesheet-same-origin.css" 18 rel="stylesheet"> 19 <link id="loaderror" href="support/malformed-http-response.asis" rel="stylesheet"> 20 21 <script> 22 var crossorigin = document.getElementById("crossorigin").sheet; 23 var redirectSameOriginToCrossOrigin = document.getElementById("redirect-sameorigin-to-crossorigin").sheet; 24 var redirectCrossOriginToSameOrigin = document.getElementById("redirect-crossorigin-to-sameorigin").sheet; 25 var loadError = document.getElementById("loaderror").sheet; 26 var sameorigin = document.getElementById("sameorigin").sheet; 27 var sameorigindata = document.getElementById("sameorigindata").sheet; 28 29 function doOriginCleanCheck(sheet, name) { 30 assert_equals(sheet.cssRules.length, 1, name + " stylesheet.cssRules should be accessible."); 31 sheet.insertRule("#test { margin: 10px; }", 1); 32 assert_equals(sheet.cssRules.length, 2, name + " stylesheet.insertRule should be accessible."); 33 sheet.deleteRule(0); 34 assert_equals(sheet.cssRules.length, 1, name + " stylesheet.deleteRule should be accessible."); 35 } 36 37 function doOriginDirtyCheck(sheet) { 38 assert_throws_dom("SecurityError", 39 function () { 40 sheet.cssRules; 41 }, 42 'stylesheet.cssRules should throw SecurityError.'); 43 assert_throws_dom("SecurityError", 44 function () { 45 sheet.insertRule("#test { margin: 10px; }", 1); 46 }, 47 'stylesheet.insertRule should throw SecurityError.'); 48 49 assert_throws_dom("SecurityError", 50 function () { 51 sheet.deleteRule(0); 52 }, 53 'stylesheet.deleteRule should throw SecurityError.'); 54 } 55 56 test(function() { 57 doOriginDirtyCheck(crossorigin); 58 }, "Origin-clean check in cross-origin CSSOM Stylesheets"); 59 60 test(function() { 61 doOriginDirtyCheck(redirectSameOriginToCrossOrigin); 62 }, "Origin-clean check in cross-origin CSSOM Stylesheets (redirect from same-origin to cross-origin)"); 63 64 test(function() { 65 doOriginDirtyCheck(redirectCrossOriginToSameOrigin); 66 }, "Origin-clean check in cross-origin CSSOM Stylesheets (redirect from cross-origin to same-origin)"); 67 68 test(function() { 69 doOriginDirtyCheck(loadError); 70 }, "Origin-clean check in loading error CSSOM Stylesheets"); 71 72 test(function() { 73 doOriginCleanCheck(sameorigin, "Same-origin"); 74 }, "Origin-clean check in same-origin CSSOM Stylesheets"); 75 76 test(function() { 77 doOriginCleanCheck(sameorigindata, "data:css"); 78 }, "Origin-clean check in data:css CSSOM Stylesheets"); 79 80 </script> 81 </head> 82 <body> 83 </html>