Commit 461dc1e1 authored by steveblock@google.com's avatar steveblock@google.com

2010-06-04 Steve Block <steveblock@google.com>

        Reviewed by Jeremy Orlow.

        Geolocation LayoutTests should make more careful use of LayoutTestController
        https://bugs.webkit.org/show_bug.cgi?id=39994

        Guards calls to LayoutTestController methods with 'if (window.layoutTestController)'
        and adds test output to make it clear if the test can not pass without LayoutTestController.
        Also removes superfluous calls to LayoutTestController.waitUntilDone(), which are now made
        by js-test-post.js.

        * fast/dom/Geolocation/callback-exception-expected.txt:
        * fast/dom/Geolocation/script-tests/callback-exception.js:
        * fast/dom/Geolocation/script-tests/error.js:
        * fast/dom/Geolocation/script-tests/maximum-age.js:
        * fast/dom/Geolocation/script-tests/notimer-after-unload.js:
        * fast/dom/Geolocation/script-tests/permission-denied-already-clear-watch.js:
        * fast/dom/Geolocation/script-tests/permission-denied-already-error.js:
        * fast/dom/Geolocation/script-tests/permission-denied-already-success.js:
        * fast/dom/Geolocation/script-tests/permission-denied-stops-watches.js:
        * fast/dom/Geolocation/script-tests/permission-denied.js:
        * fast/dom/Geolocation/script-tests/position-string.js:
        * fast/dom/Geolocation/script-tests/reentrant-error.js:
        * fast/dom/Geolocation/script-tests/reentrant-success.js:
        * fast/dom/Geolocation/script-tests/success.js:
        * fast/dom/Geolocation/script-tests/timeout-clear-watch.js:
        * fast/dom/Geolocation/script-tests/timeout-zero.js:
        * fast/dom/Geolocation/script-tests/timeout.js:
        * fast/dom/Geolocation/script-tests/watch.js:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@60667 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 14891f9d
