What's new? | Help | Directory | Sign in
Google
  
  
  
    
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<!--
Copyright 2007, Google Inc.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of Google Inc. nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->

<HTML>
<HEAD>
<TITLE>Manual Gears WebCache Tests</TITLE>
<script type="text/javascript" src="../gears_init.js"></script>
<script type="text/javascript" language="javascript">

var localServer;
var nameInput;
var cookieInput;

function OnLoad() {
nameInput = document.getElementById("nameInput");
cookieInput = document.getElementById("cookieInput");
localServer =
google.gears.factory.create("beta.localserver");
}

function Now() {
return new Date().getTime();
}

//----------------------------------------------------------
// LocalServer tests
//----------------------------------------------------------

var managedStore = null;
var store = null;
var fileSubmitter = null;

function CreateManagedStore() {
managedStore = localServer.createManagedStore(nameInput.value,
cookieInput.value);
return managedStore != null;
}

function OpenManagedStore() {
managedStore = localServer.openManagedStore(nameInput.value,
cookieInput.value);
return managedStore != null;
}

function RemoveManagedStore() {
localServer.removeManagedStore(nameInput.value,
cookieInput.value);
}

function ShowManagedStoreInfo() {
var info = "";
info += "enabled = " + managedStore.enabled + "\n";
info += "name = " + managedStore.name + "\n";
info += "requiredCookie = " + managedStore.requiredCookie + "\n";
info += "manifestUrl = " + managedStore.manifestUrl + "\n";
info += "updateStatus = " + managedStore.updateStatus + "\n";
info += "lastUpdateCheckTime = " + managedStore.lastUpdateCheckTime + "\n";
info += "lastUpdateCheckTime as Date = " + new Date(managedStore.lastUpdateCheckTime * 1000) + "\n";
info += "lastErrorMessage = " + managedStore.lastErrorMessage + "\n";
info += "currentVersion = " + managedStore.currentVersion + "\n";
alert(info);
}

function CreateStore() {
store = localServer.createStore(nameInput.value,
cookieInput.value);
return store != null;
}

function OpenStore() {
store = localServer.openStore(nameInput.value,
cookieInput.value);
return store != null;
}

function RemoveStore() {
localServer.removeStore(nameInput.value,
cookieInput.value);
}

function ShowStoreInfo() {
var info = "";
info += "enabled = " + store.enabled + "\n";
info += "name = " + store.name + "\n";
info += "requiredCookie = " + store.requiredCookie + "\n";
alert(info);
}

function CaptureCallback(url, success, id) {
alert(url + "\n" + success + " " + id);
}


function CanServeLocally(url) {
try {
display_text(localServer.canServeLocally(url));
} catch (e) {
display_text(e.message);
}
}

//----------------------------------------------------------
// XmlHttpRequest tests
//----------------------------------------------------------

function NewXHR() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Msxml2.XMLHTTP");
} else {
return null;
}
}

function DoXmlHttpRequest(url, verb, data) {
var xmlhttp = NewXHR();
var statesReached = [0, 0, 0, 0, 0];
xmlhttp.onreadystatechange = function() {
var state = xmlhttp.readyState;
statesReached[state] += 1;
if (state >= 3) {
var responseText = "";
var statusText = "";
var headers = "";
var status = 0;
try {
headers = xmlhttp.getAllResponseHeaders();
status = xmlhttp.status;
statusText = xmlhttp.statusText;
responseText = xmlhttp.responseText;
} catch (e) {
}
display_text(statesReached + "\n" +
status + " " + statusText + "\n" +
headers +
"----------------------------\n" +
responseText);
}
}
xmlhttp.open(verb, url, true);
xmlhttp.send(data)
}


//----------------------------------------------------------
// Gears.HttpRequest tests
//----------------------------------------------------------

function NewGearsHR() {
return google.gears.factory.create("beta.httprequest");
}

