Skip to content

Commit

Permalink
Add clear device posture and test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
JuhaVainio committed Apr 5, 2024
1 parent 21d943a commit 2ebcd5d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 2 deletions.
19 changes: 19 additions & 0 deletions device-posture/device-posture-clear.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
'use strict';

promise_test(async (t) => {
const originalPosture = navigator.devicePosture.type;
const posture = originalPosture ? 'folded' : 'continuous';

await test_driver.set_device_posture(posture);
assert_equals(navigator.devicePosture.type, posture);

await test_driver.clear_device_posture();
assert_equals(navigator.devicePosture.type, originalPosture);
}, 'Tests that device posture override can be removed.');
</script>
11 changes: 11 additions & 0 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,13 @@
set_device_posture: function(posture, context=null) {
return window.test_driver_internal.set_device_posture(posture, context);
},

/**
* Clears the device posture.
*/
clear_device_posture: function(context=null) {
return window.test_driver_internal.clear_device_posture(context);
},
};

window.test_driver_internal = {
Expand Down Expand Up @@ -1214,6 +1221,10 @@

async set_device_posture(posture, context=null) {
throw new Error("set_device_posture() is not implemented by testdriver-vendor.js");
},

async clear_device_posture(context=null) {
throw new Error("clear_device_posture() is not implemented by testdriver-vendor.js");
}
};
})();
13 changes: 12 additions & 1 deletion tools/wptrunner/wptrunner/executors/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,16 @@ def __call__(self, payload):
posture = payload["posture"]
return self.protocol.device_posture.set_device_posture(posture)

class ClearDevicePostureAction:
name = "clear_device_posture"

def __init__(self, logger, protocol):
self.logger = logger
self.protocol = protocol

def __call__(self, payload):
return self.protocol.device_posture.clear_device_posture()

actions = [ClickAction,
DeleteAllCookiesAction,
GetAllCookiesAction,
Expand Down Expand Up @@ -488,4 +498,5 @@ def __call__(self, payload):
UpdateVirtualSensorAction,
RemoveVirtualSensorAction,
GetVirtualSensorInformationAction,
SetDevicePostureAction]
SetDevicePostureAction,
ClearDevicePostureAction]
3 changes: 3 additions & 0 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@ def set_device_posture(self, posture):
body = {"posture": posture}
return self.webdriver.send_session_command("POST", "deviceposture", body)

def clear_device_posture(self):
return self.webdriver.send_session_command("DELETE", "deviceposture")

class WebDriverProtocol(Protocol):
implements = [WebDriverBaseProtocolPart,
WebDriverTestharnessProtocolPart,
Expand Down
4 changes: 4 additions & 0 deletions tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,7 @@ class DevicePostureProtocolPart(ProtocolPart):
@abstractmethod
def set_device_posture(self, posture):
pass

@abstractmethod
def clear_device_posture(self):
pass
6 changes: 5 additions & 1 deletion tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@
};

window.test_driver_internal.set_device_posture = function(posture, context=null) {
return create_action("set_device_posture", {posture, context});
return create_action("set_device_posture", {posture, context});
};

window.test_driver_internal.clear_device_posture = function(context=null) {
return create_action("clear_device_posture", {context});
};
})();

0 comments on commit 2ebcd5d

Please sign in to comment.