Truly independent web browser
LibWeb+Tests: Drive geolocation WPT tests through the BiDi test driver
sideshowbarkere73eeb538145
diff --git a/Libraries/LibWeb/Internals/Internals.cpp b/Libraries/LibWeb/Internals/Internals.cppindex e87b190c462..5e39704ec53 100644--- a/Libraries/LibWeb/Internals/Internals.cpp+++ b/Libraries/LibWeb/Internals/Internals.cpp@@ -2096,15 +2096,25 @@ void Internals::set_environments_top_level_url(Utf16String const& url)window().associated_document().relevant_settings_object().top_level_creation_url = URL::Parser::basic_parse(url.utf16_view());}-void Internals::set_geolocation_emulated_position(double latitude, double longitude, double accuracy)+void Internals::set_geolocation_emulated_position(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitude_accuracy, Optional<double> heading, Optional<double> speed){page().set_emulated_position_data(Geolocation::CoordinatesData {.accuracy = accuracy,.latitude = latitude,.longitude = longitude,+ .altitude = altitude,+ .altitude_accuracy = altitude_accuracy,+ .heading = heading,+ .speed = speed,});}+// Every position request then fails with POSITION_UNAVAILABLE, as it does when no position can be found.+void Internals::set_geolocation_emulated_position_unavailable()+{+ page().set_emulated_position_data(Geolocation::GeolocationPositionError::ErrorCode::PositionUnavailable);+}+GC::Ref<WebIDL::Promise> Internals::request_permission(Utf16String const& name){auto& realm = window().principal_realm();diff --git a/Libraries/LibWeb/Internals/Internals.h b/Libraries/LibWeb/Internals/Internals.hindex e764bb808dc..a6506b6b0e6 100644--- a/Libraries/LibWeb/Internals/Internals.h+++ b/Libraries/LibWeb/Internals/Internals.h@@ -254,7 +254,8 @@ public:void clear_element(HTML::HTMLElement&);void set_environments_top_level_url(Utf16String const& url);- void set_geolocation_emulated_position(double latitude, double longitude, double accuracy);+ void set_geolocation_emulated_position(double latitude, double longitude, double accuracy, Optional<double> altitude, Optional<double> altitude_accuracy, Optional<double> heading, Optional<double> speed);+ void set_geolocation_emulated_position_unavailable();GC::Ref<WebIDL::Promise> request_permission(Utf16String const& name);GC::Ref<WebIDL::Promise> set_permission(Utf16String const& name, Utf16String const& state);diff --git a/Libraries/LibWeb/Internals/Internals.idl b/Libraries/LibWeb/Internals/Internals.idlindex b4bf5d759e2..ffc024d60a5 100644--- a/Libraries/LibWeb/Internals/Internals.idl+++ b/Libraries/LibWeb/Internals/Internals.idl@@ -256,7 +256,8 @@ interface Internals {undefined pumpGamepadEvents();undefined setEnvironmentsTopLevelURL(USVString url);- undefined setGeolocationEmulatedPosition(double latitude, double longitude, optional double accuracy = 100);+ undefined setGeolocationEmulatedPosition(double latitude, double longitude, optional double accuracy = 100, optional double? altitude = null, optional double? altitudeAccuracy = null, optional double? heading = null, optional double? speed = null);+ undefined setGeolocationEmulatedPositionUnavailable();Promise<DOMString> requestPermission(DOMString name);Promise<undefined> setPermission(DOMString name, DOMString state);diff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-error.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-error.https.txtindex 1402c747b01..bb6cab07f41 100644--- a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-error.https.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-error.https.txt@@ -1,6 +1,6 @@-Harness status: Error+Harness status: OKFound 1 tests-1 Not Run-Not Run Tests Geolocation error callback\ No newline at end of file+1 Pass+Pass Tests Geolocation error callback\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-success.https.txt b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-success.https.txtindex fd2b5fd445f..a08de7e17cf 100644--- a/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-success.https.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/geolocation/getCurrentPosition-success.https.txt@@ -1,7 +1,7 @@-Harness status: Error+Harness status: OKFound 2 tests-2 Not Run-Not Run getCurrentPosition called with success and error callbacks-Not Run Error callback is nullable for getCurrentPosition().\ No newline at end of file+2 Pass+Pass getCurrentPosition called with success and error callbacks+Pass Error callback is nullable for getCurrentPosition().\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.js b/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.jsindex ad4235a8ff2..e3cbfcd59d2 100644--- a/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.js+++ b/Tests/LibWeb/Text/input/wpt-import/resources/testdriver-vendor.js@@ -155,3 +155,28 @@ window.test_driver_internal.action_sequence = async function(actions, context) {window.test_driver_internal.set_permission = function(permission_params, context) {return window.internals.setPermission(permission_params.descriptor.name, permission_params.state);};++// The WebDriver BiDi forms of the same, which the geolocation tests use.+window.test_driver_internal.bidi.permissions.set_permission = function(params) {+ return window.internals.setPermission(params.descriptor.name, params.state);+};++// An error override makes every request fail with POSITION_UNAVAILABLE, the one error WebDriver BiDi can emulate.+// Clearing the override (coordinates: null) puts back the position the harness emulates for every test.+window.test_driver_internal.bidi.emulation.set_geolocation_override = function(params) {+ if (params.error) {+ window.internals.setGeolocationEmulatedPositionUnavailable();+ return Promise.resolve();+ }+ const coordinates = params.coordinates ?? { latitude: 37.7647658, longitude: -122.4345892, accuracy: 100 };+ window.internals.setGeolocationEmulatedPosition(+ coordinates.latitude,+ coordinates.longitude,+ coordinates.accuracy ?? 100,+ coordinates.altitude ?? null,+ coordinates.altitudeAccuracy ?? null,+ coordinates.heading ?? null,+ coordinates.speed ?? null+ );+ return Promise.resolve();+};