function DoGearsHttpRequest(url, verb, data) {
var gearshttp = NewGearsHR();
var statesReached = [0, 0, 0, 0, 0];
gearshttp.onreadystatechange = function() {
var state = gearshttp.readyState;
statesReached[state] += 1;
if (state >= 3) {
var responseText = "";
try { responseText = gearshttp.responseText; }
catch (e) {}
display_text(statesReached + "\n" +
gearshttp.status + " " + gearshttp.statusText + "\n" +
gearshttp.getAllResponseHeaders() +
"----------------------------\n" +
responseText);
}
}
gearshttp.open(verb, url, true);
gearshttp.send(data)
}

//----------------------------------------------------------
// CopyMany
//----------------------------------------------------------

function CopyMany(capturedUrl, count) {
var startTime = Now();
for (var i = 0; i < count; ++i) {
store.copy(capturedUrl, capturedUrl + i);
}
var timeTaken = Now() - startTime;
display_text(count + " copies made in " + timeTaken + " msecs");
}

//----------------------------------------------------------
// GetMany
//----------------------------------------------------------

var getmany; // either an XmlHttpRequest or a Gears.HttpReqeust
var getmany_baseurl;
var getmany_num_to_get;
var getmany_num_got;
var getmany_start_time;

function DoXhrGetMany(urlbase, count) {
DoGetMany(NewXHR(), urlbase, count);
}

function DoGearsGetMany(urlbase, count) {
DoGetMany(NewGearsHR(), urlbase, count);
}

function DoGetMany(request, urlbase, count) {
if (getmany) {
alert("Already getting many");
return;
}
getmany = request;
getmany_baseurl = urlbase;
getmany_num_to_get = count;
getmany_num_got = 0;
getmany_start_time = Now();
DoGetOne();
}

function DoGetOne() {
if (getmany_num_got >= getmany_num_to_get) {
display_text("Got all in " + (Now() - getmany_start_time) + " msecs");
getmany = null;
return;
}
var url = getmany_baseurl + getmany_num_got++;
getmany.open("GET", url, true);
getmany.onreadystatechange = function() {
if (getmany.readyState==4) {
display_text("Got " + getmany_num_got +
" of " + getmany_num_to_get);
setTimeout(DoGetOne, 0);
}
}
getmany.send(null);
}


//----------------------------------------------------------
// Output stuff to the results div
//----------------------------------------------------------

function display_text(text) {
var html = '<pre>' + text + '</pre>';
var div = document.getElementById("result");
div.innerHTML = html;
// TODO(michaeln): this doesn't always clear previous contents in FF
}

function display_result(url, status) {
var text;
if (status) {
text = url + " captured";
} else {
text = url + " NOT captured";
}
display_text(text);
}

</script>
</HEAD>
<BODY onload="OnLoad()">
<form method="post" enctype="multipart/form-data">
name:<input type="text" size="10" name="nameInput" id="nameInput">
cookie:<input type="text" size="10" name="cookieInput" id="cookieInput">
<br>
url:<input type="text" size="50" name="urlinput" id="urlinput"> <input type="button" value="SetLink->" onclick="link.href=urlinput.value;">
<a id="link">link</a><br>
url2:<input type="text" size="50" name="url2input" id="url2input">

<!-- LocalServer --><h5>LocalServer</h5>
<input type="button" value="CreateManagedStore" onclick="CreateManagedStore(); display_text(managedStore != null)">
<input type="button" value="OpenManagedStore" onclick="OpenManagedStore(); display_text(managedStore != null)">
<input type="button" value="RemoveManagedStore" onclick="RemoveManagedStore(); display_text('removed')">
<br>
<input type="button" value="CreateStore" onclick="CreateStore(); display_text(store != null)">
<input type="button" value="OpenStore" onclick="OpenStore(); display_text(store != null)">
<input type="button" value="RemoveStore" onclick="RemoveStore(); display_text('removed')">
<br>
<input type="button" value="CanServeLocally(url)" onclick="CanServeLocally( urlinput.value )">

