@@ -197,9 +197,11 @@ def test_main(self):
197197
198198 # Client handlers
199199 display_handler2 = DisplayHandler2 (self )
200+ v8context_handler = V8ContextHandler (self )
200201 client_handlers = [LoadHandler (self , g_datauri ),
201202 DisplayHandler (self ),
202- display_handler2 ]
203+ display_handler2 ,
204+ v8context_handler ]
203205 for handler in client_handlers :
204206 browser .SetClientHandler (handler )
205207 subtest_message ("browser.SetClientHandler() ok" )
@@ -336,6 +338,35 @@ def OnLoadingProgressChange(self, progress, **_):
336338 self .OnLoadingProgressChange_Progress = progress
337339
338340
341+ class V8ContextHandler (object ):
342+ def __init__ (self , test_case ):
343+ self .test_case = test_case
344+ self .OnContextCreatedFirstCall_True = False
345+ self .OnContextCreatedSecondCall_True = False
346+ self .OnContextReleased_True = False
347+
348+ def OnContextCreated (self , browser , frame ):
349+ """CEF creates one context when creating browser and this one is
350+ released immediately. Then when it loads url another context is
351+ created."""
352+ if not self .OnContextCreatedFirstCall_True :
353+ self .OnContextCreatedFirstCall_True = True
354+ else :
355+ self .test_case .assertFalse (self .OnContextCreatedSecondCall_True )
356+ self .OnContextCreatedSecondCall_True = True
357+ self .test_case .assertEqual (browser .GetIdentifier (), MAIN_BROWSER_ID )
358+ self .test_case .assertEqual (frame .GetIdentifier (), 2 )
359+
360+ def OnContextReleased (self , browser , frame ):
361+ """This gets called only for the initial empty context, see comment
362+ in OnContextCreated. This should never get called for the main frame
363+ of the main browser, because it happens during app exit and there
364+ isn't enough time for the IPC messages to go through."""
365+ self .test_case .assertFalse (self .OnContextReleased_True )
366+ self .OnContextReleased_True = True
367+ self .test_case .assertEqual (browser .GetIdentifier (), MAIN_BROWSER_ID )
368+ self .test_case .assertEqual (frame .GetIdentifier (), 2 )
369+
339370class External (object ):
340371 """Javascript 'window.external' object."""
341372
0 commit comments