Update web-platform-tests to revision 5e3ea8f49fee68c327388bfd1dd1375a8ce12a0e.

This commit is contained in:
Ms2ger 2015-07-09 14:05:01 +02:00
parent 12195a5c4a
commit bfb96b9448
1166 changed files with 35123 additions and 900 deletions

View file

@ -0,0 +1,3 @@
importScripts("../testharness.js");
throw new Error("This failure is expected.");

View file

@ -0,0 +1,34 @@
importScripts("../testharness.js");
test(
function(test) {
assert_true(true, "True is true");
},
"Worker test that completes successfully");
test(
function(test) {
assert_true(false, "Failing test");
},
"Worker test that fails ('FAIL')");
async_test(
function(test) {
assert_true(true, "True is true");
},
"Worker test that times out ('TIMEOUT')");
async_test("Worker test that doesn't run ('NOT RUN')");
async_test(
function(test) {
self.setTimeout(
function() {
test.done();
},
0);
},
"Worker async_test that completes successfully");
// An explicit done() is required for dedicated and shared web workers.
done();

View file

@ -0,0 +1,175 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Sample HTML5 API Tests</title>
<meta name="timeout" content="6000">
</head>
<body onload="load_test_attr.done()">
<h1>Sample HTML5 API Tests</h1>
<div id="log"></div>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
setup_run = false;
setup(function() {
setup_run = true;
});
test(function() {assert_true(setup_run)}, "Setup function ran");
// Two examples for testing events from handler and attributes
var load_test_event = async_test("window onload event fires when set from the handler");
function windowLoad()
{
load_test_event.done();
}
on_event(window, "load", windowLoad);
// see the body onload below
var load_test_attr = async_test("body element fires the onload event set from the attribute");
</script>
<script>
function bodyElement()
{
assert_equals(document.body, document.getElementsByTagName("body")[0]);
}
test(bodyElement, "document.body should be the first body element in the document");
test(function() {
assert_equals(1,1);
assert_equals(NaN, NaN, "NaN case");
assert_equals(0, 0, "Zero case");
}, "assert_equals tests")
test(function() {
assert_equals(-0, 0, "Zero case");
}, "assert_equals tests expected to fail")
test(function() {
assert_not_equals({}, {}, "object case");
assert_not_equals(-0, 0, "Zero case");
}, "assert_not_equals tests")
function testAssertPass()
{
assert_true(true);
}
test(testAssertPass, "assert_true expected to pass");
function testAssertFalse()
{
assert_true(false, "false should not be true");
}
test(testAssertFalse, "assert_true expected to fail");
function basicAssertArrayEquals()
{
assert_array_equals([1, NaN], [1, NaN], "[1, NaN] is equal to [1, NaN]");
}
test(basicAssertArrayEquals, "basic assert_array_equals test");
function basicAssertObjectEquals()
{
assert_object_equals([1, 2, [1, 2]], { 0: 1, 1: 2, 2: { 0: 1, 1: 2} }, "array is equal to object")
}
test(basicAssertObjectEquals, "basic assert_object_equals test");
function basicAssertApproxEquals()
{
assert_approx_equals(10, 11, 1, "10 is approximately (+/- 1) 11")
}
test(basicAssertApproxEquals, "basic assert_approx_equals test");
function basicAssertLessThan()
{
assert_less_than(10, 11, "10 is less than 11")
}
test(basicAssertApproxEquals, "basic assert_less_than test");
function basicAssertGreaterThan()
{
assert_greater_than(10, 11, "10 is not greater than 11");
}
test(basicAssertGreaterThan, "assert_greater_than expected to fail");
function basicAssertGreaterThanEqual()
{
assert_greater_than_equal(10, 10, "10 is greater than or equal to 10")
}
test(basicAssertGreaterThanEqual, "basic assert_greater_than_equal test");
function basicAssertLessThanEqual()
{
assert_greater_than_equal('10', 10, "'10' is not a number")
}
test(basicAssertLessThanEqual, "assert_less_than_equal expected to fail");
function testAssertInherits() {
var A = function(){this.a = "a"}
A.prototype = {b:"b"}
var a = new A();
assert_exists(a, "a");
assert_not_exists(a, "b");
assert_inherits(a, "b");
}
test(testAssertInherits, "test for assert[_not]_exists and insert_inherits")
test(function()
{
var a = document.createElement("a")
var b = document.createElement("b")
assert_throws("NOT_FOUND_ERR", function(){a.removeChild(b)});
}, "Test throw DOM exception")
test(function()
{
var a = document.createTextNode("a")
var b = document.createElement("b")
assert_throws("NOT_FOUND_ERR", function(){a.appendChild(b)});
}, "Test throw DOM exception expected to fail")
test(function()
{
var e = {code:0, name:"TEST_ERR", TEST_ERR:0}
assert_throws("TEST_ERR", function() {throw e});
}, "Test assert_throws with non-DOM-exception expected to Fail");
var t = async_test("Test step_func")
setTimeout(
t.step_func(
function () {
assert_true(true); t.done();
}), 0);
async_test(function(t) {
setTimeout(t.step_func(function (){assert_true(true); t.done();}), 0);
}, "Test async test with callback");
async_test(function() {
setTimeout(this.step_func(function (){assert_true(true); this.done();}), 0);
}, "Test async test with callback and `this` obj.");
async_test("test should timeout (fail) with the default of 2 seconds").step(function(){});
async_test("test should timeout (fail) with a custom set timeout value of 1 second",
{timeout:1000}).step(function(){});
async_test("async test that is never started, should have status Not Run", {timeout:1000});
test(function(t) {
window.global = 1;
t.add_cleanup(function() {delete window.global});
assert_equals(window.global, 1);
},
"Test that defines a global and cleans it up");
test(function() {assert_equals(window.global, undefined)},
"Test that cleanup handlers from previous test ran");
</script>
</body>
</html>

