summaryrefslogtreecommitdiffstats
path: root/LayoutTests/fast/dom/HTMLAnchorElement/script-tests/set-href-attribute-search.js
blob: 5b90a04abfc61561699ad324b827e6097cabacab (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
description('Test setting the search attribute of the URL in HTMLAnchorElement .');

var a = document.createElement('a');

debug("Set search without '?'");
a.href = "https://www.mydomain.com/path/?key=value";
a.search = "value=key";
shouldBe("a.href", "'https://www.mydomain.com/path/?value=key'");

// IE8 does not encode spaces in search string
debug("Set search that starts with '?' and contains spaces");
a.href = "https://www.mydomain.com/path/?key=value";
a.search = "?val ue= key?";
shouldBe("a.href", "'https://www.mydomain.com/path/?val%20ue=%20key?'");

debug("Set search to a malformed URL");
a.href = "s:www.mydomain.com/path/";
a.search = "%";
shouldBe("a.href", "'s:www.mydomain.com/path/?%'");

// IE8 throws "The URL is invalid" exception.
debug("Set search containing '#'");
try {
a.href = "https://www.mydomain.com/path/?key=value#hash";
a.search = "?value#key";
shouldBe("a.href", "'https://www.mydomain.com/path/?value%23key#hash'");
} catch(e) {
debug("Exception: " + e.description);
}

debug("Set search to a malformed URL");
a.href = "bad:/|/url";
a.search = "?value=key";
shouldBe("a.href", "'bad:/|/url?value=key'");

// IE8 converts null to "null", which is not the right thing to do.
debug("Set search to null");
a.href = "https://www.mydomain.com/path/?key=value";
a.search = null;
shouldBe("a.href", "'https://www.mydomain.com/path/'");

// Firefox 3.5.2 Removes the '?', and it shouldn't, per
// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
debug("Set search to empty string");
a.href = "https://www.mydomain.com/path/?key=value";
a.search = "";
shouldBe("a.href", "'https://www.mydomain.com/path/?'");

var successfullyParsed = true;