Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: chrome_frame/test/data/chrome_frame_tester_helpers.js

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 //
2 // This script provides some mechanics for testing ChromeFrame
3 //
4 function onSuccess(name, id) {
5 onFinished(name, id, "OK");
6 }
7
8 function onFailure(name, id, status) {
9 onFinished(name, id, status);
10 }
11
12 function getXHRObject(){
13 var XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP',
14 'Msxml2.XMLHTTP.4.0'];
15 var http = null;
16 try {
17 http = new XMLHttpRequest();
18 } catch(e) {
19 }
20
21 if (http)
22 return http;
23
24 for (var i = 0; i < 3; ++i) {
25 var progid = XMLHTTP_PROGIDS[i];
26 try {
27 http = new ActiveXObject(progid);
28 } catch(e) {
29 }
30
31 if (http)
32 break;
33 }
34 return http;
35 }
36
37 var reportURL = "/writefile/";
38
39 function shutdownServer() {
40 var xhr = getXHRObject();
41 if(!xhr)
42 return;
43
44 xhr.open("POST", "/kill", false);
45 try {
46 xhr.send(null);
47 } catch(e) {
48 appendStatus("XHR send failed. Error: " + e.description);
49 }
50 }
51
52 // Optionally send the server a notification that onload was fired.
53 // To be called from within window.onload.
54 function sendOnLoadEvent() {
55 writeToServer("OnLoadEvent", "loaded");
56 }
57
58 function writeToServer(name, result) {
59 var xhr = getXHRObject();
60 if(!xhr)
61 return;
62
63 // synchronously POST the results
64 xhr.open("POST", reportURL + name, false);
65 xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
66 try {
67 xhr.send(result);
68 } catch(e) {
69 appendStatus("XHR send failed. Error: " + e.description);
70 }
71 }
72
73 function postResult(name, result) {
74 writeToServer(name, result);
75 // NOTE:
76 // not watching for failure or return status issues. What should we do here?
77 shutdownServer();
78 }
79
80 // Finish running a test by setting the status
81 // and the cookie.
82 function onFinished(name, id, result) {
83 appendStatus(result);
84
85 // set a cookie to report the results...
86 var cookie = name + "." + id + ".status=" + result + "; path=/";
87 document.cookie = cookie;
88
89 // ...and POST the status back to the server
90 postResult(name, result);
91 }
92
93 function appendStatus(message) {
94 var statusPanel = document.getElementById("statusPanel");
95 if (statusPanel) {
96 statusPanel.innerHTML += '<BR>' + message;
97 }
98 }
99
100 function readCookie(name) {
101 var cookie_name = name + "=";
102 var ca = document.cookie.split(';');
103
104 for(var i = 0 ; i < ca.length ; i++) {
105 var c = ca[i];
106 while (c.charAt(0) == ' ') {
107 c = c.substring(1,c.length);
108 }
109 if (c.indexOf(cookie_name) == 0) {
110 return c.substring(cookie_name.length, c.length);
111 }
112 }
113 return null;
114 }
115
116 function createCookie(name,value,days) {
117 var expires = "";
118 if (days) {
119 var date = new Date();
120 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
121 expires = "; expires=" + date.toGMTString();
122 }
123 document.cookie = name+"="+value+expires+"; path=/";
124 }
125
126 function eraseCookie(name) {
127 createCookie(name, "", -1);
128 }
129
130 function isRunningInMSIE() {
131 if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
132 return true;
133
134 return false;
135 }
136
137 function reloadUsingCFProtocol() {
138 var redirect_location = "cf:";
139 redirect_location += window.location;
140 window.location = redirect_location;
141 }
142
OLDNEW
« no previous file with comments | « chrome_frame/test/data/chrome_frame_resize_hosted.html ('k') | chrome_frame/test/data/event_listener.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698