Skip to content

Commit 0d1b3e9

Browse files
committed
fix: build and linters
1 parent 4117050 commit 0d1b3e9

File tree

2 files changed

+20
-35
lines changed

2 files changed

+20
-35
lines changed

lib/ferrum/browser/options/chrome.rb

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,7 @@ class Chrome < Base
4242
# NOTE: --no-sandbox is not needed if you properly setup a user in the container.
4343
# https://github.com/ebidel/lighthouse-ci/blob/master/builder/Dockerfile#L35-L40
4444
# "no-sandbox" => nil,
45-
}
46-
# On Windows, the --disable-gpu flag is a temporary work around for a few bugs.
47-
# See crbug.com/737678 for more information.
48-
if Utils::Platform.windows?
49-
DEFAULT_OPTIONS.merge!("disable-gpu" => nil)
50-
end
51-
# Use Metal on Apple Silicon
52-
# https://github.com/google/angle#platform-support-via-backing-renderers
53-
if Utils::Platform.mac_arm?
54-
DEFAULT_OPTIONS.merge!("use-angle" => "metal")
55-
end
56-
DEFAULT_OPTIONS.freeze
45+
}.freeze
5746

5847
MAC_BIN_PATH = [
5948
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
@@ -94,6 +83,12 @@ def merge_default(flags, options)
9483
end
9584

9685
defaults ||= DEFAULT_OPTIONS
86+
# On Windows, the --disable-gpu flag is a temporary work around for a few bugs.
87+
# See https://bugs.chromium.org/p/chromium/issues/detail?id=737678 for more information.
88+
defaults = defaults.merge("disable-gpu" => nil) if Utils::Platform.windows?
89+
# Use Metal on Apple Silicon
90+
# https://github.com/google/angle#platform-support-via-backing-renderers
91+
defaults = defaults.merge("use-angle" => "metal") if Utils::Platform.mac_arm?
9792
defaults.merge(flags)
9893
end
9994
end
Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,28 @@
11
# frozen_string_literal: true
22

33
describe Ferrum::Browser::Options::Chrome do
4-
def reload_chrome_class
5-
described_class.constants(false).each do |const|
6-
described_class.send(:remove_const, const)
7-
end
8-
load 'ferrum/browser/options/chrome.rb'
9-
end
4+
let(:defaults) { described_class.options }
5+
let(:options) { Ferrum::Browser::Options.new }
106

11-
describe "DEFAULT_OPTIONS" do
12-
it "includes `disable-gpu` flag only on windows" do
7+
describe "#merge_default" do
8+
it "includes --disable-gpu flag on windows" do
139
allow(Ferrum::Utils::Platform).to receive(:windows?).and_return(true)
14-
reload_chrome_class
15-
expect(described_class::DEFAULT_OPTIONS).to include("disable-gpu" => nil)
10+
expect(defaults.merge_default({}, options)).to include("disable-gpu" => nil)
11+
end
1612

13+
it "excludes --disable-gpu flag on other platforms" do
1714
allow(Ferrum::Utils::Platform).to receive(:windows?).and_return(false)
18-
reload_chrome_class
19-
expect(described_class::DEFAULT_OPTIONS).not_to include("disable-gpu" => nil)
20-
21-
allow(Ferrum::Utils::Platform).to receive(:windows?).and_call_original
22-
reload_chrome_class
15+
expect(defaults.merge_default({}, options)).not_to include("disable-gpu" => nil)
2316
end
2417

25-
it "includes `use-angle=metal` flag only on mac arm" do
18+
it "includes --use-angle=metal flag on mac arm" do
2619
allow(Ferrum::Utils::Platform).to receive(:mac_arm?).and_return(true)
27-
reload_chrome_class
28-
expect(described_class::DEFAULT_OPTIONS).to include("use-angle" => "metal")
20+
expect(defaults.merge_default({}, options)).to include("use-angle" => "metal")
21+
end
2922

23+
it "excludes --use-angle=metal flag on mac arm" do
3024
allow(Ferrum::Utils::Platform).to receive(:mac_arm?).and_return(false)
31-
reload_chrome_class
32-
expect(described_class::DEFAULT_OPTIONS).not_to include("use-angle" => "metal")
33-
34-
allow(Ferrum::Utils::Platform).to receive(:mac_arm?).and_call_original
35-
reload_chrome_class
25+
expect(defaults.merge_default({}, options)).not_to include("use-angle" => "metal")
3626
end
3727
end
3828
end

0 commit comments

Comments
 (0)