Skip to content

Commit

Permalink
Rename visual-viewport to display-feature
Browse files Browse the repository at this point in the history
Also added rest of the parameters which display-feature needs.
  • Loading branch information
JuhaVainio committed Mar 7, 2024
1 parent ebc5223 commit 6d08aa0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
10 changes: 5 additions & 5 deletions resources/testdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,9 +1036,9 @@
/**
* Sets the viewport orientation.
*/
async set_viewport_orientation(orientation, context=null) {
console.log('JV666 TEST_DRIVER testdriver.js set_viewport_orientation: ' + orientation);
return window.test_driver_internal.set_viewport_orientation(orientation, context);
async set_display_feature(orientation, offset, mask_length, context=null) {
console.log('JV666 TEST_DRIVER testdriver.js set_display_feature: ' + orientation + ' ' + offset + ' ' + mask_length);
return window.test_driver_internal.set_display_feature(orientation, offset, mask_length, context);
}
};

Expand Down Expand Up @@ -1225,8 +1225,8 @@
throw new Error("set_device_posture() is not implemented by testdriver-vendor.js");
},

async set_viewport_orientation(orientation, context=null) {
throw new Error("set_viewport_orientation() is not implemented by testdriver-vendor.js");
async set_display_feature(orientation, offset, mask_length, context=null) {
throw new Error("set_display_feature() is not implemented by testdriver-vendor.js");
}
};
})();
12 changes: 7 additions & 5 deletions tools/wptrunner/wptrunner/executors/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,19 @@ def __call__(self, payload):
self.logger.debug("JV666 tools/wptrunner/wptrunner/executors/actions.py set_device_posture: %s" % posture)
return self.protocol.device_posture.set_device_posture(posture)

class SetViewportOrientation:
name = "set_viewport_orientation"
class SetDisplayFeature:
name = "set_display_feature"

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

def __call__(self, payload):
orientation = payload["orientation"]
self.logger.debug("JV666 tools/wptrunner/wptrunner/executors/actions.py set_viewport_orientation: %s" % orientation)
return self.protocol.viewport.set_viewport_orientation(orientation)
offset = payload["offset"]
mask_length = payload["mask_length"]
self.logger.debug("JV666 tools/wptrunner/wptrunner/executors/actions.py set_display_feature: %s" % orientation)
return self.protocol.display_feature.set_display_feature(orientation, offset, mask_length)

actions = [ClickAction,
DeleteAllCookiesAction,
Expand Down Expand Up @@ -502,4 +504,4 @@ def __call__(self, payload):
RemoveVirtualSensorAction,
GetVirtualSensorInformationAction,
SetDevicePostureAction,
SetViewportOrientation]
SetDisplayFeature]
14 changes: 8 additions & 6 deletions tools/wptrunner/wptrunner/executors/executorwebdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
FedCMProtocolPart,
VirtualSensorProtocolPart,
DevicePostureProtocolPart,
ViewportProtocolPart,
DisplayFeatureProtocolPart,
merge_dicts)

from webdriver.client import Session
Expand Down Expand Up @@ -442,14 +442,16 @@ def set_device_posture(self, posture):
self.logger.debug("JV666 tools/wptrunner/wptrunner/executors/executorwebdriver.py set_device_posture: %s" % posture)
return self.webdriver.send_session_command("POST", "deviceposture", body)

class WebDriverViewportPart(ViewportProtocolPart):
class WebDriverDisplayFeaturePart(DisplayFeatureProtocolPart):
def setup(self):
self.webdriver = self.parent.webdriver

def set_viewport_orientation(self, orientation):
def set_display_feature(self, orientation, offset, mask_length):
body = {"orientation": orientation}
self.logger.debug("JV666 tools/wptrunner/wptrunner/executors/executorwebdriver.py set_viewport_orientation: %s" % orientation)
return self.webdriver.send_session_command("POST", "viewportsegments", body)
body.update({"offset": offset})
body.update({"maskLength": mask_length})
self.logger.debug("JV666 tools/wptrunner/wptrunner/executors/executorwebdriver.py set_display_feature: %s" % orientation)
return self.webdriver.send_session_command("POST", "displayfeature", body)

class WebDriverProtocol(Protocol):
implements = [WebDriverBaseProtocolPart,
Expand All @@ -471,7 +473,7 @@ class WebDriverProtocol(Protocol):
WebDriverDebugProtocolPart,
WebDriverVirtualSensorPart,
WebDriverDevicePosturePart,
WebDriverViewportPart]
WebDriverDisplayFeaturePart]

def __init__(self, executor, browser, capabilities, **kwargs):
super().__init__(executor, browser)
Expand Down
8 changes: 4 additions & 4 deletions tools/wptrunner/wptrunner/executors/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,12 +813,12 @@ class DevicePostureProtocolPart(ProtocolPart):
def set_device_posture(self, posture):
pass

class ViewportProtocolPart(ProtocolPart):
"""Protocol part for Viewport"""
class DisplayFeatureProtocolPart(ProtocolPart):
"""Protocol part for Display Feature"""
__metaclass__ = ABCMeta

name = "viewport"
name = "display_feature"

@abstractmethod
def set_viewport_orientation(self, orientation):
def set_display_feature(self, orientation, offset, mask_length):
pass
6 changes: 3 additions & 3 deletions tools/wptrunner/wptrunner/testdriver-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@
return create_action("set_device_posture", {posture, context});
};

window.test_driver_internal.set_viewport_orientation = function(orientation, context=null) {
console.log('JV666 TEST_DRIVER tools/wptrunner/wptrunner/testdriver-extra.js set_viewport_orientation: ' + orientation);
return create_action("set_viewport_orientation", {orientation, context});
window.test_driver_internal.set_display_feature = function(orientation, offset, mask_length, context=null) {
console.log('JV666 TEST_DRIVER tools/wptrunner/wptrunner/testdriver-extra.js set_display_feature: ' + orientation + ' ' + offset + ' ' + mask_length);
return create_action("set_display_feature", {orientation, offset, mask_length, context});
};
})();
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
assert_equals(visualViewport.segments, null, "For a viewport not segmented, no segments must be exposed.");

// HORIZONTAL
await test_driver.set_viewport_orientation('horizontal');
await test_driver.set_display_feature('horizontal', 380, 30);
assert_equals(window.visualViewport.segments.length, 2);
assert_true(matchMedia('(horizontal-viewport-segments: 1)').matches);
assert_true(matchMedia('(vertical-viewport-segments: 2)').matches);
Expand All @@ -30,10 +30,12 @@
{ once: true }
);
});
await test_driver.set_viewport_orientation('vertical');
await test_driver.set_display_feature('vertical', 390, 20);
assert_true(await promise)
assert_true(matchMedia('(horizontal-viewport-segments: 2)').matches);
assert_true(matchMedia('(vertical-viewport-segments: 1)').matches);
assert_not_equals(visualViewport.segments, null, "For a viewport segmented, segments must be exposed.");
console.log('JV666 visualViewport.segments: ' + JSON.stringify(visualViewport.segments, null, 2));
}, 'Viewport segments');
</script>

0 comments on commit 6d08aa0

Please sign in to comment.