OLD | NEW |
1 // | 1 // |
2 // This script provides some mechanics for testing ChromeFrame | 2 // This script provides some mechanics for testing ChromeFrame |
3 // | 3 // |
4 function onSuccess(name, id) { | 4 function onSuccess(name, id) { |
5 onFinished(name, id, "OK"); | 5 onFinished(name, id, "OK"); |
6 } | 6 } |
7 | 7 |
8 function onFailure(name, id, status) { | 8 function onFailure(name, id, status) { |
9 onFinished(name, id, status); | 9 onFinished(name, id, status); |
10 } | 10 } |
11 | 11 |
12 function getXHRObject(){ | 12 function getXHRObject(){ |
13 var XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', | 13 var XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', |
14 'Msxml2.XMLHTTP.4.0']; | 14 'Msxml2.XMLHTTP.4.0']; |
15 var http = null; | 15 var http = null; |
16 try { | 16 try { |
17 http = new XMLHttpRequest(); | 17 http = new XMLHttpRequest(); |
18 } catch(e) { | 18 } catch(e) { |
19 } | 19 } |
20 | 20 |
21 if (http) | 21 if (http) |
22 return http; | 22 return http; |
23 | 23 |
24 for (var i = 0; i < 3; ++i) { | 24 for (var i = 0; i < 3; ++i) { |
25 var progid = XMLHTTP_PROGIDS[i]; | 25 var progid = XMLHTTP_PROGIDS[i]; |
26 try { | 26 try { |
27 http = new ActiveXObject(progid); | 27 http = new ActiveXObject(progid); |
28 } catch(e) { | 28 } catch(e) { |
29 } | 29 } |
30 | 30 |
31 if (http) | 31 if (http) |
32 break; | 32 break; |
33 } | 33 } |
34 return http; | 34 return http; |
35 } | 35 } |
36 | 36 |
37 var reportURL = "/writefile/"; | 37 var reportURL = "/writefile/"; |
38 | 38 |
39 function shutdownServer() { | 39 function shutdownServer() { |
40 var xhr = getXHRObject(); | 40 var xhr = getXHRObject(); |
41 if(!xhr) | 41 if(!xhr) |
42 return; | 42 return; |
(...skipping 19 matching lines...) Expand all Loading... |
62 | 62 |
63 // synchronously POST the results | 63 // synchronously POST the results |
64 xhr.open("POST", reportURL + name, false); | 64 xhr.open("POST", reportURL + name, false); |
65 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); | 65 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); |
66 try { | 66 try { |
67 xhr.send(result); | 67 xhr.send(result); |
68 } catch(e) { | 68 } catch(e) { |
69 appendStatus("XHR send failed. Error: " + e.description); | 69 appendStatus("XHR send failed. Error: " + e.description); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 function postResult(name, result) { | 73 function postResult(name, result) { |
74 writeToServer(name, result); | 74 writeToServer(name, result); |
75 // NOTE: | 75 // NOTE: |
76 // not watching for failure or return status issues. What should we do here? | 76 // not watching for failure or return status issues. What should we do here? |
77 shutdownServer(); | 77 shutdownServer(); |
78 } | 78 } |
79 | 79 |
80 // Finish running a test by setting the status | 80 // Finish running a test by setting the status |
81 // and the cookie. | 81 // and the cookie. |
82 function onFinished(name, id, result) { | 82 function onFinished(name, id, result) { |
83 appendStatus(result); | 83 appendStatus(result); |
84 | 84 |
85 // set a cookie to report the results... | 85 // set a cookie to report the results... |
86 var cookie = name + "." + id + ".status=" + result + "; path=/"; | 86 var cookie = name + "." + id + ".status=" + result + "; path=/"; |
87 document.cookie = cookie; | 87 document.cookie = cookie; |
88 | 88 |
89 // ...and POST the status back to the server | 89 // ...and POST the status back to the server |
90 postResult(name, result); | 90 postResult(name, result); |
91 } | 91 } |
92 | 92 |
93 function appendStatus(message) { | 93 function appendStatus(message) { |
94 var statusPanel = document.getElementById("statusPanel"); | 94 var statusPanel = document.getElementById("statusPanel"); |
95 if (statusPanel) { | 95 if (statusPanel) { |
96 statusPanel.innerHTML += '<BR>' + message; | 96 statusPanel.innerHTML += '<BR>' + message; |
97 } | 97 } |
98 } | 98 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 133 |
134 return false; | 134 return false; |
135 } | 135 } |
136 | 136 |
137 function reloadUsingCFProtocol() { | 137 function reloadUsingCFProtocol() { |
138 var redirect_location = "cf:"; | 138 var redirect_location = "cf:"; |
139 redirect_location += window.location; | 139 redirect_location += window.location; |
140 window.location = redirect_location; | 140 window.location = redirect_location; |
141 } | 141 } |
142 | 142 |
| 143 function TestIfRunningInChrome() { |
| 144 var is_chrome = /chrome/.test(navigator.userAgent.toLowerCase()); |
| 145 if (!is_chrome) { |
| 146 onFailure("ChromeFrameWindowOpen", "Window Open failed :-(", |
| 147 "User agent = " + navigator.userAgent.toLowerCase()); |
| 148 } |
| 149 return is_chrome; |
| 150 } |
OLD | NEW |