tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 31676f3c897d4d8c6b7bc3858fabf36ecae30071
parent 6de050c36772b581161cee7d7ca8003a2e2b7650
Author: Benjamin VanderSloot <bvandersloot@mozilla.com>
Date:   Thu,  4 Dec 2025 17:32:50 +0000

Bug 2000448 - [wdspec] Add wdspec tests for global_privacy_control - r=whimboo,geckodriver-reviewers,jgraham

I caught a typo with this. Tests are good to have.

Differential Revision: https://phabricator.services.mozilla.com/D272806

Diffstat:
Mremote/marionette/driver.sys.mjs | 8++++----
Mtesting/geckodriver/marionette/src/webdriver.rs | 8++++----
Mtesting/geckodriver/src/marionette.rs | 34+++++++++++++++++-----------------
Mtesting/web-platform/tests/tools/wptrunner/wptrunner/executors/executormarionette.py | 4++--
Atesting/web-platform/tests/webdriver/tests/classic/global_privacy_control/__init__.py | 0
Atesting/web-platform/tests/webdriver/tests/classic/global_privacy_control/get.py | 14++++++++++++++
Atesting/web-platform/tests/webdriver/tests/classic/global_privacy_control/set.py | 32++++++++++++++++++++++++++++++++
Mtesting/webdriver/src/command.rs | 12++++++------
Mtesting/webdriver/src/httpapi.rs | 24++++++++++++------------
9 files changed, 91 insertions(+), 45 deletions(-)

