Bug 1093611 - Add/modify tests making sure Link,URL,nsLocation::GetHash don't unescape characters r=smaug
authorValentin Gosu <valentin.gosu@gmail.com>
Wed, 12 Nov 2014 05:59:24 +0200
changeset 223455 948c42f9cd3a7acac6ef89c569d328ab64d1dde5
parent 223454 c270a096d97aecf4a398e675cdfc9aa36274d70b
child 223456 3d4ea993d8f01e2e7c034c1b5b3c2aba6d965978
push id28095
push usercbook@mozilla.com
push dateTue, 13 Jan 2015 13:24:48 +0000
treeherdermozilla-central@a5700bec72e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1093611
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1093611 - Add/modify tests making sure Link,URL,nsLocation::GetHash don't unescape characters r=smaug
dom/base/test/test_url.html
dom/html/test/mochitest.ini
dom/html/test/test_hash_encoded.html
dom/workers/test/urlApi_worker.js
--- a/dom/base/test/test_url.html
+++ b/dom/base/test/test_url.html
@@ -112,17 +112,17 @@
       port: '',
       pathname: '/',
       search: '?test',
       hash: ''
     },
     { url: 'http://example.com/carrot#question%3f',
       base: undefined,
       error: false,
-      hash: '#question?'
+      hash: '#question%3f'
     },
     { url: 'https://example.com:4443?',
       base: undefined,
       error: false,
       protocol: 'https:',
       port: '4443',
       pathname: '/',
       hash: '',
--- a/dom/html/test/mochitest.ini
+++ b/dom/html/test/mochitest.ini
@@ -573,10 +573,11 @@ skip-if = toolkit == 'android'
 skip-if = buildapp == 'mulet' || buildapp == 'b2g' || toolkit == 'android' || e10s # b2g(needs control of popup window size) b2g-debug(needs control of popup window size) b2g-desktop(needs control of popup window size)
 [test_non-ascii-cookie.html]
 skip-if = buildapp == 'b2g' || e10s
 [test_bug765780.html]
 [test_bug871161.html]
 skip-if = (buildapp == 'b2g' && toolkit != 'gonk') || e10s #Bug 931116, b2g desktop specific, initial triage
 support-files = file_bug871161-1.html file_bug871161-2.html
 [test_bug1013316.html]
+[test_hash_encoded.html]
 [test_bug1081037.html]
 
new file mode 100644
--- /dev/null
+++ b/dom/html/test/test_hash_encoded.html
@@ -0,0 +1,91 @@
+<!doctype html>
+<html>
+<head>
+<title>Test link.hash attribute</title>
+<script src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<a id="target1" href="http://www.example.com/#q=♥â¥#hello"></a>
+<a id="target2" href="http://www.example.com/#q=%E2%99%A5%C3%A2%C2%A5"></a>
+<a id="target3" href="http://www.example.com/#/search/%23important"></a>
+<a id="target4" href='http://www.example.com/#{"a":[13, 42], "b":{"key":"value"}}'></a>
+
+<pre id="test">
+
+<script>
+  // Tests Link::GetHash
+
+  // Check that characters aren't being encoded
+  var target = document.getElementById("target1");
+  is(target.hash, '#q=♥â¥#hello', 'Unexpected link hash');
+
+  // Check that encoded characters aren't being decoded
+  target = document.getElementById("target2");
+  is(target.hash, '#q=%E2%99%A5%C3%A2%C2%A5', 'Unexpected link hash');
+
+  // A more regular use case
+  target = document.getElementById("target3");
+  is(target.hash, '#/search/%23important', 'Unexpected link hash');
+
+  // Some JSON
+  target = document.getElementById("target4");
+  is(target.hash, '#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected link hash');
+</script>
+
+<script>
+  // Tests URL::GetHash
+
+  var url = new URL("http://www.example.com/#q=♥â¥#hello")
+  is(url.hash, '#q=♥â¥#hello', 'Unexpected url hash');
+
+  url = new URL("http://www.example.com/#q=%E2%99%A5%C3%A2%C2%A5")
+  is(url.hash, '#q=%E2%99%A5%C3%A2%C2%A5', 'Unexpected url hash');
+
+  url = new URL("http://www.example.com/#/search/%23important")
+  is(url.hash, '#/search/%23important', 'Unexpected url hash');
+
+  // Test getters and setters
+
+  url = new URL("http://www.example.com/");
+  url.hash = "#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important"
+  is(url.hash, '#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important', 'Unexpected url hash');
+
+  // codepath in nsStandardUrl::SetRef is different if the path is non-empty
+  url = new URL("http://www.example.com/test/");
+  url.hash = "#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important"
+  is(url.hash, '#q=♥â¥#hello%E2%99%A5%C3%A2%C2%A5#/search/%23important', 'Unexpected url hash');
+
+  url = new URL("http://www.example.com/");
+  url.hash = '#{"a":[13, 42], "b":{"key":"value"}}';
+  is(target.hash, '#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected url hash');
+  var parsed = JSON.parse(target.hash.substring(1));
+  is(parsed.b.key, 'value', 'JSON not parsed correctly');
+
+  url = new URL("http://www.example.com/test/");
+  url.hash = '#{"a":[13, 42], "b":{"key":"value"}}';
+  is(target.hash, '#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected url hash');
+  parsed = JSON.parse(target.hash.substring(1));
+  is(parsed.b.key, 'value', 'JSON not parsed correctly');
+</script>
+
+<script>
+  // Tests nsLocation::GetHash
+
+  window.history.pushState(1, document.title, '#q=♥â¥#hello');
+  is(location.hash,'#q=♥â¥#hello', 'Unexpected location hash');
+
+  window.history.pushState(1, document.title, '#q=%E2%99%A5%C3%A2%C2%A5');
+  is(location.hash,'#q=%E2%99%A5%C3%A2%C2%A5', 'Unexpected location hash');
+
+  window.history.pushState(1, document.title, '#/search/%23important');
+  is(location.hash,'#/search/%23important', 'Unexpected location hash');
+
+  window.history.pushState(1, document.title, '#{"a":[13, 42], "b":{"key":"value"}}');
+  is(location.hash,'#{"a":[13, 42], "b":{"key":"value"}}', 'Unexpected location hash');
+</script>
+
+</pre>
+</body>
+</html>
--- a/dom/workers/test/urlApi_worker.js
+++ b/dom/workers/test/urlApi_worker.js
@@ -106,17 +106,17 @@ onmessage = function() {
       port: '',
       pathname: '/',
       search: '?test',
       hash: ''
     },
     { url: 'http://example.com/carrot#question%3f',
       base: undefined,
       error: false,
-      hash: '#question?'
+      hash: '#question%3f'
     },
     { url: 'https://example.com:4443?',
       base: undefined,
       error: false,
       protocol: 'https:',
       port: '4443',
       pathname: '/',
       hash: '',