registry.html
2.1 KB
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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Registry Test</title>
<script>
var dojoConfig = {
async: true,
requestProvider: 'dojo/request/registry'
};
</script>
<script src="../../dojo.js"></script>
<script>
require([
"doh",
"dojo/request",
"dojo/request/registry",
"dojo/request/script",
"dojo/domReady!"
], function(doh, request, registry, script){
doh.register("dojo/request/registry", [
function requestEqualsRegistry(t){
t.is(registry, request, "request should be the registry function");
},
{
name: "RegExp registration works",
runTest: function(t){
var d = new doh.Deferred();
var h = request.register(/^foo/, d.getTestCallback(function(url, options){
t.t(/^foo/.test(url), "URL should begin with 'foo'");
h.remove();
}));
request.get('foobar');
return d;
}
},
{
name: "Function registration works",
runTest: function(t){
var d = new doh.Deferred();
var h = request.register(function(url, options){
return options.method == 'POST';
}, d.getTestCallback(function(url, options){
t.is('POST', options.method, "Method should be 'POST'");
h.remove();
}));
request.post('foobar');
return d;
}
},
{
name: "String registration works",
runTest: function(t){
var d = new doh.Deferred();
var h = request.register("foobar", d.getTestCallback(function(url, options){
t.is('foobar', url, "URL should be 'foobar'");
h.remove();
}));
request.get('foobar');
return d;
}
},
{
name: "Fallback works",
runTest: function(t){
var d = new doh.Deferred();
var h = t.handle = request.register("foobar", function(url, options){});
request.get("registry.html").then(d.getTestCallback(function(){
delete t.handle;
h.remove();
}));
return d;
},
tearDown: function(t){
if(t.handle){
t.handle.remove();
}
}
}
]);
doh.run();
});
</script>
</head>
<body>
</body>
</html>