pagerequest.js
3.56 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
/*global casper*/
/*jshint strict:false*/
/* jshint -W100 */
casper.test.begin('event page.resource.requested tests', 4, function (test) {
var pageResourceRequested = false;
var pageResourceReceived = false;
casper.on('page.resource.requested', function () {
pageResourceRequested = true;
});
casper.on('page.resource.received', function () {
pageResourceReceived = true;
});
casper.start('tests/site/urls.html', function () {
rawUnicodeUrlTest();
});
var rawUnicodeUrlTest = function () {
casper.waitFor(function () {
return pageResourceRequested === true
}, function () {
casper.test.pass('page.resource.requested called on raw unicode url');
}, function () {
casper.test.fail('page.resource.requested was not called on raw unicode url')
}, 200);
casper.waitFor(function () {
return pageResourceReceived === true
}, function () {
casper.test.pass('page.resource.received called on raw unicode url');
uriEncodedUrlTest();
}, function () {
casper.test.fail('page.resource.received was not called on raw unicode url')
}, 200);
pageResourceRequested = false;
pageResourceReceived = false;
casper.clickLabel('raw unicode', 'a');
};
var uriEncodedUrlTest = function () {
casper.waitFor(function () {
return pageResourceRequested === true
}, function () {
casper.test.pass('page.resource.requested called on uri encoded url');
}, function () {
casper.test.fail('page.resource.requested was not called on uri encoded url')
}, 200);
casper.waitFor(function () {
return pageResourceReceived === true
}, function () {
casper.test.pass('page.resource.received called on uri encoded url');
// This test fails because of PhantomJS bug
//escapedUrlTest();
}, function () {
casper.test.fail('page.resource.received was not called on uri encoded url')
}, 200);
pageResourceRequested = false;
pageResourceReceived = false;
casper.clickLabel('uri encoded', 'a');
};
// this test fails, because page.onNavigationRequested event get not correctly escaped url from PhantomJS:
// console.log(casper.requestUrl) -> http://localhost:54321/tests/site/urls.html?test=Forl�
// Chrome and Firefox do not escape this URL at all (/urls.html?test=Forl%EC)
// We could unescape it, but it will still not be equal equal with the PhantomJS one
// console.log(unescape(requestData.url)) -> http://localhost:54321/tests/site/urls.html?test=Forlì
var escapedUrlTest = function () {
casper.waitFor(function () {
return pageResourceRequested === true
}, function () {
casper.test.pass('page.resource.requested called on escaped url');
}, function () {
casper.test.fail('page.resource.requested was not called on escaped url')
}, 200);
casper.waitFor(function () {
return pageResourceReceived === true
}, function () {
casper.test.pass('page.resource.received called on escaped url');
}, function () {
casper.test.fail('page.resource.received was not called on escaped url')
}, 200);
pageResourceRequested = false;
pageResourceReceived = false;
casper.clickLabel('escaped', 'a');
};
casper.run(function () {
test.done();
});
});