summaryrefslogtreecommitdiffstats
path: root/dom/svg/test/test_a_href_01.xhtml
blob: a1ff8d7227dee8844ee4dfec1862aa2b3a22c92a (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
92
93
94
95
96
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=620295
https://bugzilla.mozilla.org/show_bug.cgi?id=1245751
-->
<head>
  <title>Test that activating SVG 'a' elements navigate to their xlink:href or href</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620295">Mozilla Bug 620295</a>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1245751">Mozilla Bug 1245751</a>
<p id="display"></p>
<pre id="test">
<script class="testbody" type="text/javascript"><![CDATA[

SimpleTest.waitForExplicitFinish();

var testCount = 7;
var didWindowLoad = false;
var frameLoadCount = 0;
var navigationCount = 0;

function endsWith(s1, s2) {
  s1 = String(s1);
  return s1.length >= s2.length && s1.substring(s1.length - s2.length) == s2;
}

function windowLoaded() {
  didWindowLoad = true;
  doNavigationIfReady();
}

function frameLoaded() {
  frameLoadCount++;
  doNavigationIfReady();
}

function doNavigationIfReady() {
  if (didWindowLoad && frameLoadCount == testCount) {
    doNavigation();
  }
}

function doNavigation() {
  // Test clicking on an unmodified <a>.
  doNavigationTest(1, "a_href_helper_01.svg");
  // Test clicking on an <a> whose xlink:href is modified by assigning to href.baseVal.
  doNavigationTest(2, "a_href_helper_02_03.svg", function(a) { a.href.baseVal = "a_href_destination.svg"; });
  // Test clicking on an <a> whose xlink:href is modified by a setAttributeNS call.
  doNavigationTest(3, "a_href_helper_02_03.svg", function(a) { a.setAttributeNS("http://www.w3.org/1999/xlink", "xlink:href", "a_href_destination.svg"); });
  // Test clicking on an <a> whose xlink:href is modified by animation.
  doNavigationTest(4, "a_href_helper_04.svg");
  // Test clicking on an unmodified <a> with both href and xlink:href.
  doNavigationTest(5, "a_href_helper_05.svg");
  // Test clicking on an <a> whose href is modified by a setAttribute call.
  doNavigationTest(6, "a_href_helper_06.svg", function(a) { a.setAttribute("href", "a_href_destination.svg"); });
  // Test clicking on an <a> whose href is modified by animation.
  doNavigationTest(7, "a_href_helper_07.svg");
}

function doNavigationTest(testNumber, initialHref, f) {
  var iframe = document.getElementById("iframe" + testNumber);
  var a = iframe.contentDocument.getElementById("a");
  ok(endsWith(iframe.contentWindow.location, initialHref), "Initial href of test " + testNumber);
  is("pointer", window.getComputedStyle(a).getPropertyValue("cursor"), "expected pointer cursor");
  iframe.onload = function() {
    ok(endsWith(iframe.contentWindow.location, "a_href_destination.svg"), "Final href of test " + testNumber);
    if (++navigationCount == testCount) {
      SimpleTest.finish();
    }
  };
  if (f) {
    f(a);
  }
  sendMouseEvent({type: "click"}, a);
}

window.onload = windowLoaded;

]]></script>
</pre>
<div id="content" style="visibility: hidden">
<!-- These must come after frameLoaded is defined -->
<iframe id="iframe1" src="a_href_helper_01.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe2" src="a_href_helper_02_03.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe3" src="a_href_helper_02_03.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe4" src="a_href_helper_04.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe5" src="a_href_helper_05.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe6" src="a_href_helper_06.svg" onload="frameLoaded()"></iframe>
<iframe id="iframe7" src="a_href_helper_07.svg" onload="frameLoaded()"></iframe>
</div>
</body>
</html>