Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- var webserver = require('webserver');
- casper.test.begin('Image onload should be invoked', 1, {
- setUp: function() {
- var server = webserver.create();
- this.server = server.listen(8080, function(request, response) {
- if (request.url == '/') {
- response.writeHead(200, { 'Content-Type': 'text/html' });
- response.write('' +
- '<!doctype html>n' +
- '<html>n' +
- '<head>n' +
- '<script type="text/javascript">n' +
- 'window.onload = function() {n' +
- 'var px = document.createElement("img");n' +
- 'px.onload = function() {n' +
- 'window._pxLoad = true;n' +
- '};n' +
- 'px.src = "px.gif";n' +
- '};n' +
- '</script>n' +
- '</head>n' +
- '<body></body>n' +
- '</html>' +
- '');
- } else if (request.url.match(/px.gif$/i)) {
- response.writeHead(200, {
- 'Content-Type': 'image/gif',
- 'Cache-Control': 'no-cache'
- });
- var filePath = fs.workingDirectory + request.url.split('/').join(fs.separator).replace(/d/gi, '');
- response.write(fs.read(filePath));
- }
- response.close();
- });
- },
- tearDown: function() {
- this.server.close();
- },
- test: function(test) {
- casper.start('http://localhost:8190', function() {
- this.waitFor(function() {
- return this.evaluate(function () {
- return window._pxLoad !== undefined;
- });
- }, function then() {
- var flag = this.evaluate(function () {
- return window._pxLoad;
- });
- test.assertTruthy(flag, 'Image has been successfully loaded');
- });
- });
- casper.run(function () {
- test.done();
- });
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement