summaryrefslogtreecommitdiffstats
path: root/dom/svg/test/test_switch.xhtml
blob: a589a934c12efd2ebb574f3cdc6e0bc1626f741e (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
97
98
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=484176
-->
<head>
  <title>Test SVG Switch</title>
  <script src="/tests/SimpleTest/SimpleTest.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=484176">Mozilla Bug 484176</a>
<p id="display"></p>
<div id="content"></div>

<iframe id="svg" src="switch-helper.svg"></iframe>

<pre id="test">
<script class="testbody" type="text/javascript">
        <![CDATA[

SimpleTest.waitForExplicitFinish();

var test = 1;

function checkWidth(element, w) {
  var bbox = element.getBBox();
  var name = element.nodeName;

  is(bbox.width, w, test + " " + name + ".getBBox().width");
  ++test;
}

async function run() {
  try {
    // Set accept_languages to something we know
    await SpecialPowers.pushPrefEnv({"set": [["intl.accept_languages", "en-gb,en,it"]]}, run1);
  } finally {
    SimpleTest.finish();
  }
}

function run1() {
  let doc = $("svg").contentDocument;
  let s = doc.getElementById("s");
  let first = doc.getElementById("first");
  let second = doc.getElementById("second");
  let third = doc.getElementById("third");

  first.setAttribute("systemLanguage", "fr");

  /* test for an exact match */
  second.setAttribute("systemLanguage", "en-gb");
  checkWidth(s, 50);

  /* test for a close match i.e. the same language prefix */
  second.setAttribute("systemLanguage", "en");
  checkWidth(s, 50);

  /* test for a close match regardless of case */
  second.setAttribute("systemLanguage", "eN");
  checkWidth(s, 50);

  /* test that different regions don't match */
  second.setAttribute("systemLanguage", "en-us");
  checkWidth(s, 80);

  /* test that we pick the best match */
  second.setAttribute("systemLanguage", "it");
  checkWidth(s, 50);

  /* test that we use the default if nothing matches */
  second.setAttribute("systemLanguage", "fr");
  checkWidth(s, 80);

  /* test we still ignore non-matches */
  second.removeAttribute("systemLanguage");
  third.setAttribute("systemLanguage", "fr");
  checkWidth(s, 50);

  /* check what happens if nothing matches */
  second.setAttribute("systemLanguage", "fr");
  third.setAttribute("systemLanguage", "fr");
  checkWidth(s, 0);

  /* test that we pick the best match */
  first.setAttribute("systemLanguage", "en");
  second.setAttribute("systemLanguage", "en-gb");
  third.removeAttribute("systemLanguage");
  checkWidth(s, 50);
}

window.addEventListener("load", run);

]]>
</script>
</pre>
</body>
</html>