Skip to content

Commit

Permalink
Cleanup testharness-related code (#5559)
Browse files Browse the repository at this point in the history
Couple of testharness-related changes to make it run correctly in
Chromium:
- removed usage of global done() function, relying instead on invidual
 test cases step_func_done() etc.
- using step_func_done(), unreached_func(), etc to simplify the
 text.
  • Loading branch information
yellowdoge authored and foolip committed May 5, 2017
1 parent f9e3d12 commit e38c392
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 56 deletions.
3 changes: 2 additions & 1 deletion geolocation-API/OWNERS
@@ -1,2 +1,3 @@
@zqzhang
@jdm
@mcasas
@zqzhang
29 changes: 8 additions & 21 deletions geolocation-API/PositionOptions.https.html
Expand Up @@ -43,12 +43,9 @@

try {
geo.getCurrentPosition(
t86.step_func(function(pos) {
assert_unreached('A success callback was invoked unexpectedly');
}),
t86.step_func(function(err) {
t86.unreached_func('A success callback was invoked unexpectedly'),
t86.step_func_done(function(err) {
assert_equals(err.code, err.TIMEOUT);
t86.done();
}),
{timeout: 0, maximumAge: 0}
);
Expand All @@ -60,12 +57,9 @@

try {
geo.watchPosition(
t88.step_func(function(pos) {
assert_unreached('A success callback was invoked unexpectedly');
}),
t88.step_func(function(err) {
t88.unreached_func('A success callback was invoked unexpectedly'),
t88.step_func_done(function(err) {
assert_equals(err.code, err.TIMEOUT);
t88.done();
}),
{timeout: 0, maximumAge: 0}
);
Expand All @@ -77,12 +71,9 @@

try {
geo.getCurrentPosition(
t91.step_func(function(pos) {
assert_unreached('A success callback was invoked unexpectedly');
}),
t91.step_func(function(err) {
t91.unreached_func('A success callback was invoked unexpectedly'),
t91.step_func_done(function(err) {
assert_equals(err.code, err.TIMEOUT);
t91.done();
}),
{timeout:-1, maximumAge: 0}
);
Expand All @@ -94,13 +85,9 @@

try {
geo.watchPosition(
t92.step_func(function(pos) {
assert_unreached('A success callback was invoked unexpectedly');
done();
}),
t92.step_func(function(err) {
t92.unreached_func('A success callback was invoked unexpectedly'),
t92.step_func_done(function(err) {
assert_equals(err.code, err.TIMEOUT);
done();
}),
{timeout: -1, maximumAge: 0}
);
Expand Down
1 change: 0 additions & 1 deletion geolocation-API/clearWatch_TypeError.html
Expand Up @@ -18,6 +18,5 @@
} catch(e) {
assert_unreached('An exception was thrown unexpectedly: ' + e.message);
}
done();
}, 'Test that calling clearWatch with invalid watch IDs does not cause an exception');
</script>
32 changes: 11 additions & 21 deletions geolocation-API/getCurrentPosition_permission_allow.https.html
Expand Up @@ -14,31 +14,21 @@
var t = async_test('User allows access, check that success callback is called or error callback is called with correct code.'),
onSuccess, onError, hasMethodReturned = false;

onSuccess = t.step_func(function(pos) {
// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00031
test(function() {
t.step(function() {
onSuccess = t.step_func_done(function(pos) {
// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00031
assert_true(hasMethodReturned);
}, 'Check that getCurrentPosition returns synchronously before any callbacks are invoked.');

done();
});
});

onError = t.step_func(function(err) {
// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00031
test(function() {
onError = t.step_func_done(function(err) {
// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00031
assert_true(hasMethodReturned);
}, 'Check that getCurrentPosition returns synchronously before any callbacks are invoked.');

assert_true(!isUsingPreemptivePermission && err.code === err.POSITION_UNAVAILABLE);
done();
});
assert_false(isUsingPreemptivePermission);
assert_equals(err.code, err.POSITION_UNAVAILABLE, errorToString(err));
});

try {
geo.getCurrentPosition(onSuccess, onError);
hasMethodReturned = true;
} catch(e) {
t.step(function() {
assert_unreached('An exception was thrown unexpectedly: ' + e.message);
});
}
});

</script>
10 changes: 4 additions & 6 deletions geolocation-API/getCurrentPosition_permission_deny.https.html
Expand Up @@ -15,20 +15,18 @@
onSuccess, onError, hasMethodReturned = false;

t.step(function() {
onSuccess = t.step_func(function(pos) {
onSuccess = t.step_func_done(function(pos) {
assert_unreached('A success callback was invoked unexpectedly with position ' + positionToString(pos));
});

onError = t.step_func(function(err) {
onError = t.step_func_done(function(err) {
// http://dev.w3.org/geo/api/test-suite/t.html?00031
assert_true(hasMethodReturned, 'Check that getCurrentPosition returns synchronously before any callbacks are invoked');
assert_equals(err.code, err.PERMISSION_DENIED,
'PossitionError code: ' + err.code, + ', message: ' + err.message);
done();
assert_equals(err.code, err.PERMISSION_DENIED, errorToString(err));
});

geo.getCurrentPosition(onSuccess, onError);
hasMethodReturned = true;
});
</script>

</script>
2 changes: 1 addition & 1 deletion geolocation-API/support.js
Expand Up @@ -2,7 +2,7 @@ var geo;

setup(function() {
geo = navigator.geolocation;
}, {explicit_done: true});
});

// The spec states that an implementation SHOULD acquire user permission before
// beggining the position acquisition steps. If an implementation follows this
Expand Down
7 changes: 2 additions & 5 deletions geolocation-API/watchPosition_permission_deny.https.html
Expand Up @@ -14,18 +14,15 @@
var t = async_test('Check that watchPosition returns synchronously before any callbacks are invoked.'),
id, checkMethodHasReturned, hasMethodReturned = false;

checkMethodHasReturned = t.step_func(function() {
checkMethodHasReturned = t.step_func_done(function() {
assert_true(hasMethodReturned);
done();
});

try {
id = geo.watchPosition(checkMethodHasReturned, checkMethodHasReturned);
hasMethodReturned = true;
} catch(e) {
t.step(function() {
assert_unreached('An exception was thrown unexpectedly: ' + e.message);
});
t.unreached_func('An exception was thrown unexpectedly: ' + e.message);
}

// Rewrite http://dev.w3.org/geo/api/test-suite/t.html?00151
Expand Down

0 comments on commit e38c392

Please sign in to comment.