Skip to content

Commit

Permalink
fix race in test
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Oct 16, 2024
1 parent 7f44d39 commit f5c0418
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions v2/chrome_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ type ChromeTarget struct {
conn *WebSocket // the connection to the chrome debugger service for this tab/process

// Chrome Debugger Domains
Autofill *gcdapi.Autofill
Accessibility *gcdapi.Accessibility
Animation *gcdapi.Animation
Audits *gcdapi.Audits
BackgroundService *gcdapi.BackgroundService
BluetoothEmulation *gcdapi.BluetoothEmulation
Browser *gcdapi.Browser
CacheStorage *gcdapi.CacheStorage
Cast *gcdapi.Cast
Expand All @@ -91,10 +93,12 @@ type ChromeTarget struct {
DOMDebugger *gcdapi.DOMDebugger // DOM Debugger API
DOMSnapshot *gcdapi.DOMSnapshot
DOMStorage *gcdapi.DOMStorage // DOM Storage API
Extensions *gcdapi.Extensions
Emulation *gcdapi.Emulation
EventBreakpoints *gcdapi.EventBreakpoints
FedCm *gcdapi.FedCm
Fetch *gcdapi.Fetch
FileSystem *gcdapi.FileSystem
HeadlessExperimental *gcdapi.HeadlessExperimental
HeapProfiler *gcdapi.HeapProfiler // HeapProfiler API
IndexedDB *gcdapi.IndexedDB // IndexedDB API
Expand All @@ -112,6 +116,7 @@ type ChromeTarget struct {
PerformanceTimeline *gcdapi.PerformanceTimeline
Preload *gcdapi.Preload
Profiler *gcdapi.Profiler
PWA *gcdapi.PWA
Runtime *gcdapi.Runtime
Schema *gcdapi.Schema
Security *gcdapi.Security
Expand Down Expand Up @@ -165,11 +170,13 @@ func openChromeTarget(debugger *Gcd, target *TargetInfo, observer observer.Messa

// Init all api objects
func (c *ChromeTarget) Init() {
c.Autofill = gcdapi.NewAutofill(c)
c.Accessibility = gcdapi.NewAccessibility(c)
c.Animation = gcdapi.NewAnimation(c)
c.Audits = gcdapi.NewAudits(c)
c.BackgroundService = gcdapi.NewBackgroundService(c)
c.Browser = gcdapi.NewBrowser(c)
c.BluetoothEmulation = gcdapi.NewBluetoothEmulation(c)
c.CacheStorage = gcdapi.NewCacheStorage(c)
c.Cast = gcdapi.NewCast(c)
c.Console = gcdapi.NewConsole(c)
Expand All @@ -183,9 +190,11 @@ func (c *ChromeTarget) Init() {
c.DOMSnapshot = gcdapi.NewDOMSnapshot(c)
c.DOMStorage = gcdapi.NewDOMStorage(c)
c.Emulation = gcdapi.NewEmulation(c)
c.Extensions = gcdapi.NewExtensions(c)
c.EventBreakpoints = gcdapi.NewEventBreakpoints(c)
c.FedCm = gcdapi.NewFedCm(c)
c.Fetch = gcdapi.NewFetch(c)
c.FileSystem = gcdapi.NewFileSystem(c)
c.HeadlessExperimental = gcdapi.NewHeadlessExperimental(c)
c.HeapProfiler = gcdapi.NewHeapProfiler(c)
c.IndexedDB = gcdapi.NewIndexedDB(c)
Expand All @@ -203,6 +212,7 @@ func (c *ChromeTarget) Init() {
c.PerformanceTimeline = gcdapi.NewPerformanceTimeline(c)
c.Preload = gcdapi.NewPreload(c)
c.Profiler = gcdapi.NewProfiler(c)
c.PWA = gcdapi.NewPWA(c)
c.Runtime = gcdapi.NewRuntime(c)
c.Schema = gcdapi.NewSchema(c)
c.Security = gcdapi.NewSecurity(c)
Expand Down
10 changes: 7 additions & 3 deletions v2/gcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"runtime"
"runtime/pprof"
"strings"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -572,7 +573,9 @@ func TestNetworkIntercept(t *testing.T) {
}, false); err != nil {
t.Fatalf("error enabling fetch: %s", err)
}
continued := false

var continued atomic.Bool

target.Subscribe("Fetch.requestPaused", func(target *ChromeTarget, payload []byte) {

pausedEvent := &gcdapi.FetchRequestPausedEvent{}
Expand Down Expand Up @@ -600,15 +603,16 @@ func TestNetworkIntercept(t *testing.T) {
Headers: fetchHeaders,
}
target.Fetch.ContinueRequestWithParams(ctx, p)
continued = true
continued.Store(true)
})

params := &gcdapi.PageNavigateParams{Url: "http://www.example.com"}
_, _, _, err = target.Page.NavigateWithParams(testCtx, params)
if err != nil {
t.Fatalf("error navigating: %s\n", err)
}
if continued == false {

if continued.Load() == false {
t.Fatal("failed to intercept and continue request")
}
}
Expand Down

0 comments on commit f5c0418

Please sign in to comment.