Commit f0f4a144 authored by mek@chromium.org's avatar mek@chromium.org

Fix the geofencing test to not break if the promises resolve asynchronously.

Also add a similar test to make sure the API exists/rejects in service workers.

BUG=383125

Review URL: https://codereview.chromium.org/543203003

git-svn-id: svn://svn.chromium.org/blink/trunk@181855 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 70ebbecc
Tests that all geofencing methods always reject.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS Promise rejected as expected.
PASS Promise rejected as expected.
PASS Promise rejected as expected.
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<head>
<script src="../resources/js-test.js"></script>
</head>
<body>
<title>Tests that all geofencing methods always reject.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
description("Tests that all geofencing methods always reject.");
function shouldReject(promise)
{
promise.then(
function() { testFailed("Promise unexpectedly resolved."); },
function() { testPassed("Promise rejected as expected."); });
// Copied from http/tests/serviceworker/resources/worker-test-harness.js, can be
// removed once this makes it into testharness.js itself.
function promise_test(func, name, properties) {
properties = properties || {};
var test = async_test(name, properties);
Promise.resolve(test.step(func, test, test))
.then(function() { test.done(); })
.catch(test.step_func(function(value) {
throw value;
}));
}
shouldReject(navigator.geofencing.registerRegion(new CircularGeofencingRegion({latitude: 37.421999, longitude: -122.084015})));
shouldReject(navigator.geofencing.unregisterRegion(""));
shouldReject(navigator.geofencing.getRegisteredRegions());
promise_test(function(test) {
return navigator.geofencing.registerRegion(
new CircularGeofencingRegion({latitude: 37.421999,
longitude: -122.084015}))
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'registerRegion should fail');
promise_test(function(test) {
return navigator.geofencing.unregisterRegion("")
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'unregisterRegion should fail');
promise_test(function(test) {
return navigator.geofencing.getRegisteredRegions()
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'getRegisteredRegions should fail');
</script>
</body>
</html>
importScripts('../../serviceworker/resources/worker-test-harness.js');
promise_test(function(test) {
return navigator.geofencing.registerRegion(
new CircularGeofencingRegion({latitude: 37.421999,
longitude: -122.084015}))
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'registerRegion should fail');
promise_test(function(test) {
return navigator.geofencing.unregisterRegion("")
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'unregisterRegion should fail');
promise_test(function(test) {
return navigator.geofencing.getRegisteredRegions()
.then(test.unreached_func('Promise should not have resolved'))
.catch(function() { });
}, 'getRegisteredRegions should fail');
<!DOCTYPE html>
<title>Tests that all geofencing methods always reject, in a service worker.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
<script>
service_worker_test(
'resources/worker.js',
'Verifies that all geofencing methods always reject.');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment