Skip to content

Commit 3ba27d8

Browse files
committed
add spec: 'resizes to 'normal' from 'fullscreen' window state'
1 parent f7659f0 commit 3ba27d8

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/ferrum/page.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,12 @@ def close
9090
end
9191

9292
def resize(width: nil, height: nil, fullscreen: false)
93-
@window_id = @browser.command("Browser.getWindowForTarget", targetId: @target_id)["windowId"]
94-
9593
if fullscreen
9694
width, height = document_size
97-
@browser.command("Browser.setWindowBounds", windowId: @window_id, bounds: { windowState: "fullscreen" })
95+
set_window_bounds(windowState: "fullscreen")
9896
else
99-
@browser.command("Browser.setWindowBounds", windowId: @window_id, bounds: { windowState: "normal" })
100-
@browser.command("Browser.setWindowBounds", windowId: @window_id, bounds: { width: width, height: height })
97+
set_window_bounds(windowState: "normal")
98+
set_window_bounds(width: width, height: height)
10199
end
102100

103101
command("Emulation.setDeviceMetricsOverride", slowmoable: true,
@@ -137,6 +135,14 @@ def bypass_csp(value = true)
137135
enabled
138136
end
139137

138+
def window_id
139+
@browser.command("Browser.getWindowForTarget", targetId: @target_id)["windowId"]
140+
end
141+
142+
def set_window_bounds(bounds = {})
143+
@browser.command("Browser.setWindowBounds", windowId: window_id, bounds: bounds)
144+
end
145+
140146
def command(method, wait: 0, slowmoable: false, **params)
141147
iteration = @event.reset if wait > 0
142148
sleep(@browser.slowmo) if slowmoable && @browser.slowmo > 0

spec/browser_spec.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,11 @@ module Ferrum
9999

100100
context 'fullscreen' do
101101
shared_examples 'resize viewport by fullscreen' do
102-
it "allows the viewport to be resized to fullscreen and back" do
102+
it "allows the viewport to be resized by fullscreen" do
103103
expect(browser.viewport_size).to eq([1024, 768])
104104
browser.go_to(path)
105105
browser.resize(fullscreen: true)
106106
expect(browser.viewport_size).to eq(viewport_size)
107-
browser.resize(width: 200, height: 400)
108-
expect(browser.viewport_size).to eq([200, 400])
109107
end
110108
end
111109

@@ -118,6 +116,13 @@ module Ferrum
118116
let(:path) { "/ferrum/custom_html_size_100%" }
119117
let(:viewport_size) { [1272, 1008] }
120118
end
119+
120+
it "resizes to 'normal' from 'fullscreen' window state" do
121+
browser.go_to(path)
122+
browser.resize(fullscreen: true)
123+
browser.resize(width: 200, height: 400)
124+
expect(browser.viewport_size).to eq([200, 400])
125+
end
121126
end
122127

123128
it "allows the page to be scrolled" do

0 commit comments

Comments
 (0)