3 <script src=
"../http/tests/inspector/inspector-test.js"></script>
4 <script src=
"../http/tests/resources/permissions-helper.js"></script>
7 function grantGeolocationPermission() {
8 PermissionsHelper
.setPermission('geolocation', 'granted').then(function(p
) {
9 console
.log("Permission granted.");
13 function serializeGeolocationError(error
) {
14 var result
= "Unknown error"
17 case error
.PERMISSION_DENIED
:
18 result
= "Permission denied";
20 case error
.POSITION_UNAVAILABLE
:
21 result
= "Position unavailable";
24 result
= "Request timed out";
28 result
+= " (" + error
.message
+ ")";
32 function overrideGeolocation()
34 function testSuccess(position
)
36 if (position
&& position
.coords
)
37 console
.log("Latitude: " + position
.coords
.latitude
+ " Longitude: " + position
.coords
.longitude
);
39 console
.log("Unexpected error occured. Test failed.");
42 function testFailed(error
)
44 console
.log(serializeGeolocationError(error
));
47 navigator
.geolocation
.getCurrentPosition(testSuccess
, testFailed
);
50 function overridenTimestampGeolocation()
52 function testSuccess(position
)
54 if ((new Date(position
.timestamp
)).toDateString() == (new Date()).toDateString())
55 console
.log("PASSED");
57 console
.log("Unexpected error occured. Test failed.");
60 function testFailed(error
)
62 console
.log(serializeGeolocationError(error
));
65 navigator
.geolocation
.getCurrentPosition(testSuccess
, testFailed
);
70 InspectorTest
.runTestSuite([
71 function testPermissionGranted(next
)
73 InspectorTest
.addConsoleSniffer(next
);
74 InspectorTest
.evaluateInPage("grantGeolocationPermission()");
77 function testGeolocationUnavailable(next
)
79 InspectorTest
.EmulationAgent
.setGeolocationOverride();
80 InspectorTest
.addConsoleSniffer(next
);
81 InspectorTest
.evaluateInPage("overrideGeolocation()");
84 function testOverridenGeolocation(next
)
86 InspectorTest
.EmulationAgent
.setGeolocationOverride(50, 100, 95);
87 InspectorTest
.addConsoleSniffer(next
);
88 InspectorTest
.evaluateInPage("overrideGeolocation()");
91 function testInvalidParam(next
)
93 InspectorTest
.EmulationAgent
.setGeolocationOverride(true, 100, 95);
97 function testInvalidGeolocation(next
)
99 InspectorTest
.EmulationAgent
.setGeolocationOverride(200, 300, 95);
100 InspectorTest
.addConsoleSniffer(next
);
101 InspectorTest
.evaluateInPage("overrideGeolocation()");
104 function testTimestampOfOverridenPosition(next
)
106 InspectorTest
.EmulationAgent
.setGeolocationOverride(50, 100, 95);
107 InspectorTest
.addConsoleSniffer(next
);
108 InspectorTest
.evaluateInPage("overridenTimestampGeolocation()");
114 <body onload=
"runTest()">
116 Tests that geolocation emulation with latitude and longitude works as expected.