summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/data/xmlhttprequest_header_test.html
blob: 83a220ede67c5e2ff031ec6946a5a208d5de0104 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<html>
  <head>
    <meta http-equiv="x-ua-compatible" content="chrome=1" />
    <title>ChromeFrame XHR Authorization header test</title>
    <script type="text/javascript"
        src="chrome_frame_tester_helpers.js"></script>

    <script type="text/javascript">
      function ValidateUserAgent() {
        if (isRunningInMSIE()) {
          onFailure("FullTab_XMLHttpRequestAuthorizationHeaderTest", 1,
                    "Failed");
          return;
        }
        if (!SendHeader("Authorization", "Basic"))
          return;
        if (!SendHeader("accept", "application/json"))
          return
        if (SendHeader("cache-control", "no-cache")) {
          onSuccess("FullTabModeIE_XHRHeaderTest", 1);
        }
      }
      
      function ValidateResponse(xhr, ExpectedValue) {
        var pos = xhr.responseText.indexOf(ExpectedValue);
        if (pos >= 0) {
          return true;
        }
        return false;
      }

      function SendHeader(header, header_value) {
        var test_name = "FullTabModeIE_XHRHeaderTest";
        var xhr = getXHRObject();
        if (!xhr) {
          onFailure(test_name, 1, "Failed to get XHR object");
        }
        var request_uri = AppendArgumentsToBaseUrl("echoheader?",
                                                   header);
        xhr.open("GET", request_uri, false);
        xhr.setRequestHeader(header, header_value);

        try {
          xhr.send(null);
          if (ValidateResponse(xhr, header_value)) {
            appendStatus("Received header: " + xhr.responseText);
            return true;
          } else {
            onFailure(test_name, 1,
                      "Failed to find header in response.");
          }
        } catch (e) {
          appendStatus("XHR send failed. Error: " + e.description);
          onFailure(test_name, 1, "Failed to send XHR request");
        }
        return false;
      }
    </script>
  </head>

  <body onLoad="setTimeout(ValidateUserAgent, 100);">
    ChromeFrame full tab mode XMLHttpRequest HTTP header tests.
    Verifies that HTTP headers set by XML HTTP requests make it via
    the host network stack.
  </body>
</html>