Skip to content

Commit

Permalink
Rename to DefaultBrowserContextOptions
Browse files Browse the repository at this point in the history
NewBrowserContextOptions no longer makes sense.
DefaultBrowserContextOptions also reads better when we look at the code.
We can easily tell we're working with the default options, not just a
new BrowserContextOptions value.
  • Loading branch information
inancgumus committed Nov 7, 2024
1 parent 7ee71c5 commit 6e8c206
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion browser/browser_context_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestBrowserContextSetGeolocation(t *testing.T) {
func TestBrowserContextDefaultOptions(t *testing.T) {
vu := k6test.NewVU(t)

defaults := common.NewBrowserContextOptions()
defaults := common.DefaultBrowserContextOptions()

// gets the default options by default
opts, err := parseBrowserContextOptions(vu.Runtime(), nil)
Expand Down
2 changes: 1 addition & 1 deletion browser/browser_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func initBrowserContext(bctx *common.BrowserContext, testRunID string) error {

// parseBrowserContextOptions parses the [common.BrowserContext] options from a Sobek value.
func parseBrowserContextOptions(rt *sobek.Runtime, opts sobek.Value) (*common.BrowserContextOptions, error) {
b := common.NewBrowserContextOptions()
b := common.DefaultBrowserContextOptions()
if err := mergeWith(rt, b, opts); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion common/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (b *Browser) connect() error {
}

// We don't need to lock this because `connect()` is called only in NewBrowser
b.defaultContext, err = NewBrowserContext(b.vuCtx, b, "", NewBrowserContextOptions(), b.logger)
b.defaultContext, err = NewBrowserContext(b.vuCtx, b, "", DefaultBrowserContextOptions(), b.logger)
if err != nil {
return fmt.Errorf("browser connect: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func NewBrowserContext(
) (*BrowserContext, error) {
// set the default options if none provided.
if opts == nil {
opts = NewBrowserContextOptions()
opts = DefaultBrowserContextOptions()
}

b := BrowserContext{
Expand Down
4 changes: 2 additions & 2 deletions common/browser_context_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type BrowserContextOptions struct {
Viewport Viewport `js:"viewport"`
}

// NewBrowserContextOptions creates a default set of browser context options.
func NewBrowserContextOptions() *BrowserContextOptions {
// DefaultBrowserContextOptions returns the default browser context options.
func DefaultBrowserContextOptions() *BrowserContextOptions {
return &BrowserContextOptions{
ColorScheme: ColorSchemeLight,
DeviceScaleFactor: 1.0,
Expand Down
6 changes: 3 additions & 3 deletions tests/browser_context_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestBrowserContextOptionsDefaultValues(t *testing.T) {
t.Parallel()

opts := common.NewBrowserContextOptions()
opts := common.DefaultBrowserContextOptions()
assert.False(t, opts.AcceptDownloads)
assert.Empty(t, opts.DownloadsPath)
assert.False(t, opts.BypassCSP)
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestBrowserContextOptionsSetViewport(t *testing.T) {
t.Parallel()

tb := newTestBrowser(t)
opts := common.NewBrowserContextOptions()
opts := common.DefaultBrowserContextOptions()
opts.Viewport = common.Viewport{
Width: 800,
Height: 600,
Expand All @@ -77,7 +77,7 @@ func TestBrowserContextOptionsExtraHTTPHeaders(t *testing.T) {

tb := newTestBrowser(t, withHTTPServer())

opts := common.NewBrowserContextOptions()
opts := common.DefaultBrowserContextOptions()
opts.ExtraHTTPHeaders = map[string]string{
"Some-Header": "Some-Value",
}
Expand Down
2 changes: 1 addition & 1 deletion tests/element_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestElementHandleClickConcealedLink(t *testing.T) {

tb := newTestBrowser(t, withFileServer())

bcopts := common.NewBrowserContextOptions()
bcopts := common.DefaultBrowserContextOptions()
bcopts.Viewport = common.Viewport{
Width: 500,
Height: 240,
Expand Down
2 changes: 1 addition & 1 deletion tests/network_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestBasicAuth(t *testing.T) {

browser := newTestBrowser(t, withHTTPServer())

bcopts := common.NewBrowserContextOptions()
bcopts := common.DefaultBrowserContextOptions()
bcopts.HTTPCredentials = common.Credentials{
Username: validUser,
Password: validPassword,
Expand Down

0 comments on commit 6e8c206

Please sign in to comment.