View file

@ -0,0 +1,119 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Async Tests and Promises</title>
</head>
<body>
<h1>Async Tests and Promises</h1>
<p>This test assumes ECMAScript 6 Promise support. Some failures are expected.</p>
<div id="log"></div>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
test(function() {
var p = new Promise(function(resolve, reject) {});
assert_true('then' in p);
assert_equals(typeof Promise.resolve, 'function');
assert_equals(typeof Promise.reject, 'function');
}, "Promises are supported in your browser");
(function() {
var t = async_test("Promise resolution");
t.step(function() {
Promise.resolve('x').then(
t.step_func(function(value) {
assert_equals(value, 'x');
t.done();
}),
t.unreached_func('Promise should not reject')
);
});
}());
(function() {
var t = async_test("Promise rejection");
t.step(function() {
Promise.reject(Error('fail')).then(
t.unreached_func('Promise should reject'),
t.step_func(function(reason) {
assert_true(reason instanceof Error);
assert_equals(reason.message, 'fail');
t.done();
})
);
});
}());
(function() {
var t = async_test("Promises resolution chaining");
t.step(function() {
var resolutions = [];
Promise.resolve('a').then(
t.step_func(function(value) {
resolutions.push(value);
return 'b';
})
).then(
t.step_func(function(value) {
resolutions.push(value);
return 'c';
})
).then(
t.step_func(function(value) {
resolutions.push(value);
assert_array_equals(resolutions, ['a', 'b', 'c']);
t.done();
})
).catch(
t.unreached_func('promise should not have rejected')
);
});
}());
(function() {
var t = async_test("Use of step_func with Promises");
t.step(function() {
var resolutions = [];
Promise.resolve('x').then(
t.step_func_done(),
t.unreached_func('Promise should not have rejected')
);
});
}());
(function() {
var t = async_test("Promises and test assertion failures (should fail)");
t.step(function() {
var resolutions = [];
Promise.resolve('x').then(
t.step_func(function(value) {
assert_true(false, 'This failure is expected');
})
).then(
t.unreached_func('Promise should not have resolved')
).catch(
t.unreached_func('Promise should not have rejected')
);
});
}());
(function() {
var t = async_test("Use of unreached_func with Promises (should fail)");
t.step(function() {
var resolutions = [];
var r;
var p = new Promise(function(resolve, reject) {
// Reject instead of resolve, to demonstrate failure.
reject(123);
});
p.then(
function(value) {
assert_equals(value, 123, 'This should not actually happen');
},
t.unreached_func('This failure is expected')
);
});
}());
</script>

