Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/Geolocation/script-tests/cached-position-called-once.js

Issue 1948033003: Convert most geolocation layout tests to use a JS mock implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission-disconnect
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 description('Tests that when a cached position is available the callback for get CurrentPosition is called only once. This is a regression test for http://crbug. com/311876 .'); 1 description('Tests that when a cached position is available the callback for get CurrentPosition is called only once. This is a regression test for http://crbug. com/311876 .');
2 2
3 if (!window.testRunner || !window.internals) 3 if (!window.testRunner || !window.mojo)
4 debug('This test can not run without testRunner or internals'); 4 debug('This test can not run without testRunner or mojo');
5
6 internals.setGeolocationClientMock(document);
7 internals.setGeolocationPosition(document, 31.478, -0.166, 100);
8 internals.setGeolocationPermission(document, true);
9 5
10 // Only one success callback should be reported per call to getCurrentPosition. 6 // Only one success callback should be reported per call to getCurrentPosition.
11 var reportCount = 0; 7 var reportCount = 0;
8 var isSuccess;
9
12 function reportCallback(success, id) { 10 function reportCallback(success, id) {
13 isSuccess = success; 11 isSuccess = success;
14 shouldBeTrue('isSuccess'); 12 shouldBeTrue('isSuccess');
15 getCurrentPositionCallId = id; 13 getCurrentPositionCallId = id;
16 shouldBe('getCurrentPositionCallId', 'reportCount'); 14 shouldBe('getCurrentPositionCallId', 'reportCount');
17 if (++reportCount >= 3) 15 if (++reportCount >= 3)
18 finishJSTest(); 16 finishJSTest();
19 } 17 }
20 18
21 var getCurrentPositionCall = 0; 19 var getCurrentPositionCall = 0;
22 function getPosition(milliseconds) { 20 function getPosition(milliseconds) {
23 var id = getCurrentPositionCall++; 21 var id = getCurrentPositionCall++;
24 var fn = function() { 22 var fn = function() {
25 navigator.geolocation.getCurrentPosition( 23 navigator.geolocation.getCurrentPosition(
26 function(position) { 24 function(position) {
27 reportCallback(true, id); 25 reportCallback(true, id);
28 }, 26 },
29 function(error) { 27 function(error) {
30 reportCallback(false, id); 28 reportCallback(false, id);
31 }, 29 },
32 { maximumAge:600000, timeout:0 }); 30 { maximumAge:600000, timeout:0 });
33 }; 31 };
34 setTimeout(fn, milliseconds); 32 setTimeout(fn, milliseconds);
35 } 33 }
36 34
37 // The test terminates at the 3rd reported callback. If the bug still exists 35 geolocationServiceMock.then(mock => {
38 // this happens after the 2nd call to getCurrentPosition, one of them is a 36 mock.setGeolocationPosition(31.478, -0.166, 100);
39 // repeat of the first. 37 mock.setGeolocationPermission(true);
40 getPosition(0); 38
41 getPosition(100); 39 // Make a geolocation request to populate the cached value so requests with a
42 getPosition(200); 40 // timeout of 0 can succeed.
41 navigator.geolocation.getCurrentPosition(function(position) {
42 // The test terminates at the 3rd reported callback. If the bug still ex ists
43 // this happens after the 2nd call to getCurrentPosition, one of them is a
44 // repeat of the first.
45 getPosition(0);
46 getPosition(100);
47 getPosition(200);
48 }, function(error) {
49 testFailed('Error callback invoked unexpectedly');
50 });
51 });
43 52
44 window.jsTestIsAsync = true; 53 window.jsTestIsAsync = true;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698