Skip to content

Commit b03b78b

Browse files
committed
Fix V8ContextHandler.OnContextCreated and OnContextReleased (cztomczak#484).
These callbacks were never called previously. Rename --no-run-examples flag to --unittests in build scripts.
1 parent e9116fa commit b03b78b

6 files changed

Lines changed: 66 additions & 25 deletions

File tree

api/V8ContextHandler.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
# V8ContextHandler (interface)
55

6-
Implement this interface to handle javascript exceptions globally.
6+
Implement this interface to handle render process callbacks.
7+
Through inter-process messaging you are notified about these events
8+
in the browser process.
79

810

911
Table of contents:

src/browser.pyx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ cdef class PyBrowser:
267267
"OnScrollOffsetChanged",
268268
"StartDragging", "UpdateDragCursor",
269269
"OnTextSelectionChanged"]
270+
# V8ContextHandler
271+
self.allowedClientCallbacks += ["OnContextCreated",
272+
"OnContextReleased"]
270273
# JavascriptDialogHandler
271274
self.allowedClientCallbacks += ["OnJavascriptDialog",
272275
"OnBeforeUnloadJavascriptDialog",

tools/build.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
from sources or use ready binaries from Spotify Automated Builds.
1919
2020
Usage:
21-
build.py VERSION [--rebuild-cpp] [--fast] [--clean] [--kivy]
22-
[--hello-world]
21+
build.py VERSION [--rebuild-cpp] [--unittests] [--fast] [--clean] [--kivy]
22+
[--hello-world] [--enable-profiling]
23+
[--enable-line-tracing]
2324
2425
Options:
2526
VERSION Version number eg. 50.0
26-
--no-run-examples Do not run examples after build, only unit tests
27+
--unittests Run only unit tests. Do not run examples while
28+
building cefpython modules. Examples require
29+
interaction such as closing window before proceeding.
2730
--fast Fast mode
2831
--clean Clean C++ projects build files on Linux/Mac
2932
--kivy Run only Kivy example
@@ -79,7 +82,7 @@
7982
# Command line args variables
8083
SYS_ARGV_ORIGINAL = None
8184
VERSION = ""
82-
NO_RUN_EXAMPLES = False
85+
UNITTESTS = False
8386
DEBUG_FLAG = False
8487
FAST_FLAG = False
8588
CLEAN_FLAG = False
@@ -125,7 +128,7 @@ def main():
125128

126129
def command_line_args():
127130
global DEBUG_FLAG, FAST_FLAG, CLEAN_FLAG, KIVY_FLAG, HELLO_WORLD_FLAG, \
128-
REBUILD_CPP, VERSION, NO_RUN_EXAMPLES
131+
REBUILD_CPP, VERSION, UNITTESTS
129132

130133
VERSION = get_version_from_command_line_args(__file__)
131134
# Other scripts called by this script expect that version number
@@ -140,10 +143,10 @@ def command_line_args():
140143
global SYS_ARGV_ORIGINAL
141144
SYS_ARGV_ORIGINAL = copy.copy(sys.argv)
142145

143-
if "--no-run-examples" in sys.argv:
144-
NO_RUN_EXAMPLES = True
145-
print("[build.py] Running examples disabled (--no-run-examples)")
146-
sys.argv.remove("--no-run-examples")
146+
if "--unittests" in sys.argv:
147+
UNITTESTS = True
148+
print("[build.py] Running examples disabled (--unittests)")
149+
sys.argv.remove("--unittests")
147150

148151
if "--debug" in sys.argv:
149152
DEBUG_FLAG = True
@@ -913,7 +916,7 @@ def install_and_run():
913916
sys.exit(1)
914917

915918
# Run examples
916-
if not NO_RUN_EXAMPLES:
919+
if not UNITTESTS:
917920
print("[build.py] Run examples")
918921
os.chdir(EXAMPLES_DIR)
919922
flags = ""

tools/build_distrib.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
python versions.
88
99
Usage:
10-
build_distrib.py VERSION [--no-run-examples] [--no-rebuild]
10+
build_distrib.py VERSION [--unittests] [--no-rebuild] [--no-automate]
11+
[--allow-partial]
1112
1213
Options:
1314
VERSION Version number eg. 50.0
14-
--no-run-examples Do not run examples while building cefpython modules.
15-
Examples require interaction, closing window before
16-
proceeding. Only unit tests will be run in such case.
15+
--unittests Run only unit tests. Do not run examples while building
16+
cefpython modules. Examples require interaction such as
17+
closing window before proceeding.
1718
--no-rebuild Do not rebuild cefpython modules. For internal use
1819
so that changes to packaging can be quickly tested.
1920
--no-automate Do not run automate.py --prebuilt-cef. This flag
@@ -73,7 +74,7 @@
7374

7475
# Command line args
7576
VERSION = ""
76-
NO_RUN_EXAMPLES = False
77+
UNITTESTS = False
7778
NO_REBUILD = False
7879
NO_AUTOMATE = False
7980
ALLOW_PARTIAL = False
@@ -152,15 +153,15 @@ def main():
152153

153154

154155
def command_line_args():
155-
global VERSION, NO_RUN_EXAMPLES, NO_REBUILD, NO_AUTOMATE, ALLOW_PARTIAL
156+
global VERSION, UNITTESTS, NO_REBUILD, NO_AUTOMATE, ALLOW_PARTIAL
156157
version = get_version_from_command_line_args(__file__)
157158
if not version or "--help" in sys.argv:
158159
print(__doc__)
159160
sys.exit(1)
160161
VERSION = version
161-
if "--no-run-examples" in sys.argv:
162-
NO_RUN_EXAMPLES = True
163-
sys.argv.remove("--no-run-examples")
162+
if "--unittests" in sys.argv:
163+
UNITTESTS = True
164+
sys.argv.remove("--unittests")
164165
if "--no-rebuild" in sys.argv:
165166
NO_REBUILD = True
166167
sys.argv.remove("--no-rebuild")
@@ -488,8 +489,8 @@ def build_cefpython_modules(pythons, arch):
488489
print("[build_distrib.py] Build cefpython module for {python_name}"
489490
.format(python_name=python["name"]))
490491
flags = ""
491-
if NO_RUN_EXAMPLES:
492-
flags += " --no-run-examples"
492+
if UNITTESTS:
493+
flags += " --unittests"
493494
# On Linux/Mac Makefiles are used and must pass --clean flag
494495
command = ("\"{python}\" {build_py} {version} --clean {flags}"
495496
.format(python=python["executable"],

unittests/_common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def check_auto_asserts(test_case, objects):
8282
test_for_True = False # Test whether asserts are working correctly
8383
for key, value in obj.__dict__.items():
8484
if key == "test_for_True":
85-
test_for_True = True
85+
test_for_True = value
8686
continue
8787
if "_True" in key:
8888
test_case.assertTrue(value, "Check assert: " +
@@ -96,7 +96,8 @@ def check_auto_asserts(test_case, objects):
9696
subtest_message(obj.__class__.__name__ + "." +
9797
key.replace("_False", "") +
9898
" ok")
99-
test_case.assertTrue(test_for_True)
99+
if "test_for_True" in obj.__dict__.keys():
100+
test_case.assertTrue(test_for_True)
100101

101102

102103
class DisplayHandler(object):

unittests/main_test.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
339370
class External(object):
340371
"""Javascript 'window.external' object."""
341372

0 commit comments

Comments
 (0)