Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / geolocation-emulation-tests.html
blob9ffdf9f8fd6cf0e1cb33ad49bd881f53085eb5bb
1 <html>
2 <head>
3 <script src="../http/tests/inspector/inspector-test.js"></script>
4 <script src="../http/tests/resources/permissions-helper.js"></script>
5 <script>
7 function grantGeolocationPermission() {
8 PermissionsHelper.setPermission('geolocation', 'granted').then(function(p) {
9 console.log("Permission granted.");
10 });
13 function serializeGeolocationError(error) {
14 var result = "Unknown error"
15 switch (error.code)
17 case error.PERMISSION_DENIED:
18 result = "Permission denied";
19 break;
20 case error.POSITION_UNAVAILABLE:
21 result = "Position unavailable";
22 break;
23 case error.TIMEOUT:
24 result = "Request timed out";
25 break;
27 if (error.message)
28 result += " (" + error.message + ")";
29 return result;
32 function overrideGeolocation()
34 function testSuccess(position)
36 if (position && position.coords)
37 console.log("Latitude: " + position.coords.latitude + " Longitude: " + position.coords.longitude);
38 else
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");
56 else
57 console.log("Unexpected error occured. Test failed.");
60 function testFailed(error)
62 console.log(serializeGeolocationError(error));
65 navigator.geolocation.getCurrentPosition(testSuccess, testFailed);
68 function test()
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);
94 next();
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()");
112 </script>
113 </head>
114 <body onload="runTest()">
116 Tests that geolocation emulation with latitude and longitude works as expected.
117 </p>
118 </body>
119 </html>