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
|
<!DOCTYPE html>
<html>
<!--
Copyright 2007 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<!--
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.net.CrossDomainRpc</title>
<link href="CrossDomainRpc_test.css?123" rel="stylesheet" type="text/css">
<link href="CrossDomainRpc_test.css#123" rel="stylesheet" type="text/css">
<link href="CrossDomainRpc_test.css" rel="stylesheet" type="text/css">
<script src="../base.js"></script>
<script>
goog.require('goog.debug.Logger');
goog.require('goog.net.CrossDomainRpc');
goog.require('goog.testing.jsunit');
</script>
<script>
// TODO(user): These tests are in fact async since the send command makes a
// request for a file, the reason they do not fail is that the JsUnit test
// runner reports completion after the testFoo functions are finished, and
// does not catch any errors after this point. These tests need updating so
// that they either mock out the async part of the test, or they should be
// written as an async test case.
function print(o) {
if (Object.prototype.toSource) {
return o.toSource();
} else {
var fragments = [];
fragments.push('{');
var first = true;
for (var p in o) {
if (!first) fragments.push(',');
fragments.push(p);
fragments.push(':"');
fragments.push(o[p]);
fragments.push('"');
first = false;
}
return fragments.join('');
}
};
function testNormalRequest() {
var start = new Date();
goog.net.CrossDomainRpc.send(
'crossdomainrpc_test_response.html',
function(e) {
if (e.target.status < 300) {
var elapsed = new Date() - start;
var responseData = eval(e.target.responseText);
goog.net.CrossDomainRpc.logger_.log(goog.debug.Logger.Level.FINE,
elapsed + 'ms: [' + responseData.result.length + '] '
+ print(responseData)
);
assertEquals(16 * 1024, responseData.result.length);
assertEquals(e.target.status, 123);
assertEquals(e.target.responseHeaders.a, 1);
assertEquals(e.target.responseHeaders.b, '2');
} else {
goog.net.CrossDomainRpc.logger_.log(goog.debug.Logger.Level.FINE,
print(e));
fail();
}
},
'POST',
{xyz: '01234567891123456789'}
);
};
function testErrorRequest() {
goog.net.CrossDomainRpc.send(
'http://hoodjimcwaadji.google.com/index.html',
function(e) {
if (e.target.status < 300) {
fail('should have failed requesting a non-existent URI');
} else {
goog.net.CrossDomainRpc.logger_.log(goog.debug.Logger.Level.FINE,
'expected error seen; event=' + print(e));
}
},
'POST',
{xyz: '01234567891123456789'}
);
};
function testGetDummyResourceUri() {
var url = goog.net.CrossDomainRpc.getDummyResourceUri_();
assertTrue(
'dummy resource URL should not contain "?"', url.indexOf('?') < 0);
assertTrue(
'dummy resource URL should not contain "#"', url.indexOf('#') < 0);
};
function testRemoveHash() {
assertEquals('abc', goog.net.CrossDomainRpc.removeHash_('abc#123'));
assertEquals('abc', goog.net.CrossDomainRpc.removeHash_('abc#12#3'));
};
</script>
</head>
<body>
<img src="crossdomainrpc_test.gif?123" alt="dummy resource">
<img src="crossdomainrpc_test.gif#123" alt="dummy resource">
<img src="crossdomainrpc_test.gif" alt="dummy resource">
</body>
</html>
|