diff --git a/lib/ferrum/browser/options/chrome.rb b/lib/ferrum/browser/options/chrome.rb index 5a38378c..14c1e1c0 100644 --- a/lib/ferrum/browser/options/chrome.rb +++ b/lib/ferrum/browser/options/chrome.rb @@ -42,18 +42,7 @@ class Chrome < Base # NOTE: --no-sandbox is not needed if you properly setup a user in the container. # https://github.com/ebidel/lighthouse-ci/blob/master/builder/Dockerfile#L35-L40 # "no-sandbox" => nil, - } - # On Windows, the --disable-gpu flag is a temporary work around for a few bugs. - # See crbug.com/737678 for more information. - if Utils::Platform.windows? - DEFAULT_OPTIONS.merge!("disable-gpu" => nil) - end - # Use Metal on Apple Silicon - # https://github.com/google/angle#platform-support-via-backing-renderers - if Utils::Platform.mac_arm? - DEFAULT_OPTIONS.merge!("use-angle" => "metal") - end - DEFAULT_OPTIONS.freeze + }.freeze MAC_BIN_PATH = [ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", @@ -94,6 +83,12 @@ def merge_default(flags, options) end defaults ||= DEFAULT_OPTIONS + # On Windows, the --disable-gpu flag is a temporary work around for a few bugs. + # See https://bugs.chromium.org/p/chromium/issues/detail?id=737678 for more information. + defaults = defaults.merge("disable-gpu" => nil) if Utils::Platform.windows? + # Use Metal on Apple Silicon + # https://github.com/google/angle#platform-support-via-backing-renderers + defaults = defaults.merge("use-angle" => "metal") if Utils::Platform.mac_arm? defaults.merge(flags) end end diff --git a/spec/browser/options/chrome_spec.rb b/spec/browser/options/chrome_spec.rb index 322939a7..d02f730a 100644 --- a/spec/browser/options/chrome_spec.rb +++ b/spec/browser/options/chrome_spec.rb @@ -1,38 +1,28 @@ # frozen_string_literal: true describe Ferrum::Browser::Options::Chrome do - def reload_chrome_class - described_class.constants(false).each do |const| - described_class.send(:remove_const, const) - end - load 'ferrum/browser/options/chrome.rb' - end + let(:defaults) { described_class.options } + let(:options) { Ferrum::Browser::Options.new } - describe "DEFAULT_OPTIONS" do - it "includes `disable-gpu` flag only on windows" do + describe "#merge_default" do + it "includes --disable-gpu flag on windows" do allow(Ferrum::Utils::Platform).to receive(:windows?).and_return(true) - reload_chrome_class - expect(described_class::DEFAULT_OPTIONS).to include("disable-gpu" => nil) + expect(defaults.merge_default({}, options)).to include("disable-gpu" => nil) + end + it "excludes --disable-gpu flag on other platforms" do allow(Ferrum::Utils::Platform).to receive(:windows?).and_return(false) - reload_chrome_class - expect(described_class::DEFAULT_OPTIONS).not_to include("disable-gpu" => nil) - - allow(Ferrum::Utils::Platform).to receive(:windows?).and_call_original - reload_chrome_class + expect(defaults.merge_default({}, options)).not_to include("disable-gpu" => nil) end - it "includes `use-angle=metal` flag only on mac arm" do + it "includes --use-angle=metal flag on mac arm" do allow(Ferrum::Utils::Platform).to receive(:mac_arm?).and_return(true) - reload_chrome_class - expect(described_class::DEFAULT_OPTIONS).to include("use-angle" => "metal") + expect(defaults.merge_default({}, options)).to include("use-angle" => "metal") + end + it "excludes --use-angle=metal flag on mac arm" do allow(Ferrum::Utils::Platform).to receive(:mac_arm?).and_return(false) - reload_chrome_class - expect(described_class::DEFAULT_OPTIONS).not_to include("use-angle" => "metal") - - allow(Ferrum::Utils::Platform).to receive(:mac_arm?).and_call_original - reload_chrome_class + expect(defaults.merge_default({}, options)).not_to include("use-angle" => "metal") end end end