diff --git a/remote/marionette/driver.sys.mjs b/remote/marionette/driver.sys.mjs @@ -4055,10 +4055,10 @@ GeckoDriver.prototype.commands = { "WebDriver:SwitchToParentFrame": GeckoDriver.prototype.switchToParentFrame, "WebDriver:SwitchToWindow": GeckoDriver.prototype.switchToWindow, "WebDriver:TakeScreenshot": GeckoDriver.prototype.takeScreenshot, - "WebDriver:GetGlobalPrivacyControl": - GeckoDriver.prototype.getGlobalPrivacyControl, - "WebDriver:SetGlobalPrivacyControl": - GeckoDriver.prototype.setGlobalPrivacyControl, + + // Global Privacy Control + "GPC:GetGlobalPrivacyControl": GeckoDriver.prototype.getGlobalPrivacyControl, + "GPC:SetGlobalPrivacyControl": GeckoDriver.prototype.setGlobalPrivacyControl, // WebAuthn "WebAuthn:AddVirtualAuthenticator": diff --git a/testing/geckodriver/marionette/src/webdriver.rs b/testing/geckodriver/marionette/src/webdriver.rs @@ -360,6 +360,10 @@ pub enum Command { SwitchToWindow(Window), #[serde(rename = "WebDriver:TakeScreenshot")] TakeScreenshot(ScreenshotOptions), + #[serde(rename = "GPC:GetGlobalPrivacyControl")] + GPCGetGlobalPrivacyControl, + #[serde(rename = "GPC:SetGlobalPrivacyControl")] + GPCSetGlobalPrivacyControl(GlobalPrivacyControlParameters), #[serde(rename = "WebAuthn:AddVirtualAuthenticator")] WebAuthnAddVirtualAuthenticator(AuthenticatorParameters), #[serde(rename = "WebAuthn:RemoveVirtualAuthenticator")] @@ -374,10 +378,6 @@ pub enum Command { WebAuthnRemoveAllCredentials, #[serde(rename = "WebAuthn:SetUserVerified")] WebAuthnSetUserVerified(UserVerificationParameters), - #[serde(rename = "WebAuthn:GetGlobalPrivacyControl")] - GetGlobalPrivacyControl, - #[serde(rename = "WebAuthn:SetGlobalPrivacyControl")] - SetGlobalPrivacyControl(GlobalPrivacyControlParameters), } #[cfg(test)] diff --git a/testing/geckodriver/src/marionette.rs b/testing/geckodriver/src/marionette.rs @@ -54,14 +54,14 @@ use webdriver::command::WebDriverCommand::{ AcceptAlert, AddCookie, CloseWindow, DeleteCookie, DeleteCookies, DeleteSession, DismissAlert, ElementClear, ElementClick, ElementSendKeys, ExecuteAsyncScript, ExecuteScript, Extension, FindElement, FindElementElement, FindElementElements, FindElements, FindShadowRootElement, - FindShadowRootElements, FullscreenWindow, Get, GetActiveElement, GetAlertText, GetCSSValue, - GetComputedLabel, GetComputedRole, GetCookies, GetCurrentUrl, GetElementAttribute, - GetElementProperty, GetElementRect, GetElementTagName, GetElementText, GetGlobalPrivacyControl, - GetNamedCookie, GetPageSource, GetShadowRoot, GetTimeouts, GetTitle, GetWindowHandle, - GetWindowHandles, GetWindowRect, GoBack, GoForward, IsDisplayed, IsEnabled, IsSelected, - MaximizeWindow, MinimizeWindow, NewSession, NewWindow, PerformActions, Print, Refresh, - ReleaseActions, SendAlertText, SetGlobalPrivacyControl, SetPermission, SetTimeouts, - SetWindowRect, Status, SwitchToFrame, SwitchToParentFrame, SwitchToWindow, + FindShadowRootElements, FullscreenWindow, GPCGetGlobalPrivacyControl, + GPCSetGlobalPrivacyControl, Get, GetActiveElement, GetAlertText, GetCSSValue, GetComputedLabel, + GetComputedRole, GetCookies, GetCurrentUrl, GetElementAttribute, GetElementProperty, + GetElementRect, GetElementTagName, GetElementText, GetNamedCookie, GetPageSource, + GetShadowRoot, GetTimeouts, GetTitle, GetWindowHandle, GetWindowHandles, GetWindowRect, GoBack, + GoForward, IsDisplayed, IsEnabled, IsSelected, MaximizeWindow, MinimizeWindow, NewSession, + NewWindow, PerformActions, Print, Refresh, ReleaseActions, SendAlertText, SetPermission, + SetTimeouts, SetWindowRect, Status, SwitchToFrame, SwitchToParentFrame, SwitchToWindow, TakeElementScreenshot, TakeScreenshot, WebAuthnAddCredential, WebAuthnAddVirtualAuthenticator, WebAuthnGetCredentials, WebAuthnRemoveAllCredentials, WebAuthnRemoveCredential, WebAuthnRemoveVirtualAuthenticator, WebAuthnSetUserVerified, @@ -470,15 +470,15 @@ impl MarionetteSession { | Print(_) | SetPermission(_) | TakeElementScreenshot(_) + | GPCGetGlobalPrivacyControl + | GPCSetGlobalPrivacyControl(_) | WebAuthnAddVirtualAuthenticator(_) | WebAuthnRemoveVirtualAuthenticator | WebAuthnAddCredential(_) | WebAuthnGetCredentials | WebAuthnRemoveCredential | WebAuthnRemoveAllCredentials - | WebAuthnSetUserVerified(_) - | GetGlobalPrivacyControl - | SetGlobalPrivacyControl(_) => { + | WebAuthnSetUserVerified(_) => { WebDriverResponse::Generic(resp.into_value_response(true)?) } GetTimeouts => { @@ -980,6 +980,12 @@ fn try_convert_to_marionette_message( Print(ref x) => Some(Command::WebDriver(MarionetteWebDriverCommand::Print( x.to_marionette()?, ))), + GPCGetGlobalPrivacyControl => Some(Command::WebDriver( + MarionetteWebDriverCommand::GPCGetGlobalPrivacyControl, + )), + GPCSetGlobalPrivacyControl(ref x) => Some(Command::WebDriver( + MarionetteWebDriverCommand::GPCSetGlobalPrivacyControl(x.to_marionette()?), + )), WebAuthnAddVirtualAuthenticator(ref x) => Some(Command::WebDriver( MarionetteWebDriverCommand::WebAuthnAddVirtualAuthenticator(x.to_marionette()?), )), @@ -1001,12 +1007,6 @@ fn try_convert_to_marionette_message( WebAuthnSetUserVerified(ref x) => Some(Command::WebDriver( MarionetteWebDriverCommand::WebAuthnSetUserVerified(x.to_marionette()?), )), - GetGlobalPrivacyControl => Some(Command::WebDriver( - MarionetteWebDriverCommand::GetGlobalPrivacyControl, - )), - SetGlobalPrivacyControl(ref x) => Some(Command::WebDriver( - MarionetteWebDriverCommand::SetGlobalPrivacyControl(x.to_marionette()?), - )), Refresh => Some(Command::WebDriver(MarionetteWebDriverCommand::Refresh)), ReleaseActions => Some(Command::WebDriver( MarionetteWebDriverCommand::ReleaseActions, diff --git a/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executormarionette.py b/testing/web-platform/tests/tools/wptrunner/wptrunner/executors/executormarionette.py @@ -630,13 +630,13 @@ class MarionetteGlobalPrivacyControlProtocolPart(GlobalPrivacyControlProtocolPar "gpc": gpc, } try: - return self.marionette._send_message("WebDriver:SetGlobalPrivacyControl", body)["value"] + return self.marionette._send_message("GPC:SetGlobalPrivacyControl", body)["value"] except errors.UnsupportedOperationException as e: raise NotImplementedError("set_global_privacy_control not yet implemented") from e def get_global_privacy_control(self): try: - return self.marionette._send_message("WebDriver:GetGlobalPrivacyControl")["value"] + return self.marionette._send_message("GPC:GetGlobalPrivacyControl")["value"] except errors.UnsupportedOperationException as e: raise NotImplementedError("get_global_privacy_control not yet implemented") from e diff --git a/testing/web-platform/tests/webdriver/tests/classic/global_privacy_control/__init__.py b/testing/web-platform/tests/webdriver/tests/classic/global_privacy_control/__init__.py diff --git a/testing/web-platform/tests/webdriver/tests/classic/global_privacy_control/get.py b/testing/web-platform/tests/webdriver/tests/classic/global_privacy_control/get.py @@ -0,0 +1,14 @@ +from tests.support.asserts import assert_success + + +def get_gpc(session): + return session.transport.send( + "GET", "/session/{session_id}/privacy".format( + session_id=session.session_id)) + + +def test_get_gpc(session): + response = get_gpc(session) + value = assert_success(response) + assert "gpc" in value + assert type(value["gpc"]) is bool diff --git a/testing/web-platform/tests/webdriver/tests/classic/global_privacy_control/set.py b/testing/web-platform/tests/webdriver/tests/classic/global_privacy_control/set.py @@ -0,0 +1,32 @@ +import pytest +from tests.support.asserts import assert_error, assert_success + + +def set_gpc(session, value): + return session.transport.send( + "POST", "/session/{session_id}/privacy".format( + session_id=session.session_id), {"gpc": value}) + +def get_gpc(session): + return session.transport.send( + "GET", "/session/{session_id}/privacy".format( + session_id=session.session_id)) + +@pytest.mark.parametrize("value", [True, False]) +def test_set_gpc_success(session, value): + response = set_gpc(session, value) + newValue = assert_success(response) + assert "gpc" in newValue + assert type(newValue["gpc"]) is bool + assert newValue["gpc"] == value + getResponse = get_gpc(session) + value = assert_success(getResponse) + assert "gpc" in value + assert type(value["gpc"]) is bool + assert newValue["gpc"] == value["gpc"] + + +@pytest.mark.parametrize("value", [None, 1, "hello", [], {}]) +def test_set_gpc_failure(session, value): + response = set_gpc(session, value) + error = assert_error(response, "invalid argument") diff --git a/testing/webdriver/src/command.rs b/testing/webdriver/src/command.rs @@ -81,6 +81,8 @@ pub enum WebDriverCommand<T: WebDriverExtensionCommand> { SetPermission(SetPermissionParameters), Status, Extension(T), + GPCSetGlobalPrivacyControl(GlobalPrivacyControlParameters), + GPCGetGlobalPrivacyControl, WebAuthnAddVirtualAuthenticator(AuthenticatorParameters), WebAuthnRemoveVirtualAuthenticator, WebAuthnAddCredential(CredentialParameters), @@ -88,8 +90,6 @@ pub enum WebDriverCommand<T: WebDriverExtensionCommand> { WebAuthnRemoveCredential, WebAuthnRemoveAllCredentials, WebAuthnSetUserVerified(UserVerificationParameters), - SetGlobalPrivacyControl(GlobalPrivacyControlParameters), - GetGlobalPrivacyControl, } pub trait WebDriverExtensionCommand: Clone + Send { @@ -415,6 +415,10 @@ impl<U: WebDriverExtensionRoute> WebDriverMessage<U> { } Route::Status => WebDriverCommand::Status, Route::Extension(ref extension) => extension.command(params, &body_data)?, + Route::GPCGetGlobalPrivacyControl => WebDriverCommand::GPCGetGlobalPrivacyControl, + Route::GPCSetGlobalPrivacyControl => { + WebDriverCommand::GPCSetGlobalPrivacyControl(serde_json::from_str(raw_body)?) + } Route::WebAuthnAddVirtualAuthenticator => { WebDriverCommand::WebAuthnAddVirtualAuthenticator(serde_json::from_str(raw_body)?) } @@ -430,10 +434,6 @@ impl<U: WebDriverExtensionRoute> WebDriverMessage<U> { Route::WebAuthnSetUserVerified => { WebDriverCommand::WebAuthnSetUserVerified(serde_json::from_str(raw_body)?) } - Route::GetGlobalPrivacyControl => WebDriverCommand::GetGlobalPrivacyControl, - Route::SetGlobalPrivacyControl => { - WebDriverCommand::SetGlobalPrivacyControl(serde_json::from_str(raw_body)?) - } }; Ok(WebDriverMessage::new(session_id, command)) } diff --git a/testing/webdriver/src/httpapi.rs b/testing/webdriver/src/httpapi.rs @@ -311,6 +311,16 @@ pub fn standard_routes<U: WebDriverExtensionRoute>() -> Vec<(Method, &'static st (Method::POST, "/session/{sessionId}/print", Route::Print), ( Method::POST, + "/session/{sessionId}/privacy", + Route::GPCSetGlobalPrivacyControl, + ), + ( + Method::GET, + "/session/{sessionId}/privacy", + Route::GPCGetGlobalPrivacyControl, + ), + ( + Method::POST, "/session/{sessionId}/webauthn/authenticator", Route::WebAuthnAddVirtualAuthenticator, ), @@ -344,16 +354,6 @@ pub fn standard_routes<U: WebDriverExtensionRoute>() -> Vec<(Method, &'static st "/session/{sessionId}/webauthn/authenticator/{authenticatorId}/uv", Route::WebAuthnSetUserVerified, ), - ( - Method::POST, - "/session/{sessionId}/privacy", - Route::SetGlobalPrivacyControl, - ), - ( - Method::GET, - "/session/{sessionId}/privacy", - Route::GetGlobalPrivacyControl, - ), (Method::GET, "/status", Route::Status), ] } @@ -428,6 +428,8 @@ pub enum Route<U: WebDriverExtensionRoute> { SetPermission, Status, Extension(U), + GPCGetGlobalPrivacyControl, + GPCSetGlobalPrivacyControl, WebAuthnAddVirtualAuthenticator, WebAuthnRemoveVirtualAuthenticator, WebAuthnAddCredential, @@ -435,8 +437,6 @@ pub enum Route<U: WebDriverExtensionRoute> { WebAuthnRemoveCredential, WebAuthnRemoveAllCredentials, WebAuthnSetUserVerified, - GetGlobalPrivacyControl, - SetGlobalPrivacyControl, } pub trait WebDriverExtensionRoute: Clone + Send + PartialEq {