Skip to content

Commit

Permalink
fix: build and linters
Browse files Browse the repository at this point in the history
  • Loading branch information
route committed Jan 9, 2024
1 parent 4117050 commit 0d1b3e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 35 deletions.
19 changes: 7 additions & 12 deletions lib/ferrum/browser/options/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
36 changes: 13 additions & 23 deletions spec/browser/options/chrome_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0d1b3e9

Please sign in to comment.