Unit tests: reduce the flakiness of loading progress tests.

For whatever reason, swapping the order with the render() tests solve the
intermittent random failures. Also, split the tests between loading
start and finish checks (to better recognize which one is failing, if
there is a failure), also make the tests more asynchoronous.

https://github.com/ariya/phantomjs/issues/11091
1.x
Ariya Hidayat 2013-06-02 13:33:52 -07:00
parent 01587211cb
commit b4c4429e86
1 changed files with 63 additions and 35 deletions

View File

@ -1929,6 +1929,69 @@ describe('WebPage navigation events', function() {
});
});
describe("WebPage loading/loadingProgress properties", function() {
var p = require("webpage").create();
it("should not be loading when page has just been created", function() {
expect(p.loading).toBeFalsy();
expect(p.loadingProgress).toEqual(0);
});
it("should be loading when 'page.open' is invoked", function() {
var s = require("webserver").create();
s.listen(12345, function(request, response) {
setTimeout(function() {
response.statusCode = 200;
response.write('<html><body>Loaded!</body></html>');
response.close();
}, 200);
});
runs(function() {
p.open("http://localhost:12345");
expect(p.loading).toBeTruthy();
expect(p.loadingProgress).toBeGreaterThan(0);
});
waits(500);
runs(function() {
s.close();
});
});
it("should be completed when page is fully loaded", function() {
var s = require("webserver").create();
s.listen(12345, function(request, response) {
setTimeout(function() {
response.statusCode = 200;
response.write('<html><body>Loaded!</body></html>');
response.close();
}, 500);
});
var loaded = false;
runs(function() {
p.open("http://localhost:12345", function () {
loaded = true;
});
});
waitsFor(function () {
return loaded;
}, 'Can not test loading progress' , 3000);
runs(function() {
expect(p.loading).toBeFalsy();
expect(p.loadingProgress).toEqual(100);
s.close();
});
});
});
describe("WebPage render image", function(){
var TEST_FILE_DIR = "webpage-spec-renders/";
@ -2032,41 +2095,6 @@ describe("WebPage render image", function(){
});
describe("WebPage loading/loadingProgress properties", function() {
var p = require("webpage").create();
it("should not be loading when page has just been created", function() {
expect(p.loading).toBeFalsy();
expect(p.loadingProgress).toEqual(0);
});
it("should be loading when 'page.open' is invoked", function() {
var s = require("webserver").create();
s.listen(12345, function(request, response) {
setTimeout(function() {
response.statusCode = 200;
response.write('<html><body>Loaded!</body></html>');
response.close();
}, 500);
});
p.onLoadFinished = function(status) {
expect(p.loading).toBeFalsy();
expect(p.loadingProgress).toEqual(0);
};
p.open("http://localhost:12345");
expect(p.loading).toBeTruthy();
expect(p.loadingProgress).toBeGreaterThan(0);
waits(500);
runs(function() {
s.close();
});
});
});
describe("WebPage network request headers handling", function() {
it("should add HTTP header to a network request", function() {
var page = require("webpage").create();