expose the default allocator options

For example, this can be useful if a user wants to simply add one flag
of their own, without otherwise messing with the default flags. In the
old codebase, they'd either have to build their own list from scratch,
or copy ours from source, needing to keep it in sync.
This commit is contained in:
Daniel Martí 2019-04-17 13:17:01 +09:00
parent 71ae9f7bbc
commit e4c16681d0
3 changed files with 18 additions and 11 deletions

View File

@ -43,6 +43,14 @@ func setupExecAllocator(opts ...ExecAllocatorOption) *ExecAllocator {
return ep
}
// DefaultExecAllocatorOptions are the ExecAllocator options used by NewContext
// if the given parent context doesn't have an allocator set up.
var DefaultExecAllocatorOptions = []ExecAllocatorOption{
NoFirstRun,
NoDefaultBrowserCheck,
Headless,
}
// NewExecAllocator creates a new context set up with an ExecAllocator, suitable
// for use with NewContext or Run.
func NewExecAllocator(parent context.Context, opts ...ExecAllocatorOption) (context.Context, context.CancelFunc) {

View File

@ -80,11 +80,7 @@ func NewContext(parent context.Context, opts ...ContextOption) (context.Context,
o(c)
}
if c.Allocator == nil {
c.Allocator = setupExecAllocator(
NoFirstRun,
NoDefaultBrowserCheck,
Headless,
)
c.Allocator = setupExecAllocator(DefaultExecAllocatorOptions...)
}
ctx = context.WithValue(ctx, contextKey{}, c)

View File

@ -17,12 +17,8 @@ var (
browserCtx context.Context
allocOpts = []ExecAllocatorOption{
NoFirstRun,
NoDefaultBrowserCheck,
Headless,
DisableGPU,
}
// allocOpts is filled in TestMain
allocOpts []ExecAllocatorOption
)
func testAllocate(t *testing.T, path string) (_ context.Context, cancel func()) {
@ -52,6 +48,13 @@ func TestMain(m *testing.M) {
}
testdataDir = "file://" + path.Join(wd, "testdata")
// build on top of the default options
allocOpts = append(allocOpts, DefaultExecAllocatorOptions...)
// disabling the GPU helps portability with some systems like Travis,
// and can slightly speed up the tests on other systems
allocOpts = append(allocOpts, DisableGPU)
// it's worth noting that newer versions of chrome (64+) run much faster
// than older ones -- same for headless_shell ...
if execPath := os.Getenv("CHROMEDP_TEST_RUNNER"); execPath != "" {