Skip to content

Commit dffdd4e

Browse files
committed
Remove automatic resizing from Ferrum
This should really live at the Cuprite level, emulating specific devices.
1 parent bd9a2ca commit dffdd4e

File tree

2 files changed

+9
-58
lines changed

2 files changed

+9
-58
lines changed

lib/ferrum/page.rb

+9-26
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ def close_connection
138138
#
139139
# Overrides device screen dimensions and emulates viewport according to parameters.
140140
#
141-
# Note that passing mobile: true will cause set_viewport to ignore the passed
142-
# height and width values, and instead use 390 x 844, which is the viewport size
143-
# of an iPhone 14.
144-
#
145141
# Read more [here](https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setDeviceMetricsOverride).
146142
#
147143
# @param [Integer] width width value in pixels. 0 disables the override
@@ -159,37 +155,24 @@ def set_viewport(width:, height:, scale_factor: 0, mobile: false)
159155
enabled: true,
160156
maxTouchPoints: 1
161157
)
162-
163-
command(
164-
"Emulation.setDeviceMetricsOverride",
165-
deviceScaleFactor: 3.0,
166-
height: 844,
167-
mobile: true,
168-
slowmoable: true,
169-
width: 390
170-
)
171158
else
172159
command(
173160
"Emulation.setTouchEmulationEnabled",
174161
enabled: false
175162
)
176-
177-
command(
178-
"Emulation.setDeviceMetricsOverride",
179-
deviceScaleFactor: scale_factor,
180-
height: height,
181-
mobile: false,
182-
slowmoable: true,
183-
width: width
184-
)
185163
end
164+
165+
command(
166+
"Emulation.setDeviceMetricsOverride",
167+
deviceScaleFactor: 3.0,
168+
height: height,
169+
mobile: true,
170+
slowmoable: true,
171+
width: width
172+
)
186173
end
187174

188175
def resize(width: nil, height: nil, fullscreen: false, mobile: false)
189-
if mobile && (height != 0 || width != 0)
190-
raise "specifying `mobile: true` causes automatic resizing to mobile dimensions"
191-
end
192-
193176
if fullscreen
194177
width, height = document_size
195178
self.window_bounds = { window_state: "fullscreen" }

spec/page_spec.rb

-32
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,6 @@
188188
end
189189
end
190190

191-
describe "#set_viewport" do
192-
it "overrides the viewport size" do
193-
page.set_viewport(width: 500, height: 300, scale_factor: 2)
194-
195-
expect(page.viewport_size).to eq([500, 300])
196-
expect(page.device_pixel_ratio).to eq(2)
197-
end
198-
end
199-
200191
describe "#on" do
201192
it "subscribes to an event" do
202193
message = nil
@@ -277,29 +268,6 @@ def is_mobile?
277268
page.reload
278269
end.to change { is_mobile? }.to(true)
279270
end
280-
281-
it "resizes to the size of an iPhone 14 viewport, taking into account scale factor" do
282-
expect do
283-
page.resize(width: 0, height: 0, mobile: true)
284-
page.reload
285-
end.to change { body_size }.to(width: 980, height: 2120)
286-
end
287-
288-
context "when a height is passed" do
289-
it "raises an error" do
290-
expect do
291-
page.resize(width: 0, height: 100, mobile: true)
292-
end.to raise_error("specifying `mobile: true` causes automatic resizing to mobile dimensions")
293-
end
294-
end
295-
296-
context "when a width is passed" do
297-
it "raises an error" do
298-
expect do
299-
page.resize(width: 100, height: 0, mobile: true)
300-
end.to raise_error("specifying `mobile: true` causes automatic resizing to mobile dimensions")
301-
end
302-
end
303271
end
304272
end
305273
end

0 commit comments

Comments
 (0)