2010-06-04 Steve Block <steveblock@google.com>
Reviewed by Jeremy Orlow.
Geolocation LayoutTests should make more careful use of LayoutTestController
https://bugs.webkit.org/show_bug.cgi?id=39994
Guards calls to LayoutTestController methods with 'if (window.layoutTestController)'
and adds test output to make it clear if the test can not pass without LayoutTestController.
Also removes superfluous calls to LayoutTestController.waitUntilDone(), which are now made
by js-test-post.js.
* fast/dom/Geolocation/callback-exception-expected.txt:
* fast/dom/Geolocation/script-tests/callback-exception.js:
* fast/dom/Geolocation/script-tests/error.js:
* fast/dom/Geolocation/script-tests/maximum-age.js:
* fast/dom/Geolocation/script-tests/notimer-after-unload.js:
* fast/dom/Geolocation/script-tests/permission-denied-already-clear-watch.js:
* fast/dom/Geolocation/script-tests/permission-denied-already-error.js:
* fast/dom/Geolocation/script-tests/permission-denied-already-success.js:
* fast/dom/Geolocation/script-tests/permission-denied-stops-watches.js:
* fast/dom/Geolocation/script-tests/permission-denied.js:
* fast/dom/Geolocation/script-tests/position-string.js:
* fast/dom/Geolocation/script-tests/reentrant-error.js:
* fast/dom/Geolocation/script-tests/reentrant-success.js:
* fast/dom/Geolocation/script-tests/success.js:
* fast/dom/Geolocation/script-tests/timeout-clear-watch.js:
* fast/dom/Geolocation/script-tests/timeout-zero.js:
* fast/dom/Geolocation/script-tests/timeout.js:
* fast/dom/Geolocation/script-tests/watch.js:
2010-06-04 Qi Zhang <qi.2.zhang@nokia.com>
Reviewed by Laszlo Gombos.
......
CONSOLE MESSAGE: line 22: Error: Exception in success callback
CONSOLE MESSAGE: line 25: Error: Exception in success callback
Tests that when an exception is thrown in the success callback, the error callback is not invoked. Note that this test throws an exception which is not caught.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
......
......@@ -4,14 +4,17 @@ var mockLatitude = 51.478;
var mockLongitude = -0.166;
var mockAccuracy = 100;
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
} else
debug('This test can not be run without the LayoutTestController');
var position;
navigator.geolocation.getCurrentPosition(function(p) {
position = p
position = p;
shouldBe('position.coords.latitude', 'mockLatitude');
shouldBe('position.coords.longitude', 'mockLongitude');
shouldBe('position.coords.accuracy', 'mockAccuracy');
......@@ -25,7 +28,5 @@ navigator.geolocation.getCurrentPosition(function(p) {
finishJSTest();
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -3,15 +3,18 @@ description("Tests Geolocation error callback using the mock service.");
var mockCode = 2;
var mockMessage = "debug";
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationError(mockCode, mockMessage);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationError(mockCode, mockMessage);
} else
debug('This test can not be run without the LayoutTestController');
var error;
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'mockCode');
shouldBe('error.message', 'mockMessage');
shouldBe('error.UNKNOWN_ERROR', 'undefined');
......@@ -20,7 +23,6 @@ navigator.geolocation.getCurrentPosition(function(p) {
shouldBe('error.TIMEOUT', '3');
finishJSTest();
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -25,8 +25,11 @@ function checkError(e) {
shouldBe('error.message', 'mockMessage');
}
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
} else
debug('This test can not be run without the LayoutTestController');
// Initialize the cached Position
navigator.geolocation.getCurrentPosition(function(p) {
......@@ -39,7 +42,8 @@ navigator.geolocation.getCurrentPosition(function(p) {
function testZeroMaximumAge() {
// Update the position provided by the mock service.
window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
if (window.layoutTestController)
layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
// The default maximumAge is zero, so we expect the updated position from the service.
navigator.geolocation.getCurrentPosition(function(p) {
checkPosition(p);
......@@ -52,7 +56,8 @@ function testZeroMaximumAge() {
function testNonZeroMaximumAge() {
// Update the mock service to report an error.
window.layoutTestController.setMockGeolocationError(mockCode, mockMessage);
if (window.layoutTestController)
layoutTestController.setMockGeolocationError(mockCode, mockMessage);
// The maximumAge is non-zero, so we expect the cached position, not the error from the service.
navigator.geolocation.getCurrentPosition(function(p) {
checkPosition(p);
......@@ -74,7 +79,5 @@ function testZeroMaximumAgeError() {
});
}
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -17,5 +17,3 @@ document.body.onunload = function() {
window.jsTestIsAsync = true;
window.successfullyParsed = true;
if (window.layoutTestController) layoutTestController.waitUntilDone();
description("Tests that when Geolocation permission has been denied prior to a call to watchPosition, and the watch is cleared in the error callback, there is no crash. This a regression test for https://bugs.webkit.org/show_bug.cgi?id=32111.");
// Prime the Geolocation instance by denying permission.
window.layoutTestController.setGeolocationPermission(false);
window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(false);
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
} else
debug('This test can not be run without the LayoutTestController');
var error;
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
debug('');
......@@ -23,7 +26,7 @@ function continueTest()
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
navigator.geolocation.clearWatch(watchId);
......@@ -31,7 +34,5 @@ function continueTest()
});
}
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
description("Tests that when Geolocation permission has been denied prior to a call to a Geolocation method, the error callback is invoked with code PERMISSION_DENIED, when the Geolocation service encounters an error.");
// Prime the Geolocation instance by denying permission.
window.layoutTestController.setGeolocationPermission(false);
window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(false);
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
} else
debug('This test can not be run without the LayoutTestController');
var error;
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
debug('');
......@@ -19,19 +22,19 @@ navigator.geolocation.getCurrentPosition(function(p) {
function continueTest()
{
// Make another request, with permission already denied.
window.layoutTestController.setMockGeolocationError(0, 'test');
if (window.layoutTestController)
layoutTestController.setMockGeolocationError(0, 'test');
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
finishJSTest();
});
}
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
description("Tests that when Geolocation permission has been denied prior to a call to a Geolocation method, the error callback is invoked with code PERMISSION_DENIED, when the Geolocation service has a good position.");
// Prime the Geolocation instance by denying permission.
window.layoutTestController.setGeolocationPermission(false);
window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(false);
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
} else
debug('This test can not be run without the LayoutTestController');
var error;
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
debug('');
......@@ -23,13 +26,12 @@ function continueTest()
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
finishJSTest();
});
}
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -2,8 +2,11 @@ description("Tests that when Geolocation permission is denied, watches are stopp
// Configure the mock Geolocation service to report a position to cause permission
// to be requested, then deny it.
window.layoutTestController.setGeolocationPermission(false);
window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(false);
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0);
} else
debug('This test can not be run without the LayoutTestController');
var error;
var errorCallbackInvoked = false;
......@@ -17,17 +20,17 @@ navigator.geolocation.watchPosition(function(p) {
}
errorCallbackInvoked = true;
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
// Update the mock Geolocation service to report a new position, then
// yield to allow a chance for the success callback to be invoked.
window.layoutTestController.setMockGeolocationPosition(55.478, -0.166, 100);
if (window.layoutTestController)
layoutTestController.setMockGeolocationPosition(55.478, -0.166, 100);
window.setTimeout(finishJSTest, 0);
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
description("Tests Geolocation when permission is denied, using the mock service.");
window.layoutTestController.setGeolocationPermission(false);
window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(false);
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0);
} else
debug('This test can not be run without the LayoutTestController');
var error;
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.PERMISSION_DENIED');
shouldBe('error.message', '"User denied Geolocation"');
finishJSTest();
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -4,15 +4,18 @@ var mockLatitude = 51.478;
var mockLongitude = -0.166;
var mockAccuracy = 100.0;
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
} else
debug('This test can not be run without the LayoutTestController');
var position;
navigator.geolocation.getCurrentPosition(function(p) {
// shouldBe can't use local variables yet.
position = p
position = p;
shouldBe('position.coords.latitude', 'mockLatitude');
shouldBe('position.coords.longitude', 'mockLongitude');
shouldBe('position.coords.accuracy', 'mockAccuracy');
......@@ -23,7 +26,6 @@ navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Error callback invoked unexpectedly');
finishJSTest();
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -3,8 +3,11 @@ description("Tests that reentrant calls to Geolocation methods from the error ca
var mockCode = 0;
var mockMessage = 'test';
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationError(mockCode, mockMessage);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationError(mockCode, mockMessage);
} else
debug('This test can not be run without the LayoutTestController');
var error;
var errorCallbackInvoked = false;
......@@ -29,7 +32,8 @@ function continueTest() {
mockCode += 1;
mockMessage += ' repeat';
window.layoutTestController.setMockGeolocationError(mockCode, mockMessage);
if (window.layoutTestController)
layoutTestController.setMockGeolocationError(mockCode, mockMessage);
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
......@@ -41,7 +45,6 @@ function continueTest() {
finishJSTest();
});
}
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -4,10 +4,13 @@ var mockLatitude = 51.478;
var mockLongitude = -0.166;
var mockAccuracy = 100.0;
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
} else
debug('This test can not be run without the LayoutTestController');
var position;
var successCallbackInvoked = false;
......@@ -30,9 +33,10 @@ navigator.geolocation.getCurrentPosition(function(p) {
});
function continueTest() {
window.layoutTestController.setMockGeolocationPosition(++mockLatitude,
++mockLongitude,
++mockAccuracy);
if (window.layoutTestController)
layoutTestController.setMockGeolocationPosition(++mockLatitude,
++mockLongitude,
++mockAccuracy);
navigator.geolocation.getCurrentPosition(function(p) {
position = p;
......@@ -45,7 +49,6 @@ function continueTest() {
finishJSTest();
});
}
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -4,14 +4,17 @@ var mockLatitude = 51.478;
var mockLongitude = -0.166;
var mockAccuracy = 100;
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
} else
debug('This test can not be run without the LayoutTestController');
var position;
navigator.geolocation.getCurrentPosition(function(p) {
position = p
position = p;
shouldBe('position.coords.latitude', 'mockLatitude');
shouldBe('position.coords.longitude', 'mockLongitude');
shouldBe('position.coords.accuracy', 'mockAccuracy');
......@@ -20,7 +23,6 @@ navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Error callback invoked unexpectedly');
finishJSTest();
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
description("Tests that when a watch times out and is cleared from the error callback, there is no crash. This a regression test for https://bugs.webkit.org/show_bug.cgi?id=32111.");
window.layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0);
if (window.layoutTestController)
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0);
var error;
var watchId = navigator.geolocation.watchPosition(function() {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.TIMEOUT');
shouldBe('error.message', '"Timeout expired"');
navigator.geolocation.clearWatch(watchId);
......@@ -16,7 +17,6 @@ var watchId = navigator.geolocation.watchPosition(function() {
timeout: 0
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
description("Tests that when timeout is zero (and maximumAge is too), the error callback is called immediately with code TIMEOUT.");
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0);
if (window.layoutTestController)
layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100.0);
var error;
navigator.geolocation.getCurrentPosition(function(p) {
testFailed('Success callback invoked unexpectedly');
finishJSTest();
}, function(e) {
error = e
error = e;
shouldBe('error.code', 'error.TIMEOUT');
shouldBe('error.message', '"Timeout expired"');
finishJSTest();
}, {
timeout: 0
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -4,10 +4,13 @@ var mockLatitude = 51.478;
var mockLongitude = -0.166;
var mockAccuracy = 100.0;
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationPosition(mockLatitude,
mockLongitude,
mockAccuracy);
} else
debug('This test can not be run without the LayoutTestController');
var position;
navigator.geolocation.getCurrentPosition(function(p) {
......@@ -22,7 +25,6 @@ navigator.geolocation.getCurrentPosition(function(p) {
}, {
timeout: 1000
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
......@@ -25,19 +25,24 @@ function checkError(e) {
debug('');
}
window.layoutTestController.setGeolocationPermission(true);
window.layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
if (window.layoutTestController) {
layoutTestController.setGeolocationPermission(true);
layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
} else
debug('This test can not be run without the LayoutTestController');
var state = 0;
navigator.geolocation.watchPosition(function(p) {
switch (state++) {
case 0:
checkPosition(p);
window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
if (window.layoutTestController)
layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
break;
case 1:
checkPosition(p);
window.layoutTestController.setMockGeolocationError(mockCode, mockMessage);
if (window.layoutTestController)
layoutTestController.setMockGeolocationError(mockCode, mockMessage);
break;
case 3:
checkPosition(p);
......@@ -51,14 +56,14 @@ navigator.geolocation.watchPosition(function(p) {
switch (state++) {
case 2:
checkError(e);
window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
if (window.layoutTestController)
layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
break;
default:
testFailed('Error callback invoked unexpectedly');
finishJSTest();
}
});
window.layoutTestController.waitUntilDone();
window.jsTestIsAsync = true;
window.successfullyParsed = true;
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