- add sources.
[platform/framework/web/crosswalk.git] / src / content / test / data / cross-origin-redirect-blocked.html
1 <html>
2 <head>
3   <title></title>
4 </head>
5 <body>
6 <script>
7
8 function NewXHR(url) {
9   var r = new XMLHttpRequest
10   r.open("GET", url);
11   return r;
12 }
13
14 function SignalSuccess() {
15   document.location = "title3.html";
16 }
17
18 function SignalFailure() {
19   document.location = "title1.html";
20 }
21
22 function CreateDummyRequest() {
23   dummy_request = NewXHR("http://mock.http/title2.html");
24   dummy_request.onload = SignalSuccess;
25   dummy_request.send(null);
26 }
27
28 function RedirectFailed() {
29   // Good, the redirect was blocked by WebKit.
30   //
31   // We also care that the underlying network stack does not send the redirect.
32   // We cannot detect that from JS, but our test harness is designed to detect
33   // that (see ResourceDispatcherTest::CrossOriginRedirectBlocked).  Before
34   // calling SignalSuccess, we want to allow the browser time to notice a request
35   // to follow the redirect if one should exist.  To do that, we just need to
36   // make another network request.
37   //
38   // The setTimeout call is intended to delay CreateDummyRequest so that any
39   // processing associated with the current "error" handler completes.
40   setTimeout(CreateDummyRequest, 0);
41 }
42
43 function RedirectSucceeded() {
44   // Oops, the redirect should have been denied!
45   SignalFailure();
46 }
47
48 // Kick off a request that will attempt a cross-origin redirect.
49 request = NewXHR("http://mock.http/redirect-to-title2.html");
50 request.onerror = RedirectFailed;
51 request.onload = RedirectSucceeded;
52 request.send(null);
53
54 </script>
55 </body>
56 </html>