Release as 1.0.4
[conkeror.git] / tests / simple / client-redirect.js
blob0f95eada5ef70f81341464d8d693057cd207fa30
2 require("walnut");
3 require("client-redirect");
5 walnut_run({
6     suite_setup: function () {
7         this.real_redirects = client_redirect.redirects;
8         client_redirect.redirects = {};
9         define_client_redirect("r1",
10             function (uri) {
11                 return /^example\.com$/.test(uri.host)
12                     && uri.filePath == "/foo"
13                     && uri.spec + "/bar";
14             });
15         define_client_redirect("r2",
16             build_url_regexp($domain = "example", $allow_www,
17                              $path = /(foo)/),
18             function (m) {
19                 return "http://example.com/"+m[1]+"/"+m[1];
20             });
21     },
22     suite_teardown: function () {
23         client_redirect.redirects = this.real_redirects;
24     },
25     test_client_redirect_1: function () {
26         var uri = make_uri("http://not-example.com/foo")
27             .QueryInterface(Ci.nsIURL);
28         assert_not(client_redirect.redirects.r1(uri));
29     },
30     test_client_redirect_2: function () {
31         var uri = make_uri("http://example.com/")
32             .QueryInterface(Ci.nsIURL);
33         assert_not(client_redirect.redirects.r1(uri));
34     },
35     test_client_redirect_3: function () {
36         var uri = make_uri("http://example.com/foo")
37             .QueryInterface(Ci.nsIURL);
38         assert_equals(client_redirect.redirects.r1(uri),
39                       "http://example.com/foo/bar");
40     },
41     test_client_redirect_4: function () {
42         var uri = make_uri("http://example.com/")
43             .QueryInterface(Ci.nsIURL);
44         assert_not(client_redirect.redirects.r2(uri));
45     },
46     test_client_redirect_5: function () {
47         var uri = make_uri("http://example.com/foo")
48             .QueryInterface(Ci.nsIURL);
49         assert_equals(client_redirect.redirects.r2(uri),
50                       "http://example.com/foo/foo");
51     }
52 });