View file

@ -0,0 +1,99 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Example with iframe that notifies containing document via callbacks</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
</head>
<body onload="start_test_in_iframe()">
<h1>Callbacks From Tests Running In An IFRAME</h1>
<p>A test is run inside an <tt>iframe</tt> with a same origin document. The
containing document should receive callbacks as the tests progress inside the
<tt>iframe</tt>. A single passing test is expected in the summary below.
<div id="log"></div>
<script>
var callbacks = [];
var START = 1
var TEST_STATE = 2
var RESULT = 3
var COMPLETION = 4
var test_complete = false;
setup({explicit_done: true});
// The following callbacks are called for tests in this document as well as the
// tests in the IFRAME. Currently, callbacks invoked from this document and any
// child document are indistinguishable from each other.
function start_callback(properties) {
callbacks.push(START);
}
function test_state_callback(test) {
callbacks.push(TEST_STATE);
}
function result_callback(test) {
callbacks.push(RESULT);
}
function completion_callback(tests, status) {
if (test_complete) {
return;
}
test_complete = true;
callbacks.push(COMPLETION);
verify_received_callbacks();
done();
}
function verify_received_callbacks() {
var copy_of_callbacks = callbacks.slice(0);
// Note that you can't run test assertions directly in a callback even if
// this is a file test. When the callback is invoked from a same-origin child
// page, the callstack reaches into the calling child document. Any
// exception thrown in a callback will be handled by the child rather than
// this document.
test(
function() {
// callbacks list should look like:
// START 1*(TEST_STATE) RESULT COMPLETION
assert_equals(copy_of_callbacks.shift(), START,
"The first received callback should be 'start_callback'.");
assert_equals(copy_of_callbacks.shift(), TEST_STATE,
"'test_state_callback' should be received before any " +
"result or completion callbacks.");
while(copy_of_callbacks.length > 0) {
var callback = copy_of_callbacks.shift();
if (callback != TEST_STATE) {
copy_of_callbacks.unshift(callback);
break;
}
}
assert_equals(copy_of_callbacks.shift(), RESULT,
"'test_state_callback' should be followed by 'result_callback'.");
assert_equals(copy_of_callbacks.shift(), COMPLETION,
"Final 'result_callback' should be followed by 'completion_callback'.");
assert_equals(copy_of_callbacks.length, 0,
"'completion_callback' should be the last callback.");
});
}
function start_test_in_iframe() {
// This document is going to clear any received callbacks and maintain
// radio silence until the test in the iframe runs to completion. The
// completion_callback() will then complete the testing on this document.
callbacks.length = 0;
var iframe = document.createElement("iframe");
// apisample6.html has a single test.
iframe.src = "apisample6.html";
iframe.style.setProperty("display", "none");
document.getElementById("target").appendChild(iframe);
}
</script>
<div id="target">
</div>
</body>

View file

@ -0,0 +1,67 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Example with iframe that notifies containing document via cross document messaging</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
</head>
<body>
<h1>Notifications From Tests Running In An IFRAME</h1>
<p>A test is run inside an <tt>iframe</tt> with a same origin document. The
containing document should receive messages via <tt>postMessage</tt>/
<tt>onmessage</tt> as the tests progress inside the <tt>iframe</tt>. A single
passing test is expected in the summary below.
</p>
<div id="log"></div>
<script>
var t = async_test("Containing document receives messages");
var start_received = false;
var result_received = false;
var completion_received = false;
// These are the messages that are expected to be seen while running the tests
// in the IFRAME.
var expected_messages = [
t.step_func(
function(message) {
assert_equals(message.data.type, "start");
assert_own_property(message.data, "properties");
}),
t.step_func(
function(message) {
assert_equals(message.data.type, "test_state");
assert_equals(message.data.test.status, message.data.test.NOTRUN);
}),
t.step_func(
function(message) {
assert_equals(message.data.type, "result");
assert_equals(message.data.test.status, message.data.test.PASS);
}),
t.step_func(
function(message) {
assert_equals(message.data.type, "complete");
assert_equals(message.data.tests.length, 1);
assert_equals(message.data.tests[0].status,
message.data.tests[0].PASS);
assert_equals(message.data.status.status, message.data.status.OK);
t.done();
}),
t.unreached_func("Too many messages received")
];
on_event(window,
"message",
function(message) {
var handler = expected_messages.shift();
handler(message);
});
</script>
<iframe src="apisample6.html" style="display:none">
<!-- apisample6 implements a file_is_test test. -->
</iframe>
</body>

