@@ -31,7 +31,7 @@ import (
31
31
)
32
32
33
33
// Test calling Frame.document does not panic with a nil document.
34
- // See: issue #53 for details.
34
+ // See: Issue #53 for details.
35
35
func TestFrameNilDocument (t * testing.T ) {
36
36
t .Parallel ()
37
37
@@ -80,6 +80,40 @@ func TestFrameNilDocument(t *testing.T) {
80
80
require .Equal (t , want , got )
81
81
}
82
82
83
+ // See: Issue #177 for details.
84
+ func TestFrameManagerFrameAbortedNavigationShouldEmitANonNilPendingDocument (t * testing.T ) {
85
+ t .Parallel ()
86
+
87
+ ctx , log := context .Background (), NewNullLogger ()
88
+
89
+ // add the frame to frame manager
90
+ fm := NewFrameManager (ctx , nil , nil , NewTimeoutSettings (nil ), log )
91
+ frame := NewFrame (ctx , fm , nil , cdp .FrameID ("42" ), log )
92
+ fm .frames [frame .id ] = frame
93
+
94
+ // listen for frame navigation events
95
+ recv := make (chan Event )
96
+ frame .on (ctx , []string {EventFrameNavigation }, recv )
97
+
98
+ // emit the navigation event
99
+ frame .pendingDocument = & DocumentInfo {
100
+ documentID : "42" ,
101
+ }
102
+ fm .frameAbortedNavigation (frame .id , "any error" , frame .pendingDocument .documentID )
103
+
104
+ // receive the emitted event and verify that emitted document
105
+ // is not nil.
106
+ e := <- recv
107
+ require .IsType (t , & NavigationEvent {}, e .data , "event should be a navigation event" )
108
+ ne := e .data .(* NavigationEvent )
109
+ require .NotNil (t , ne , "event should not be nil" )
110
+ require .NotNil (t , ne .newDocument , "emitted document should not be nil" )
111
+
112
+ // since the navigation is aborted, the aborting frame should have
113
+ // a nil pending document.
114
+ require .Nil (t , frame .pendingDocument )
115
+ }
116
+
83
117
type executionContextTestStub struct {
84
118
ExecutionContext
85
119
evaluateFn func (apiCtx context.Context , opts evaluateOptions , pageFunc goja.Value , args ... goja.Value ) (res interface {}, err error )
0 commit comments