1
1
mirror of https://github.com/ariya/phantomjs.git synced 2024-08-16 08:10:57 +03:00

Test load-images=yes and load-images=no.

This commit is contained in:
Marc Epard 2016-01-19 11:17:54 -06:00 committed by vitallium
parent 0ba7bc8ef6
commit 4ef5f27600
3 changed files with 107 additions and 0 deletions

View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src="logo.png" alt="logo">
<img src="phantomjs.png" alt="phantomjs">
</body>
</html>

View File

@ -0,0 +1,50 @@
//! phantomjs: --load-images=no
"use strict";
// Compiled for debug, this tests for leaks when not loading images.
var url = TEST_HTTP_BASE + 'load-images.html';
async_test(function testLoadImagesNo () {
var page = require('webpage').create();
var numImagesRequested = 0;
var numImagesLoaded = 0;
page.onResourceRequested = this.step_func(function (resource) {
if (/\.png$/.test(resource.url)) ++numImagesRequested;
});
page.onResourceReceived = this.step_func(function (resource) {
if (resource.stage === 'end' && /\.png$/.test(resource.url)) ++numImagesLoaded;
});
function checkImageCounts ()
{
var imageCounts = page.evaluate (function countImages() {
"use strict";
try
{
var images = document.getElementsByTagName('img');
var imageCounts = {};
imageCounts.numImages = images.length;
imageCounts.numComplete = Array.prototype.reduce.call(images, function(n, image) { return n + (image.complete? 1 : 0); }, 0);
return imageCounts;
}
catch(err)
{
return undefined;
}
});
assert_equals(imageCounts.numImages, 2);
assert_equals(imageCounts.numComplete, 0);
assert_equals(numImagesRequested, 0);
assert_equals(numImagesLoaded, 0);
}
page.open(url, this.step_func_done (function pageOpened(status) {
assert_equals(status, "success");
checkImageCounts();
page.release();
}));
}, "load a page two images with --load-images=no");

View File

@ -0,0 +1,48 @@
//! phantomjs: --load-images=yes
"use strict";
var url = TEST_HTTP_BASE + 'load-images.html';
async_test(function testLoadImagesYes () {
var page = require('webpage').create();
var numImagesRequested = 0;
var numImagesLoaded = 0;
page.onResourceRequested = this.step_func(function (resource) {
if (/\.png$/.test(resource.url)) ++numImagesRequested;
});
page.onResourceReceived = this.step_func(function (resource) {
if (resource.stage === 'end' && /\.png$/.test(resource.url)) ++numImagesLoaded;
});
function checkImageCounts ()
{
var imageCounts = page.evaluate (function countImages() {
"use strict";
try
{
var images = document.getElementsByTagName('img');
var imageCounts = {};
imageCounts.numImages = images.length;
imageCounts.numComplete = Array.prototype.reduce.call(images, function(n, image) { return n + (image.complete? 1 : 0); }, 0);
return imageCounts;
}
catch(err)
{
return undefined;
}
});
assert_equals(imageCounts.numImages, 2);
assert_equals(imageCounts.numComplete, 2);
assert_equals(numImagesRequested, 2);
assert_equals(numImagesLoaded, 2);
}
page.open(url, this.step_func_done (function pageOpened(status) {
assert_equals(status, "success");
checkImageCounts();
page.release();
}));
}, "load a page two images with --load-images=yes");