| <!DOCTYPE html> |
| <!-- |
| Copyright 2022 The Cobalt Authors. All Rights Reserved. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <!-- |
| Note: This is a very basic test of the existing minimal Web Worker |
| functionality. This can be expanded as more functionality is implemented, |
| but probably will be superseded by Web Platform Tests. |
| --> |
| <head> |
| <title>Cobalt Web Worker Test</title> |
| <script src='black_box_js_test_utils.js'></script> |
| </head> |
| |
| <body> |
| <script> |
| var message_event_count = 0; |
| console.log('running'); |
| var worker = new Worker('web_worker_test.js'); |
| console.log(worker); |
| var data = "window data"; |
| worker.onmessage = function (event) { |
| console.log('window got onmessage from worker: ' + event.data); |
| message_event_count += 1; |
| if (message_event_count == 1) { |
| assertEqual(event.data, 'worker data'); |
| } else if (message_event_count % 2 == 0) { |
| assertEqual(event.data, 'worker received correct message'); |
| } else { |
| assertEqual(event.data, data.toUpperCase()); |
| } |
| if (message_event_count == 5) { |
| window.setTimeout( |
| () => { |
| assertEqual(message_event_count, 5); |
| onEndTest(); |
| }, 250); |
| } |
| if (message_event_count > 5) { |
| notReached(); |
| } |
| }; |
| worker.onerror = function (event) { |
| console.log('window got onerror'); |
| notReached(); |
| }; |
| console.log('posting', data); |
| worker.postMessage(data); |
| window.setTimeout( |
| () => { console.log('posting', data); worker.postMessage(data); }, 250); |
| console.log('end'); |
| </script> |
| </body> |