Skip to content

Commit

Permalink
Fix V8ContextHandler.OnContextCreated and OnContextReleased (cztomcza…
Browse files Browse the repository at this point in the history
…k#484).

These callbacks were never called previously.

Rename --no-run-examples flag to --unittests in build scripts.
  • Loading branch information
cztomczak committed Jan 17, 2020
1 parent e9116fa commit b03b78b
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
4 changes: 3 additions & 1 deletion api/V8ContextHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

# V8ContextHandler (interface)

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


Table of contents:
Expand Down
3 changes: 3 additions & 0 deletions src/browser.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ cdef class PyBrowser:
"OnScrollOffsetChanged",
"StartDragging", "UpdateDragCursor",
"OnTextSelectionChanged"]
# V8ContextHandler
self.allowedClientCallbacks += ["OnContextCreated",
"OnContextReleased"]
# JavascriptDialogHandler
self.allowedClientCallbacks += ["OnJavascriptDialog",
"OnBeforeUnloadJavascriptDialog",
Expand Down
23 changes: 13 additions & 10 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
from sources or use ready binaries from Spotify Automated Builds.
Usage:
build.py VERSION [--rebuild-cpp] [--fast] [--clean] [--kivy]
[--hello-world]
build.py VERSION [--rebuild-cpp] [--unittests] [--fast] [--clean] [--kivy]
[--hello-world] [--enable-profiling]
[--enable-line-tracing]
Options:
VERSION Version number eg. 50.0
--no-run-examples Do not run examples after build, only unit tests
--unittests Run only unit tests. Do not run examples while
building cefpython modules. Examples require
interaction such as closing window before proceeding.
--fast Fast mode
--clean Clean C++ projects build files on Linux/Mac
--kivy Run only Kivy example
Expand Down Expand Up @@ -79,7 +82,7 @@
# Command line args variables
SYS_ARGV_ORIGINAL = None
VERSION = ""
NO_RUN_EXAMPLES = False
UNITTESTS = False
DEBUG_FLAG = False
FAST_FLAG = False
CLEAN_FLAG = False
Expand Down Expand Up @@ -125,7 +128,7 @@ def main():

def command_line_args():
global DEBUG_FLAG, FAST_FLAG, CLEAN_FLAG, KIVY_FLAG, HELLO_WORLD_FLAG, \
REBUILD_CPP, VERSION, NO_RUN_EXAMPLES
REBUILD_CPP, VERSION, UNITTESTS

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

if "--no-run-examples" in sys.argv:
NO_RUN_EXAMPLES = True
print("[build.py] Running examples disabled (--no-run-examples)")
sys.argv.remove("--no-run-examples")
if "--unittests" in sys.argv:
UNITTESTS = True
print("[build.py] Running examples disabled (--unittests)")
sys.argv.remove("--unittests")

if "--debug" in sys.argv:
DEBUG_FLAG = True
Expand Down Expand Up @@ -913,7 +916,7 @@ def install_and_run():
sys.exit(1)

# Run examples
if not NO_RUN_EXAMPLES:
if not UNITTESTS:
print("[build.py] Run examples")
os.chdir(EXAMPLES_DIR)
flags = ""
Expand Down
23 changes: 12 additions & 11 deletions tools/build_distrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
python versions.
Usage:
build_distrib.py VERSION [--no-run-examples] [--no-rebuild]
build_distrib.py VERSION [--unittests] [--no-rebuild] [--no-automate]
[--allow-partial]
Options:
VERSION Version number eg. 50.0
--no-run-examples Do not run examples while building cefpython modules.
Examples require interaction, closing window before
proceeding. Only unit tests will be run in such case.
--unittests Run only unit tests. Do not run examples while building
cefpython modules. Examples require interaction such as
closing window before proceeding.
--no-rebuild Do not rebuild cefpython modules. For internal use
so that changes to packaging can be quickly tested.
--no-automate Do not run automate.py --prebuilt-cef. This flag
Expand Down Expand Up @@ -73,7 +74,7 @@

# Command line args
VERSION = ""
NO_RUN_EXAMPLES = False
UNITTESTS = False
NO_REBUILD = False
NO_AUTOMATE = False
ALLOW_PARTIAL = False
Expand Down Expand Up @@ -152,15 +153,15 @@ def main():


def command_line_args():
global VERSION, NO_RUN_EXAMPLES, NO_REBUILD, NO_AUTOMATE, ALLOW_PARTIAL
global VERSION, UNITTESTS, NO_REBUILD, NO_AUTOMATE, ALLOW_PARTIAL
version = get_version_from_command_line_args(__file__)
if not version or "--help" in sys.argv:
print(__doc__)
sys.exit(1)
VERSION = version
if "--no-run-examples" in sys.argv:
NO_RUN_EXAMPLES = True
sys.argv.remove("--no-run-examples")
if "--unittests" in sys.argv:
UNITTESTS = True
sys.argv.remove("--unittests")
if "--no-rebuild" in sys.argv:
NO_REBUILD = True
sys.argv.remove("--no-rebuild")
Expand Down Expand Up @@ -488,8 +489,8 @@ def build_cefpython_modules(pythons, arch):
print("[build_distrib.py] Build cefpython module for {python_name}"
.format(python_name=python["name"]))
flags = ""
if NO_RUN_EXAMPLES:
flags += " --no-run-examples"
if UNITTESTS:
flags += " --unittests"
# On Linux/Mac Makefiles are used and must pass --clean flag
command = ("\"{python}\" {build_py} {version} --clean {flags}"
.format(python=python["executable"],
Expand Down
5 changes: 3 additions & 2 deletions unittests/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def check_auto_asserts(test_case, objects):
test_for_True = False # Test whether asserts are working correctly
for key, value in obj.__dict__.items():
if key == "test_for_True":
test_for_True = True
test_for_True = value
continue
if "_True" in key:
test_case.assertTrue(value, "Check assert: " +
Expand All @@ -96,7 +96,8 @@ def check_auto_asserts(test_case, objects):
subtest_message(obj.__class__.__name__ + "." +
key.replace("_False", "") +
" ok")
test_case.assertTrue(test_for_True)
if "test_for_True" in obj.__dict__.keys():
test_case.assertTrue(test_for_True)


class DisplayHandler(object):
Expand Down
33 changes: 32 additions & 1 deletion unittests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ def test_main(self):

# Client handlers
display_handler2 = DisplayHandler2(self)
v8context_handler = V8ContextHandler(self)
client_handlers = [LoadHandler(self, g_datauri),
DisplayHandler(self),
display_handler2]
display_handler2,
v8context_handler]
for handler in client_handlers:
browser.SetClientHandler(handler)
subtest_message("browser.SetClientHandler() ok")
Expand Down Expand Up @@ -336,6 +338,35 @@ def OnLoadingProgressChange(self, progress, **_):
self.OnLoadingProgressChange_Progress = progress


class V8ContextHandler(object):
def __init__(self, test_case):
self.test_case = test_case
self.OnContextCreatedFirstCall_True = False
self.OnContextCreatedSecondCall_True = False
self.OnContextReleased_True = False

def OnContextCreated(self, browser, frame):
"""CEF creates one context when creating browser and this one is
released immediately. Then when it loads url another context is
created."""
if not self.OnContextCreatedFirstCall_True:
self.OnContextCreatedFirstCall_True = True
else:
self.test_case.assertFalse(self.OnContextCreatedSecondCall_True)
self.OnContextCreatedSecondCall_True = True
self.test_case.assertEqual(browser.GetIdentifier(), MAIN_BROWSER_ID)
self.test_case.assertEqual(frame.GetIdentifier(), 2)

def OnContextReleased(self, browser, frame):
"""This gets called only for the initial empty context, see comment
in OnContextCreated. This should never get called for the main frame
of the main browser, because it happens during app exit and there
isn't enough time for the IPC messages to go through."""
self.test_case.assertFalse(self.OnContextReleased_True)
self.OnContextReleased_True = True
self.test_case.assertEqual(browser.GetIdentifier(), MAIN_BROWSER_ID)
self.test_case.assertEqual(frame.GetIdentifier(), 2)

class External(object):
"""Javascript 'window.external' object."""

Expand Down

0 comments on commit b03b78b

Please sign in to comment.