Skip to content

Commit

Permalink
Add JS bindings long integer test. Add comments on DPI awareness.
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed Feb 16, 2021
1 parent 06d3b8c commit 0e2503c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions examples/hello_world.py
@@ -1,5 +1,12 @@
# Hello world example. Doesn't depend on any third party GUI framework.
# Tested with CEF Python v57.0+.
#
# ==== High DPI support on Windows ====
# To enable DPI awareness on Windows you have to either embed DPI aware manifest
# in your executable created with pyinstaller or change python.exe properties manually:
# Compatibility > High DPI scaling override > Application.
# Setting DPI awareness programmatically via a call to cef.DpiAware.EnableHighDpiSupport
# is problematic in Python, may not work and can cause display glitches.

from cefpython3 import cefpython as cef
import platform
Expand Down
26 changes: 18 additions & 8 deletions unittests/main_test.py
Expand Up @@ -58,17 +58,18 @@
print("test_function() ok");
// Test binding property: test_property1
if (test_property1 == "Test binding property to the 'window' object") {
if (test_property1 === "Test binding property to the 'window' object") {
print("test_property_1 ok");
} else {
throw new Error("test_property1 contains invalid string");
}
// Test binding property: test_property2
if (JSON.stringify(test_property2) == '{"key1":"Test binding property'+
' to the \\'window\\' object","key2":["Inside list",1,2]}') {
if (JSON.stringify(test_property2) === '{"key1":"Test binding property'+
' to the \\'window\\' object","key2":["Inside list",2147483647,"2147483648"]}') {
print("test_property2 ok");
} else {
print("test_property2 invalid value: " + JSON.stringify(test_property2));
throw new Error("test_property2 contains invalid value");
}
Expand All @@ -81,7 +82,7 @@
print("[TIMER] Call Python function and then js callback that was"+
" passed (Issue #277 test)");
external.test_callbacks(function(msg_from_python, py_callback){
if (msg_from_python == "String sent from Python") {
if (msg_from_python === "String sent from Python") {
print("test_callbacks() ok");
var execution_time = new Date().getTime() - start_time;
print("[TIMER]: Elapsed = "+String(execution_time)+" ms");
Expand Down Expand Up @@ -163,15 +164,23 @@ def test_main(self):
cef.LoadCrlSetsFile(crlset)
subtest_message("cef.LoadCrlSetsFile ok")

# High DPI on Windows
# High DPI on Windows.
# Setting DPI awareness from Python is usually too late and should be done
# via manifest file. Alternatively change python.exe properties > Compatibility
# > High DPI scaling override > Application.
# Using cef.DpiAware.EnableHighDpiSupport is problematic, it can cause
# display glitches.
if WINDOWS:
self.assertIsInstance(cef.DpiAware.GetSystemDpi(), tuple)
window_size = cef.DpiAware.CalculateWindowSize(800, 600)
self.assertIsInstance(window_size, tuple)
self.assertGreater(window_size[0], 0)
self.assertGreater(cef.DpiAware.Scale((800, 600))[0], 0)
cef.DpiAware.EnableHighDpiSupport()
self.assertTrue(cef.DpiAware.IsProcessDpiAware())

# OFF - see comments above.
# cef.DpiAware.EnableHighDpiSupport()
# self.assertTrue(cef.DpiAware.IsProcessDpiAware())

# Make some calls again after DPI Aware was set
self.assertIsInstance(cef.DpiAware.GetSystemDpi(), tuple)
self.assertGreater(cef.DpiAware.Scale([800, 600])[0], 0)
Expand Down Expand Up @@ -374,9 +383,10 @@ def __init__(self, test_case):
self.test_case = test_case

# Test binding properties to the 'window' object.
# 2147483648 is out of INT_MAX limit and will be sent to JS as string value.
self.test_property1 = "Test binding property to the 'window' object"
self.test_property2 = {"key1": self.test_property1,
"key2": ["Inside list", 1, 2]}
"key2": ["Inside list", 2147483647, 2147483648]}

# Asserts for True/False will be checked just before shutdown
self.test_for_True = True # Test whether asserts are working correctly
Expand Down

0 comments on commit 0e2503c

Please sign in to comment.