1
1
mirror of https://github.com/ariya/phantomjs.git synced 2024-09-11 12:55:33 +03:00
phantomjs/test/basics/test-server.js
Zack Weinberg f69d44b829 Don't hardwire listening ports for the test HTTP(S) servers.
Instead, run-tests.py asks the kernel to assign a random unused port
number for each, and then sets environment variables TEST_HTTP_BASE
and TEST_HTTPS_BASE to the base URLs of each server.  In tests that
use testharness.js, these are exposed as global variables with the
same name; tests that don't use the harness will need to pick them out
of require('system').env if they need them.  (Currently there are no
such tests.)

Part of issue #13478 (test suite overhaul).
2015-10-20 17:11:36 -04:00

33 lines
875 B
JavaScript

/* Test the test server itself. */
var webpage = require('webpage');
function test_one_page(url) {
var page = webpage.create();
page.onResourceReceived = this.step_func(function (response) {
assert_equals(response.status, 200);
});
page.onResourceError = this.unreached_func();
page.onResourceTimeout = this.unreached_func();
page.onLoadFinished = this.step_func_done(function (status) {
assert_equals(status, 'success');
});
page.open(url);
}
function do_test(path) {
var http_url = TEST_HTTP_BASE + path;
var https_url = TEST_HTTPS_BASE + path;
var http_test = async_test(http_url);
var https_test = async_test(https_url);
http_test.step(test_one_page, null, http_url);
https_test.step(test_one_page, null, https_url);
}
[
'hello.html',
'status?200',
'echo'
]
.forEach(do_test);