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

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

Issue 940423004: Add layout tests that test connecting to a system supplied navigator.connect service. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@n-c-expose-v8-context-from-port
Patch Set: actually test with transfer from an iframe Created 5 years, 9 months 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 | « no previous file | LayoutTests/http/tests/navigatorconnect/system-service.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Helper method that waits for a {success: <boolean>, result: any} reply on 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 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. 3 // the promise with the value of the result attribute.
4 function reply_as_promise(t, port) { 4 function reply_as_promise(t, port) {
5 return new Promise(function(resolve, reject) { 5 return new Promise(function(resolve, reject) {
6 var got_reply = false; 6 var got_reply = false;
7 port.onmessage = t.step_func(function(event) { 7 port.onmessage = t.step_func(function(event) {
8 assert_false(got_reply); 8 assert_false(got_reply);
9 assert_true('success' in event.data); 9 assert_true('success' in event.data);
10 assert_true('result' in event.data); 10 assert_true('result' in event.data);
11 got_reply = true; 11 got_reply = true;
12 if (event.data.success) 12 if (event.data.success)
13 resolve(event.data.result); 13 resolve(event.data.result);
14 else 14 else
15 reject(event.data.result); 15 reject(event.data.result);
16 }); 16 });
17 }); 17 });
18 } 18 }
19 19
20 // Method that behaves similarly to navigator.connect, but the actual connect 20 // Method that behaves similarly to navigator.connect, but the actual connect
21 // call is made from a cross origin iframe. 21 // call is made from a cross origin iframe.
22 function cross_origin_connect(t, service) { 22 function cross_origin_connect(t, service) {
23 // |service| is a relative URL, but for this to work from the iframe it needs 23 // |service| could be a relative URL, but for this to work from the iframe it
24 // an absolute URL. 24 // needs an absolute URL.
25 var target_url = location.origin + base_path() + service; 25 var target_url = new URL(service, location.origin + base_path());
26 return with_iframe( 26 return with_iframe(
27 cross_origin + base_path() + 'resources/connect-helper.html') 27 cross_origin + base_path() + 'resources/connect-helper.html')
28 .then(function(iframe) { 28 .then(function(iframe) {
29 var channel = new MessageChannel(); 29 var channel = new MessageChannel();
30 iframe.contentWindow.postMessage( 30 iframe.contentWindow.postMessage(
31 {connect: target_url, port: channel.port2}, '*', [channel.port2]); 31 {connect: target_url.href, port: channel.port2}, '*', [channel.port2]) ;
32 return reply_as_promise(t, channel.port1); 32 return reply_as_promise(t, channel.port1);
33 }); 33 });
34 } 34 }
35 35
36 // Method that behaves similarly to navigator.connect, but the actual connect 36 // Method that behaves similarly to navigator.connect, but the actual connect
37 // call is made from a worker. 37 // call is made from a worker.
38 function connect_from_worker(t, service) { 38 function connect_from_worker(t, service) {
39 // |service| is a relative URL, but for this to work from the worker it needs 39 // |service| is a relative URL, but for this to work from the worker it needs
40 // an absolute URL. 40 // an absolute URL.
41 var target_url = location.origin + base_path() + service; 41 var target_url = location.origin + base_path() + service;
42 var worker = new Worker('resources/connect-helper.js'); 42 var worker = new Worker('resources/connect-helper.js');
43 var channel = new MessageChannel(); 43 var channel = new MessageChannel();
44 worker.postMessage 44 worker.postMessage
45 ({connect: target_url, port: channel.port2}, [channel.port2]); 45 ({connect: target_url, port: channel.port2}, [channel.port2]);
46 return reply_as_promise(t, channel.port1); 46 return reply_as_promise(t, channel.port1);
47 } 47 }
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/navigatorconnect/system-service.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698