summaryrefslogtreecommitdiffstats
path: root/layout/style/test/test_bug397427.html
blob: ff0e71f238ae0f3692c0c4aebe309411a3aa7ba1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=397427
-->
<head>
  <title>Test for Bug 397427</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  <style id="a">
    @import url("redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-1.css");
    @import url("redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-2.css");
    .test { color: red }
  </style>
  <link id="b" rel="stylesheet" href="http://example.com">
  <link id="c" rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-2.css">
  <link id="d" rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-3.css">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=397427">Mozilla Bug 397427</a>
<p id="display">
<span id="one" class="test"></span>
<span id="two" class="test"></span>
<span id="three" class="test"></span>
</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 397427 **/
SimpleTest.waitForExplicitFinish();

addLoadEvent(function() {
  is($("a").sheet.href, null, "href should be null");
  is(typeof($("a").sheet.href), "object", "should be actual null");

  // Make sure the redirected sheets are loaded and have the right base URI
  is(document.defaultView.getComputedStyle($("one")).color,
     "rgb(0, 128, 0)", "Redirect 1 did not work");
  is(document.defaultView.getComputedStyle($("one")).backgroundImage,
     "url(\"http://example.org/tests/layout/style/test/post-redirect-1.css?1\")",
      "Redirect 1 did not get right base URI");
  is(document.defaultView.getComputedStyle($("two")).color,
     "rgb(0, 128, 0)", "Redirect 2 did not work");
  is(document.defaultView.getComputedStyle($("two")).backgroundImage,
     "url(\"http://example.org/tests/layout/style/test/post-redirect-2.css?1\")",
      "Redirect 2 did not get right base URI");
  is(document.defaultView.getComputedStyle($("three")).color,
     "rgb(0, 128, 0)", "Redirect 3 did not work");
  is(document.defaultView.getComputedStyle($("three")).backgroundImage,
     "url(\"http://example.org/tests/layout/style/test/post-redirect-3.css?1\")",
      "Redirect 3 did not get right base URI");

  var ruleList = $("a").sheet.cssRules;

  var redirHrefBase =
    window.location.href.replace(/test_bug397427.html$/,
      "redirect.sjs?http://example.org/tests/layout/style/test/post-");

  is(ruleList[0].styleSheet.href, redirHrefBase + "redirect-1.css",
     "Unexpected href for imported sheet");
  todo_is(ruleList[0].href, redirHrefBase + "redirect-1.css",
     "Rule href should be absolute");
  is(ruleList[1].styleSheet.href, redirHrefBase + "redirect-2.css",
     "Unexpected href for imported sheet");
  todo_is(ruleList[1].href, redirHrefBase + "redirect-2.css",
     "Rule href should be absolute");

  is($("b").href, "http://example.com/", "Unexpected href one");
  is($("b").href, $("b").sheet.href,
     "Should have the same href when not redirecting");

  is($("c").href, redirHrefBase + "redirect-2.css",
     "Unexpected href two");
  is($("c").href, $("c").sheet.href,
     "Should have the same href when redirecting");

  is($("d").href, redirHrefBase + "redirect-3.css",
     "Unexpected href three");
  is($("d").href, $("d").sheet.href,
     "Should have the same href when redirecting again");
})

addLoadEvent(SimpleTest.finish);
</script>
</pre>
</body>
</html>