1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_declare_stylesheet_obsolete.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=713564 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 713564</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 + 1.15 + <!-- Load the variable stylesheet, which changes the color of #content. --> 1.16 + <link rel="stylesheet" type="text/css" href="variable_style_sheet.sjs"/> 1.17 + 1.18 + <script type="application/javascript"> 1.19 + 1.20 + function insertLinkToVarSSAndRun(callback) { 1.21 + var ss = document.createElement("link"); 1.22 + ss.rel = "stylesheet"; 1.23 + ss.type = "text/css"; 1.24 + ss.href = "variable_style_sheet.sjs"; 1.25 + document.getElementsByTagName("head")[0].appendChild(ss); 1.26 + ss.addEventListener("load", callback); 1.27 + } 1.28 + 1.29 + /** Test for Bug 713564 **/ 1.30 + 1.31 + // Then you link to that sheet, remove the link from the DOM, insert a new link to 1.32 + // the same url and check that there was no new access, then call our new method, 1.33 + // insert _another_ <link> to the same url, and check that this time we hit the 1.34 + // server. 1.35 + SimpleTest.waitForExplicitFinish(); 1.36 + 1.37 + function do_test() { 1.38 + var var_sheet = document.getElementsByTagName("link")[1]; 1.39 + var head = document.getElementsByTagName("head")[0]; 1.40 + var content = document.getElementById("content"); 1.41 + var var_sheet_url = var_sheet.href; 1.42 + 1.43 + var previousBgColor = window.getComputedStyle(content). 1.44 + getPropertyValue("background-color"); 1.45 + var_sheet.parentNode.removeChild(var_sheet); 1.46 + insertLinkToVarSSAndRun(function() { 1.47 + is(window.getComputedStyle(content).getPropertyValue("background-color"), 1.48 + previousBgColor, 1.49 + "Sheet should still be the same."); 1.50 + 1.51 + // Obsolete sheet 1.52 + try { 1.53 + SpecialPowers.wrap(document).obsoleteSheet(var_sheet_url); 1.54 + } catch (e) { 1.55 + ok(false, "obsoleteSheet should not raise an error on valid URL."); 1.56 + } 1.57 + insertLinkToVarSSAndRun(function() { 1.58 + isnot(window.getComputedStyle(content).getPropertyValue("background-color"), 1.59 + previousBgColor, 1.60 + "Sheet should change after obsoleted and reinserted."); 1.61 + SimpleTest.finish(); 1.62 + }); 1.63 + }); 1.64 + // obsoleteSheet should throw with invalid input: 1.65 + try { 1.66 + SpecialPowers.wrap(document).obsoleteSheet(""); 1.67 + ok(false, "obsoleteSheet should throw with empty string."); 1.68 + } catch (e) { 1.69 + ok(true, "obsoleteSheet throws with empty string."); 1.70 + } 1.71 + try { 1.72 + SpecialPowers.wrap(document).obsoleteSheet("foo"); 1.73 + ok(false, "obsoleteSheet should throw with invalid URL."); 1.74 + } catch (e) { 1.75 + ok(true, "obsoleteSheet throws with invalid URL."); 1.76 + } 1.77 + try { 1.78 + SpecialPowers.wrap(document).obsoleteSheet("http://www.mozilla.org"); 1.79 + ok(true, "obsoleteSheet should not throw with valid URL."); 1.80 + } catch (e) { 1.81 + ok(false, "obsoleteSheet throws with valid URL."); 1.82 + } 1.83 + } 1.84 + 1.85 + </script> 1.86 +</head> 1.87 +<body onload="do_test();"> 1.88 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=713564">Mozilla Bug 713564</a> 1.89 +<p id="display"></p> 1.90 +<div id="content"> 1.91 + <br> 1.92 + <br> 1.93 +</div> 1.94 +<pre id="test"> 1.95 +</pre> 1.96 +</body> 1.97 +</html>