<!-- ManagedResourceStore --><h5>ManagedResourceStore</h5>
<input type="button" value="ShowInfo" onclick="ShowManagedStoreInfo()">
<input type="button" value="enable" onclick="managedStore.enabled = true">
<input type="button" value="disable" onclick="managedStore.enabled = false">
<br>
<input type="button" value="manifestUrl = url" onclick="display_text((managedStore.manifestUrl = urlinput.value))">
<input type="button" value="checkForUpdate()" onclick="managedStore.checkForUpdate()">

<!-- ResourceStore --><h5>ResourceStore</h5>
<input type="button" value="ShowInfo" onclick="ShowStoreInfo()">
<input type="button" value="enable" onclick="store.enabled = true">
<input type="button" value="disable" onclick="store.enabled = false">
<br>
<input type="button" value="capture(url)" onclick="url2input.value = store.capture( urlinput.value, CaptureCallback)" >
<input type="button" value="capture([url,url2])" onclick="url2input.value = store.capture( [urlinput.value, url2input.value], CaptureCallback)">

<input type="button" value="abort(url2)" onclick="store.abortCapture( url2input.value)">
<br>
<input type="button" value="isCaptured(url)" onclick="display_result(urlinput.value, store.isCaptured( urlinput.value ))">
<input type="button" value="remove(url)" onclick="store.remove( urlinput.value ); display_text('removed')">
<br>
<input type="button" value="rename(url, url2)" onclick="store.rename(urlinput.value, url2input.value)">
<input type="button" value="copy(url, url2)" onclick="store.copy(urlinput.value, url2input.value)">
<input type="button" value="copyMany(url, url2AsNumber)" onclick="CopyMany(urlinput.value, url2input.value)">
<br>
<input type="button" value="getHeader(url, url2AsName)" onclick="display_text(store.getHeader( urlinput.value, url2input.value ))">
<input type="button" value="getAllHeaders(url)" onclick="display_text(store.getAllHeaders( urlinput.value ))">

<!-- Misc --><h5>Misc</h5>
<br><!-- XmlHttp -->
<input type="button" value="XmlHttpGET(url)" onclick="DoXmlHttpRequest( urlinput.value, 'GET' )">
<input type="button" value="XmlHttpHEAD(url)" onclick="DoXmlHttpRequest( urlinput.value, 'HEAD' )">
<input type="button" value="XmlHttpPOST(url, url2AsData)" onclick="DoXmlHttpRequest( urlinput.value, 'POST', url2input.value )">
<br><!-- GearsHttp -->
<input type="button" value="GearsHttpGET(url)" onclick="DoGearsHttpRequest( urlinput.value, 'GET', null )">
<input type="button" value="GearsHttpHEAD(url)" onclick="DoGearsHttpRequest( urlinput.value, 'HEAD', null )">
<input type="button" value="GearsHttpPOST(url, url2AsData)" onclick="DoGearsHttpRequest( urlinput.value, 'POST', url2input.value )">
<br>
<input type="button" value="XHR.GetMany(urlAsBase, url2AsNumber)" onclick="DoXhrGetMany(urlinput.value, url2input.value)">
<input type="button" value="Gears.GetMany(urlAsBase, url2AsNumber)" onclick="DoGearsGetMany(urlinput.value, url2input.value)">
</form>

<div id="result"></div>
</BODY>
</HTML>
Show details Hide details

Change log

r1086 by gears.daemon on Feb 29, 2008   Diff
[Author: aa]

Automated g4 rollback of changelist
6483486.

*** Reason for rollback ***

This is a partial rollback of the original
CL. Only the deletion of the
sdk/tools directory was rolled back. The
addition of new files to the
inspector/ directory was not rolled back.
...
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 14373 bytes, 349 lines