Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=515401 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 515401</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 10 | <base id=basehref href="base/"> |
michael@0 | 11 | <base id=basehref2> |
michael@0 | 12 | <base id=basetarget target="def_target"> |
michael@0 | 13 | </head> |
michael@0 | 14 | <body> |
michael@0 | 15 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=515401">Mozilla Bug 515401</a> |
michael@0 | 16 | <a id=a href="dest.html">Simple link</a> |
michael@0 | 17 | <a id=awtarget target="a_target">Link with target</a> |
michael@0 | 18 | |
michael@0 | 19 | <p id="display"></p> |
michael@0 | 20 | <pre id="test"> |
michael@0 | 21 | <script class="testbody" type="text/javascript"> |
michael@0 | 22 | |
michael@0 | 23 | var a = $('a'); |
michael@0 | 24 | var awtarget = $('awtarget'); |
michael@0 | 25 | var head = document.documentElement.firstElementChild; |
michael@0 | 26 | |
michael@0 | 27 | // Test targets |
michael@0 | 28 | is(a.target, "def_target", "using default target"); |
michael@0 | 29 | is(awtarget.target, "a_target", "specified target"); |
michael@0 | 30 | $('basetarget').setAttribute("target", "new_def_target"); |
michael@0 | 31 | is(a.target, "new_def_target", "using new default target"); |
michael@0 | 32 | is(awtarget.target, "a_target", "still specified target"); |
michael@0 | 33 | $('basetarget').removeAttribute("target"); |
michael@0 | 34 | is(a.target, "", "no target"); |
michael@0 | 35 | is(awtarget.target, "a_target", "yet still specified target"); |
michael@0 | 36 | newbasetarget = document.createElement('base'); |
michael@0 | 37 | newbasetarget.target = "new_target_elem"; |
michael@0 | 38 | head.appendChild(newbasetarget); |
michael@0 | 39 | is(a.target, "new_target_elem", "new target element"); |
michael@0 | 40 | is(awtarget.target, "a_target", "yet still specified target"); |
michael@0 | 41 | newbasetarget.target = "new_target_elem_value"; |
michael@0 | 42 | is(a.target, "new_target_elem_value", "new target element attribute"); |
michael@0 | 43 | is(awtarget.target, "a_target", "yet still specified target"); |
michael@0 | 44 | newbasetarget.target = ""; |
michael@0 | 45 | is(a.target, "", "new target element no attribute"); |
michael@0 | 46 | is(awtarget.target, "a_target", "yet still specified target"); |
michael@0 | 47 | |
michael@0 | 48 | |
michael@0 | 49 | // link hrefs |
michael@0 | 50 | var basehref = $('basehref'); |
michael@0 | 51 | var basehref2 = $('basehref2'); |
michael@0 | 52 | var pre = "http://mochi.test:8888/tests/content/base/test/"; |
michael@0 | 53 | function verifyBase(base, test) { |
michael@0 | 54 | if (base == "") { |
michael@0 | 55 | is(document.baseURI, document.URL, "document base when " + test); |
michael@0 | 56 | is(a.href, pre + "dest.html", "link href when " + test); |
michael@0 | 57 | } |
michael@0 | 58 | else { |
michael@0 | 59 | is(document.baseURI, pre + base, "document base when " + test); |
michael@0 | 60 | is(a.href, pre + base + "dest.html", "link href when " + test); |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | |
michael@0 | 65 | // In document base |
michael@0 | 66 | verifyBase("base/", "from markup"); |
michael@0 | 67 | |
michael@0 | 68 | // Modify existing <base> |
michael@0 | 69 | basehref.href = "base2/"; |
michael@0 | 70 | verifyBase("base2/", "modify existing"); |
michael@0 | 71 | is(basehref.href, pre + "base2/", "HTMLBaseElement.href resolves correctly"); |
michael@0 | 72 | |
michael@0 | 73 | // Modify existing <base> to absolute url |
michael@0 | 74 | basehref.href = "http://www.example.com/foo/bar.html"; |
michael@0 | 75 | is(document.baseURI, "http://www.example.com/foo/bar.html", "document base when setting absolute url"); |
michael@0 | 76 | is(a.href, "http://www.example.com/foo/dest.html", "link href when setting absolute url"); |
michael@0 | 77 | is(basehref.href, "http://www.example.com/foo/bar.html", |
michael@0 | 78 | "HTMLBaseElement.href resolves correctly when setting absolute url"); |
michael@0 | 79 | |
michael@0 | 80 | // Remove href on existing element |
michael@0 | 81 | basehref.removeAttribute("href"); |
michael@0 | 82 | verifyBase("", "remove href on existing element"); |
michael@0 | 83 | |
michael@0 | 84 | // Create href on existing element |
michael@0 | 85 | basehref.href = "base3/"; |
michael@0 | 86 | verifyBase("base3/", "create href on existing element"); |
michael@0 | 87 | |
michael@0 | 88 | // Fall back to second after remove attr |
michael@0 | 89 | basehref2.href = "base4/"; |
michael@0 | 90 | verifyBase("base3/", "add href on second base"); |
michael@0 | 91 | basehref.removeAttribute("href"); |
michael@0 | 92 | verifyBase("base4/", "fall back to second after remove attr"); |
michael@0 | 93 | |
michael@0 | 94 | // Set href on existing again |
michael@0 | 95 | basehref.href = "base5/"; |
michael@0 | 96 | verifyBase("base5/", "set href on existing again"); |
michael@0 | 97 | |
michael@0 | 98 | // Unset href on second |
michael@0 | 99 | basehref2.removeAttribute("href"); |
michael@0 | 100 | verifyBase("base5/", "unset href on second"); |
michael@0 | 101 | |
michael@0 | 102 | // Insert base with href before existing |
michael@0 | 103 | var basehref0 = document.createElement("base"); |
michael@0 | 104 | basehref0.href = "base6/"; |
michael@0 | 105 | verifyBase("base5/", "nothing modified"); |
michael@0 | 106 | head.insertBefore(basehref0, head.firstChild); |
michael@0 | 107 | verifyBase("base6/", "insert base with href before existing"); |
michael@0 | 108 | |
michael@0 | 109 | // Insert base as grandchild of head |
michael@0 | 110 | var basehref3 = document.createElement("base"); |
michael@0 | 111 | basehref3.href = "base7/"; |
michael@0 | 112 | var tmp = document.createElement("head"); |
michael@0 | 113 | tmp.appendChild(basehref3); |
michael@0 | 114 | head.insertBefore(tmp, head.firstChild); |
michael@0 | 115 | verifyBase("base7/", "inserted base as grandchild of head at the beginning of head"); |
michael@0 | 116 | is(basehref3.parentNode.parentNode, head, "base got inserted correctly"); |
michael@0 | 117 | |
michael@0 | 118 | // Remove secondary bases |
michael@0 | 119 | var tmp, tmp2; |
michael@0 | 120 | for (tmp = head.firstChild; tmp = tmp.nextSibling; tmp) { |
michael@0 | 121 | if (tmp.localName == "base" && tmp != basehref0) { |
michael@0 | 122 | tmp2 = tmp.previousSibling; |
michael@0 | 123 | head.removeChild(tmp); |
michael@0 | 124 | tmp = tmp2; |
michael@0 | 125 | } |
michael@0 | 126 | verifyBase("base7/", "remove unneeded base"); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | // Remove head |
michael@0 | 130 | document.documentElement.removeChild(head); |
michael@0 | 131 | verifyBase("", "removed head"); |
michael@0 | 132 | |
michael@0 | 133 | // Insert base in body |
michael@0 | 134 | document.body.insertBefore(basehref3, document.body.firstChild); |
michael@0 | 135 | verifyBase("base7/", "inserted base in body"); |
michael@0 | 136 | |
michael@0 | 137 | </script> |
michael@0 | 138 | </pre> |
michael@0 | 139 | </body> |
michael@0 | 140 | </html> |
michael@0 | 141 |