| <html> |
| <head> |
| <script src="../http/tests/inspector/inspector-test.js"></script> |
| <script src="../http/tests/resources/permissions-helper.js"></script> |
| <script> |
| |
| function grantGeolocationPermission() { |
| PermissionsHelper.setPermission('geolocation', 'granted').then(function(p) { |
| console.log("Permission granted."); |
| }); |
| } |
| |
| function serializeGeolocationError(error) { |
| var result = "Unknown error" |
| switch (error.code) |
| { |
| case error.PERMISSION_DENIED: |
| result = "Permission denied"; |
| break; |
| case error.POSITION_UNAVAILABLE: |
| result = "Position unavailable"; |
| break; |
| case error.TIMEOUT: |
| result = "Request timed out"; |
| break; |
| } |
| if (error.message) |
| result += " (" + error.message + ")"; |
| return result; |
| } |
| |
| function overrideGeolocation() |
| { |
| function testSuccess(position) |
| { |
| if (position && position.coords) |
| console.log("Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude); |
| else |
| console.log("Unexpected error occured. Test failed."); |
| } |
| |
| function testFailed(error) |
| { |
| console.log(serializeGeolocationError(error)); |
| } |
| |
| navigator.geolocation.getCurrentPosition(testSuccess, testFailed); |
| } |
| |
| function overridenTimestampGeolocation() |
| { |
| function testSuccess(position) |
| { |
| if ((new Date(position.timestamp)).toDateString() == (new Date()).toDateString()) |
| console.log("PASSED"); |
| else |
| console.log("Unexpected error occured. Test failed."); |
| } |
| |
| function testFailed(error) |
| { |
| console.log(serializeGeolocationError(error)); |
| } |
| |
| navigator.geolocation.getCurrentPosition(testSuccess, testFailed); |
| } |
| |
| function test() |
| { |
| InspectorTest.runTestSuite([ |
| function testPermissionGranted(next) |
| { |
| InspectorTest.addConsoleSniffer(next); |
| InspectorTest.evaluateInPage("grantGeolocationPermission()"); |
| }, |
| |
| function testGeolocationUnavailable(next) |
| { |
| InspectorTest.EmulationAgent.setGeolocationOverride(); |
| InspectorTest.addConsoleSniffer(next); |
| InspectorTest.evaluateInPage("overrideGeolocation()"); |
| }, |
| |
| function testOverridenGeolocation(next) |
| { |
| InspectorTest.EmulationAgent.setGeolocationOverride(50, 100, 95); |
| InspectorTest.addConsoleSniffer(next); |
| InspectorTest.evaluateInPage("overrideGeolocation()"); |
| }, |
| |
| function testInvalidParam(next) |
| { |
| InspectorTest.EmulationAgent.setGeolocationOverride(true, 100, 95); |
| next(); |
| }, |
| |
| function testInvalidGeolocation(next) |
| { |
| InspectorTest.EmulationAgent.setGeolocationOverride(200, 300, 95); |
| InspectorTest.addConsoleSniffer(next); |
| InspectorTest.evaluateInPage("overrideGeolocation()"); |
| }, |
| |
| function testTimestampOfOverridenPosition(next) |
| { |
| InspectorTest.EmulationAgent.setGeolocationOverride(50, 100, 95); |
| InspectorTest.addConsoleSniffer(next); |
| InspectorTest.evaluateInPage("overridenTimestampGeolocation()"); |
| } |
| ]); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p> |
| Tests that geolocation emulation with latitude and longitude works as expected. |
| </p> |
| </body> |
| </html> |