View file

@ -0,0 +1,132 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Promise Tests</title>
</head>
<body>
<h1>Promise Tests</h1>
<p>This test demonstrates the use of <tt>promise_test</tt>. Assumes ECMAScript 6
Promise support. Some failures are expected.</p>
<div id="log"></div>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
test(
function() {
var p = new Promise(function(resolve, reject){});
assert_true("then" in p);
assert_equals(typeof Promise.resolve, "function");
assert_equals(typeof Promise.reject, "function");
},
"Promises are supported in your browser");
promise_test(
function() {
return Promise.resolve("x")
.then(
function(value) {
assert_equals(value,
"x",
"Fulfilled promise should pass result to " +
"fulfill reaction.");
});
},
"Promise fulfillment with result");
promise_test(
function(t) {
return Promise.reject(new Error("fail"))
.then(t.unreached_func("Promise should reject"),
function(reason) {
assert_true(
reason instanceof Error,
"Rejected promise should pass reason to fulfill reaction.");
assert_equals(
reason.message,
"fail",
"Rejected promise should pass reason to reject reaction.");
});
},
"Promise rejection with result");
promise_test(
function() {
var resolutions = [];
return Promise.resolve("a")
.then(
function(value) {
resolutions.push(value);
return "b";
})
.then(
function(value) {
resolutions.push(value);
return "c";
})
.then(
function(value) {
resolutions.push(value);
assert_array_equals(resolutions, ["a", "b", "c"]);
});
},
"Chain of promise resolutions");
promise_test(
function(t) {
var resolutions = [];
return Promise.resolve("x")
.then(
function(value) {
assert_true(false, "Expected failure.");
})
.then(t.unreached_func("UNEXPECTED FAILURE: Promise should not have resolved."));
},
"Assertion failure in a fulfill reaction (should FAIL with an expected failure)");
promise_test(
function(t) {
return new Promise(
function(resolve, reject) {
reject(123);
})
.then(t.unreached_func("UNEXPECTED FAILURE: Fulfill reaction reached after rejection."),
t.unreached_func("Expected failure."));
},
"unreached_func as reactor (should FAIL with an expected failure)");
promise_test(
function() {
return true;
},
"promise_test with function that doesn't return a Promise");
promise_test(function(){},
"promise_test with function that doesn't return anything");
promise_test(
function() {
return Promise.reject("Expected rejection");
},
"promise_test with unhandled rejection (should FAIL)");
promise_test(
function() {
return Promise.resolve(10)
.then(
function(value) {
throw Error("Expected exception.");
});
},
"promise_test with unhandled exception in fulfill reaction (should FAIL)");
promise_test(
function(t) {
return Promise.reject(10)
.then(
t.unreached_func("UNEXPECTED FAILURE: Fulfill reaction reached after rejection."),
function(value) {
throw Error("Expected exception.");
});
},
"promise_test with unhandled exception in reject reaction (should FAIL)");
</script>

View file

@ -0,0 +1,29 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Dedicated Worker Tests</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
</head>
<body>
<h1>Dedicated Web Worker Tests</h1>
<p>Demonstrates running <tt>testharness</tt> based tests inside a dedicated web worker.
<p>The test harness is expected to fail due to an uncaught exception in one worker.</p>
<div id="log"></div>
<script>
test(function(t) {
assert_true("Worker" in self, "Browser should support Workers");
},
"Browser supports Workers");
fetch_tests_from_worker(new Worker("apisample-worker.js"));
fetch_tests_from_worker(new Worker("apisample-error-worker.js"));
test(function(t) {
assert_false(false, "False is false");
},
"Test running on main document.");
</script>
</body>

View file

