1description('Test setting the search attribute of the URL in HTMLAnchorElement .');
2
3var a = document.createElement('a');
4
5debug("Set search without '?'");
6a.href = "https://www.mydomain.com/path/?key=value";
7a.search = "value=key";
8shouldBe("a.href", "'https://www.mydomain.com/path/?value=key'");
9
10// IE8 does not encode spaces in search string
11debug("Set search that starts with '?' and contains spaces");
12a.href = "https://www.mydomain.com/path/?key=value";
13a.search = "?val ue= key?";
14shouldBe("a.href", "'https://www.mydomain.com/path/?val%20ue=%20key?'");
15
16debug("Set search to a malformed URL");
17a.href = "s:www.mydomain.com/path/";
18a.search = "%";
19shouldBe("a.href", "'s:www.mydomain.com/path/?%'");
20
21// IE8 throws "The URL is invalid" exception.
22debug("Set search containing '#'");
23try {
24a.href = "https://www.mydomain.com/path/?key=value#hash";
25a.search = "?value#key";
26shouldBe("a.href", "'https://www.mydomain.com/path/?value%23key#hash'");
27} catch(e) {
28debug("Exception: " + e.description);
29}
30
31debug("Set search to a malformed URL");
32a.href = "bad:/|/url";
33a.search = "?value=key";
34shouldBe("a.href", "'bad:/|/url?value=key'");
35
36// IE8 converts null to "null", which is not the right thing to do.
37debug("Set search to null");
38a.href = "https://www.mydomain.com/path/?key=value";
39a.search = null;
40shouldBe("a.href", "'https://www.mydomain.com/path/'");
41
42// Firefox 3.5.2 Removes the '?', and it shouldn't, per
43// http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes .
44debug("Set search to empty string");
45a.href = "https://www.mydomain.com/path/?key=value";
46a.search = "";
47shouldBe("a.href", "'https://www.mydomain.com/path/?'");
48
49var successfullyParsed = true;
50