OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script src="../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../http/tests/inspector/inspector-test.js"></script> |
4 <script> | 4 <script> |
5 | 5 |
| 6 function serializeGeolocationError(error) { |
| 7 var result = "Unknown error" |
| 8 switch (error.code) |
| 9 { |
| 10 case error.PERMISSION_DENIED: |
| 11 result = "Permission denied"; |
| 12 break; |
| 13 case error.POSITION_UNAVAILABLE: |
| 14 result = "Position unavailable"; |
| 15 break; |
| 16 case error.TIMEOUT: |
| 17 result = "Request timed out"; |
| 18 break; |
| 19 } |
| 20 if (error.message) |
| 21 result += " (" + error.message + ")"; |
| 22 return result; |
| 23 } |
| 24 |
6 function overrideGeolocation() | 25 function overrideGeolocation() |
7 { | 26 { |
8 function testSuccess(position) | 27 function testSuccess(position) |
9 { | 28 { |
10 if (position && position.coords) | 29 if (position && position.coords) |
11 console.log("Latitude: " + position.coords.latitude + " Longitude: "
+ position.coords.longitude); | 30 console.log("Latitude: " + position.coords.latitude + " Longitude: "
+ position.coords.longitude); |
12 else | 31 else |
13 console.log("Unexpected error occured. Test failed."); | 32 console.log("Unexpected error occured. Test failed."); |
14 } | 33 } |
15 | 34 |
16 function testFailed(error) | 35 function testFailed(error) |
17 { | 36 { |
18 console.log(error.message); | 37 console.log(serializeGeolocationError(error)); |
19 } | 38 } |
20 | 39 |
21 navigator.geolocation.getCurrentPosition(testSuccess, testFailed); | 40 navigator.geolocation.getCurrentPosition(testSuccess, testFailed); |
22 } | 41 } |
23 | 42 |
24 function overridenTimestampGeolocation() | 43 function overridenTimestampGeolocation() |
25 { | 44 { |
26 function testSuccess(position) | 45 function testSuccess(position) |
27 { | 46 { |
28 if ((new Date(position.timestamp)).toDateString() == (new Date()).toDate
String()) | 47 if ((new Date(position.timestamp)).toDateString() == (new Date()).toDate
String()) |
29 console.log("PASSED"); | 48 console.log("PASSED"); |
30 else | 49 else |
31 console.log("Unexpected error occured. Test failed."); | 50 console.log("Unexpected error occured. Test failed."); |
32 } | 51 } |
33 | 52 |
34 function testFailed(error) | 53 function testFailed(error) |
35 { | 54 { |
36 console.log(error.message); | 55 console.log(serializeGeolocationError(error)); |
37 } | 56 } |
38 | 57 |
39 navigator.geolocation.getCurrentPosition(testSuccess, testFailed); | 58 navigator.geolocation.getCurrentPosition(testSuccess, testFailed); |
40 } | 59 } |
41 | 60 |
42 function setup() | |
43 { | |
44 var mockLatitude = 100; | |
45 var mockLongitude = 200; | |
46 var mockAccuracy = 94; | |
47 | |
48 if (window.internals) { | |
49 internals.setGeolocationClientMock(document); | |
50 internals.setGeolocationPermission(document, true); | |
51 internals.setGeolocationPosition(document, mockLatitude, mockLongitude,
mockAccuracy); | |
52 } | |
53 } | |
54 | |
55 function test() | 61 function test() |
56 { | 62 { |
57 InspectorTest.runTestSuite([ | 63 InspectorTest.runTestSuite([ |
58 function setUp(next) | |
59 { | |
60 InspectorTest.evaluateInPage("setup()", next); | |
61 }, | |
62 | |
63 function testGeolocationUnavailable(next) | 64 function testGeolocationUnavailable(next) |
64 { | 65 { |
65 GeolocationAgent.setGeolocationOverride(); | 66 PageAgent.setGeolocationOverride(); |
66 InspectorTest.addConsoleSniffer(next); | 67 InspectorTest.addConsoleSniffer(next); |
67 InspectorTest.evaluateInPage("overrideGeolocation()"); | 68 InspectorTest.evaluateInPage("overrideGeolocation()"); |
68 }, | 69 }, |
69 | 70 |
70 function testOverridenGeolocation(next) | 71 function testOverridenGeolocation(next) |
71 { | 72 { |
72 GeolocationAgent.setGeolocationOverride(-510, 500, 100); | 73 PageAgent.setGeolocationOverride(50, 100, 95); |
73 InspectorTest.addConsoleSniffer(next); | |
74 InspectorTest.evaluateInPage("overrideGeolocation()"); | |
75 }, | |
76 | |
77 function testClearOverridenGeolocation(next) | |
78 { | |
79 GeolocationAgent.setGeolocationOverride(-510, 500, 100); | |
80 GeolocationAgent.clearGeolocationOverride(); | |
81 InspectorTest.addConsoleSniffer(next); | 74 InspectorTest.addConsoleSniffer(next); |
82 InspectorTest.evaluateInPage("overrideGeolocation()"); | 75 InspectorTest.evaluateInPage("overrideGeolocation()"); |
83 }, | 76 }, |
84 | 77 |
85 function testInvalidParam(next) | 78 function testInvalidParam(next) |
86 { | 79 { |
87 GeolocationAgent.setGeolocationOverride(true, 500, 100); | 80 PageAgent.setGeolocationOverride(true, 100, 95); |
88 next(); | 81 next(); |
89 }, | 82 }, |
90 | 83 |
| 84 function testInvalidGeolocation(next) |
| 85 { |
| 86 PageAgent.setGeolocationOverride(200, 300, 95); |
| 87 InspectorTest.addConsoleSniffer(next); |
| 88 InspectorTest.evaluateInPage("overrideGeolocation()"); |
| 89 }, |
| 90 |
91 function testTimestampOfOverridenPosition(next) | 91 function testTimestampOfOverridenPosition(next) |
92 { | 92 { |
93 GeolocationAgent.setGeolocationOverride(-510, 500, 100); | 93 PageAgent.setGeolocationOverride(50, 100, 95); |
94 InspectorTest.addConsoleSniffer(next); | 94 InspectorTest.addConsoleSniffer(next); |
95 InspectorTest.evaluateInPage("overridenTimestampGeolocation()"); | 95 InspectorTest.evaluateInPage("overridenTimestampGeolocation()"); |
96 } | 96 } |
97 ]); | 97 ]); |
98 } | 98 } |
99 </script> | 99 </script> |
100 </head> | 100 </head> |
101 <body onload="runTest()"> | 101 <body onload="runTest()"> |
102 <p> | 102 <p> |
103 Tests that geolocation emulation with latitude and longitude works as expected. | 103 Tests that geolocation emulation with latitude and longitude works as expected. |
104 </p> | 104 </p> |
105 </body> | 105 </body> |
106 </html> | 106 </html> |
OLD | NEW |