@ -0,0 +1,26 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Example with a shared worker</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
</head>
<body>
<h1>Shared Web Worker Tests</h1>
<p>Demonstrates running <tt>testharness</tt> based tests inside a shared worker.
<p>The test harness should time out due to one of the tests in the worker timing out.
<p>This test assumes that the browser supports <a href="http://www.w3.org/TR/workers/#shared-workers-and-the-sharedworker-interface">shared web workers</a>.
<div id="log"></div>
<script>
test(
function(t) {
assert_true("SharedWorker" in self,
"Browser should support SharedWorkers");
},
"Browser supports SharedWorkers");
fetch_tests_from_worker(new SharedWorker("apisample-worker.js",
"My shared worker"));
</script>
</body>

View file

@ -0,0 +1,62 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Example with a service worker</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
</head>
<body>
<h1>Service Worker Tests</h1>
<p>Demonstrates running <tt>testharness</tt> based tests inside a service worker.
<p>The test harness should time out due to one of the tests inside the worker timing out.
<p>This test assumes that the browser supports <a href="http://www.w3.org/TR/service-workers/">ServiceWorkers</a>.
<div id="log"></div>
<script>
test(
function(t) {
assert_true("serviceWorker" in navigator,
"navigator.serviceWorker exists");
},
"Browser supports ServiceWorker");
promise_test(
function() {
// Since the service worker registration could be in an indeterminate
// state (due to, for example, a previous test run failing), we start by
// unregstering our service worker and then registering it again.
var scope = "/service-worker-scope";
var worker_url = "apisample-worker.js";
return navigator.serviceWorker.register(worker_url, {scope: scope})
.then(
function(registration) {
return registration.unregister();
})
.then(
function() {
return navigator.serviceWorker.register(worker_url, {scope: scope});
})
.then(
function(registration) {
add_completion_callback(
function() {
registration.unregister();
});
return new Promise(
function(resolve) {
registration.addEventListener("updatefound",
function() {
resolve(registration.installing);
});
});
})
.then(
function(worker) {
fetch_tests_from_worker(worker);
});
},
"Register ServiceWorker");
</script>
</body>

View file

@ -0,0 +1,19 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Sample HTML5 API Tests</title>
</head>
<body onload="load_test_attr.done()">
<h1>Sample HTML5 API Tests</h1>
<p>There should be two results</p>
<div id="log"></div>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
setup({explicit_done:true})
test(function() {assert_true(true)}, "Test defined before onload");
onload = function() {test(function (){assert_true(true)}, "Test defined after onload");
done();
}
</script>

View file

@ -0,0 +1,17 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Sample HTML5 API Tests</title>
</head>
<script src="../testharness.js"></script>
<body onload="load_test_attr.done()">
<h1>Sample HTML5 API Tests</h1>
<div id="log"></div>
<script>
setup({explicit_timeout:true});
var t = async_test("This test should give a status of 'Not Run' without a delay");
timeout();
</script>
</body>
</html>

View file

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Harness Handling Uncaught Exception</title>
</head>
<script src="../testharness.js"></script>
<body>
<h1>Harness Handling Uncaught Exception</h1>
<div id="log"></div>
<script>
var t = async_test("This should show a harness status of 'Error' and a test status of 'Not Run'");
throw new Error("Example Error");
</script>
</body>
</html>

View file

@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Harness Ignoring Uncaught Exception</title>
</head>
<script src="../testharness.js"></script>
<body>
<h1>Harness Ignoring Uncaught Exception</h1>
<div id="log"></div>
<script>
setup({allow_uncaught_exception:true});
var t = async_test("setup({allow_uncaught_exception:true}) should allow tests to pass even if there is an exception");
onerror = t.step_func(function() {t.done()});
throw new Error("Example Error");
</script>
</body>
</html>

View file

@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<title>Example with file_is_test</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
onload = function() {
assert_true(true);
done();
}
</script>

View file

@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<title>Example with file_is_test (should fail)</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
onload = function() {
assert_true(false);
done();
}
</script>

View file

@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<title>Example single page test with no body</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
assert_true(true);
done();
</script>

View file

@ -0,0 +1,7 @@
<!DOCTYPE HTML>
<title>Example single page test with no asserts</title>
<script src="../testharness.js"></script>
<script src="../testharnessreport.js"></script>
<script>
done();
</script>