Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: LayoutTests/http/tests/navigatorconnect/resources/test-helpers.js

Issue 812853002: Basic tests for sending messages over a navigator.connect initiated channel. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@navigator-connect_connect-tests
Patch Set: fix Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « LayoutTests/http/tests/navigatorconnect/resources/reply-client-info-worker.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Helper method that waits for a {success: <boolean>, result: any} reply on
2 // a port and returns a promise that resolves (if success is true) or rejects
3 // the promise with the value of the result attribute.
4 function reply_as_promise(t, port) {
5 return new Promise(function(resolve, reject) {
6 var got_reply = false;
7 port.onmessage = t.step_func(function(event) {
8 assert_false(got_reply);
9 assert_true('success' in event.data);
10 assert_true('result' in event.data);
11 got_reply = true;
12 if (event.data.success)
13 resolve(event.data.result);
14 else
15 reject(event.data.result);
16 });
17 });
18 }
19
20 // Method that behaves similarly to navigator.connect, but the actual connect
21 // call is made from a cross origin iframe.
22 function cross_origin_connect(t, service) {
23 // |service| is a relative URL, but for this to work from the iframe it needs
24 // an absolute URL.
25 var target_url = location.origin + base_path() + service;
26 return with_iframe(
27 cross_origin + base_path() + 'resources/connect-helper.html')
28 .then(function(iframe) {
29 var channel = new MessageChannel();
30 iframe.contentWindow.postMessage(
31 {connect: target_url, port: channel.port2}, '*', [channel.port2]);
32 return reply_as_promise(t, channel.port1);
33 });
34 }
35
36 // Method that behaves similarly to navigator.connect, but the actual connect
37 // call is made from a worker.
38 function connect_from_worker(t, service) {
39 // |service| is a relative URL, but for this to work from the worker it needs
40 // an absolute URL.
41 var target_url = location.origin + base_path() + service;
42 var worker = new Worker('resources/connect-helper.js');
43 var channel = new MessageChannel();
44 worker.postMessage
45 ({connect: target_url, port: channel.port2}, [channel.port2]);
46 return reply_as_promise(t, channel.port1);
47 }
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/navigatorconnect/resources/reply-client-info-worker.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698