Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions assets/runtime/android/files/android-runtime-1408/main-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
In NativeScript, a file with the same name as an XML file is known as
a code-behind file. The code-behind is a great place to place your view
logic, and to set up your page’s data binding.
*/

/*
NativeScript adheres to the CommonJS specification for dealing with
JavaScript modules. The CommonJS require() function is how you import
JavaScript modules defined in other files.
*/
const createViewModel = require("./main-view-model").createViewModel;

function onNavigatingTo(args) {
/*
This gets a reference this page’s <Page> UI component. You can
view the API reference of the Page to see what’s available at
https://docs.nativescript.org/api-reference/classes/_ui_page_.page.html
*/
const page = args.object;

/*
A page’s bindingContext is an object that should be used to perform
data binding between XML markup and JavaScript code. Properties
on the bindingContext can be accessed using the {{ }} syntax in XML.
In this example, the {{ message }} and {{ onTap }} bindings are resolved
against the object returned by createViewModel().

You can learn more about data binding in NativeScript at
https://docs.nativescript.org/core-concepts/data-binding.
*/
page.bindingContext = createViewModel();
}

let worker;
if (global.TNS_WEBPACK) {
const testWorker = require("nativescript-worker-loader!./worker.js");
worker = new testWorker();
} else {
worker = new Worker("./worker.js");
}
worker.onmessage = (msg) => {
console.dir(msg.data);
};
worker.onerror = function(err) {
console.log("Worker Error: ", err, err.stack);
};
/*
Exporting a function in a NativeScript code-behind file makes it accessible
to the file’s corresponding XML file. In this case, exporting the onNavigatingTo
function here makes the navigatingTo="onNavigatingTo" binding in this page’s XML
file work.
*/
exports.onNavigatingTo = onNavigatingTo;
8 changes: 8 additions & 0 deletions assets/runtime/android/files/android-runtime-1408/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require ("tns-core-modules/globals/globals");
// Give NS a couple seconds to get everything up on main thread...
setTimeout( () => { startWorker(); }, 3000);
function startWorker() {
let r1 = {blah: "a"}; // This is our row data...
let d = {Hi: "Hi", table1: [r1, r1], table2: [r1]}; // This is our final data...
global.postMessage({id: 1, data: d, data2: JSON.stringify(d)}); // Send it on thru
}
42 changes: 42 additions & 0 deletions tests/runtimes/android/android_runtime_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,48 @@ def test_446_test_print_stack_trace_in_release_and_debug(self):
timeout=15, period=5)
assert test_result, 'Error message in tns log cat should be shown! Logs:' + log_cat

def test_447_test_worker_post_message(self):
"""
https://github.com/NativeScript/android-runtime/issues/1408
"""

source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1408',
'main-page.js')
target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'main-page.js')
File.copy(source=source_js, target=target_js, backup_files=True)
source_js = os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'android', 'files', 'android-runtime-1408',
'worker.js')
target_js = os.path.join(TEST_RUN_HOME, APP_NAME, 'app', 'worker.js')
File.copy(source=source_js, target=target_js, backup_files=True)
log = Tns.run_android(APP_NAME, device=self.emulator.id, wait=False, verify=False)
correct_object = """JS: ==== object dump start ====
JS: id: "1"
JS: data: {
JS: "Hi": "Hi",
JS: "table1": [
JS: {
JS: "blah": "a"
JS: },
JS: {
JS: "blah": "a"
JS: }
JS: ],
JS: "table2": [
JS: {
JS: "blah": "a"
JS: }
JS: ]
JS: }
JS: data2: "{"Hi":"Hi","table1":[{"blah":"a"},{"blah":"a"}],"table2":[{"blah":"a"}]}"
JS: ==== object dump end ===="""
strings = ['Successfully synced application', 'Successfully installed on device with identifier']

test_result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
period=5)
assert test_result, 'Build was not successful! Logs:' + File.read(log.log_file)
test_result = Wait.until(lambda: correct_object in File.read(log.log_file), timeout=30, period=5)
assert test_result, 'Worker PostMessage Data is not correct! Logs:' + File.read(log.log_file)

def test_500_test_ES6_support(self):
"""
https://github.com/NativeScript/android-runtime/issues/1375
Expand Down