| 348 | |
| 349 | |
| 350 | class V8ContextHandler(object): |
| 351 | def __init__(self, test_case): |
| 352 | self.test_case = test_case |
| 353 | self.OnContextCreatedFirstCall_True = False |
| 354 | self.OnContextCreatedSecondCall_True = False |
| 355 | self.OnContextReleased_True = False |
| 356 | |
| 357 | def OnContextCreated(self, browser, frame): |
| 358 | """CEF creates one context when creating browser and this one is |
| 359 | released immediately. Then when it loads url another context is |
| 360 | created.""" |
| 361 | if not self.OnContextCreatedFirstCall_True: |
| 362 | self.OnContextCreatedFirstCall_True = True |
| 363 | else: |
| 364 | self.test_case.assertFalse(self.OnContextCreatedSecondCall_True) |
| 365 | self.OnContextCreatedSecondCall_True = True |
| 366 | self.test_case.assertEqual(browser.GetIdentifier(), MAIN_BROWSER_ID) |
| 367 | self.test_case.assertEqual(frame.GetIdentifier(), 2) |
| 368 | |
| 369 | def OnContextReleased(self, browser, frame): |
| 370 | """This gets called only for the initial empty context, see comment |
| 371 | in OnContextCreated. This should never get called for the main frame |
| 372 | of the main browser, because it happens during app exit and there |
| 373 | isn't enough time for the IPC messages to go through.""" |
| 374 | self.test_case.assertFalse(self.OnContextReleased_True) |
| 375 | self.OnContextReleased_True = True |
| 376 | self.test_case.assertEqual(browser.GetIdentifier(), MAIN_BROWSER_ID) |
| 377 | self.test_case.assertEqual(frame.GetIdentifier(), 2) |
| 378 | |
| 379 | class External(object): |
| 380 | """Javascript 'window.external' object.""" |