Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
01d6718f
Commit
01d6718f
authored
Jan 20, 2022
by
Eduardo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply suggestions from code review
Co-authored-by:
Robert Knight
<
robertknight@gmail.com
>
parent
82d8ea93
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
90 deletions
+90
-90
inter-frame-communication-test.js
...shared/test/integration/inter-frame-communication-test.js
+90
-90
No files found.
src/shared/test/integration/inter-frame-communication-test.js
View file @
01d6718f
...
...
@@ -49,32 +49,30 @@ describe('PortProvider-PortFinder-PortRPC integration', () => {
});
it
(
'enables the communication between guest-host'
,
async
()
=>
{
let
done
;
const
promise
=
new
Promise
(
resolve
=>
(
done
=
resolve
));
// guest frame
const
simulateGuest
=
async
()
=>
{
const
portFinder
=
new
PortFinder
({
hostFrame
:
window
,
source
:
'guest'
,
});
const
hostRPC
=
new
PortRPC
(
);
const
port
=
await
portFinder
.
discover
(
'host'
);
portFinder
.
discover
(
'host'
).
then
(
port
=>
{
const
hostRPC
=
new
PortRPC
();
hostRPC
.
connect
(
port
);
await
new
Promise
(
resolve
=>
hostRPC
.
call
(
'ping'
,
response
=>
{
assert
.
equal
(
response
,
'pong'
);
done
();
});
});
resolve
();
})
);
};
await
delay
(
10
);
// add some realism
const
simulateHost
=
async
()
=>
{
await
delay
(
10
);
// simulate scenario when host frame is ready before the guest frame
// host frame
const
portProvider
=
new
PortProvider
(
window
.
location
.
origin
);
portProvider
.
listen
();
const
guestRPC
=
new
PortRPC
();
// Register RPC method *before* connection
const
guestRPC
=
new
PortRPC
();
guestRPC
.
on
(
'ping'
,
cb
=>
cb
(
'pong'
));
portProvider
.
on
(
'frameConnected'
,
(
source
,
port
)
=>
{
...
...
@@ -82,43 +80,41 @@ describe('PortProvider-PortFinder-PortRPC integration', () => {
guestRPC
.
connect
(
port
);
}
});
};
return
promise
;
return
Promise
.
all
([
simulateGuest
(),
simulateHost
()])
;
});
it
(
'enables the communication between guest-sidebar'
,
async
()
=>
{
let
done
;
const
promise
=
new
Promise
(
resolve
=>
(
done
=
resolve
));
// guest frame;
const
portFinder1
=
new
PortFinder
({
const
simulateGuest
=
async
()
=>
{
const
portFinder
=
new
PortFinder
({
hostFrame
:
window
,
source
:
'guest'
,
});
const
sidebar
RPC
=
new
PortRPC
();
const
host
RPC
=
new
PortRPC
();
portFinder1
.
discover
(
'sidebar'
).
then
(
port
=>
{
sidebarRPC
.
connect
(
port
);
sidebarRPC
.
call
(
'ping'
,
response
=>
{
assert
.
equal
(
response
,
'pong'
);
done
();
});
});
const
port
=
await
portFinder
.
discover
(
'sidebar'
);
hostRPC
.
connect
(
port
);
await
delay
(
10
);
// add some realism
await
new
Promise
(
resolve
=>
hostRPC
.
call
(
'ping'
,
response
=>
{
assert
.
equal
(
response
,
'pong'
);
resolve
();
})
);
};
// sidebar frame
const
portFinder2
=
new
PortFinder
({
const
simulateSidebar
=
async
()
=>
{
const
portFinder
=
new
PortFinder
({
hostFrame
:
window
,
source
:
'sidebar'
,
});
const
guestRPC
=
new
PortRPC
(
);
const
port
=
await
portFinder
.
discover
(
'host'
);
// Register RPC method *before* connection
const
guestRPC
=
new
PortRPC
();
guestRPC
.
on
(
'ping'
,
cb
=>
cb
(
'pong'
));
const
listenerCollection
=
new
ListenerCollection
();
portFinder2
.
discover
(
'host'
).
then
(
port
=>
{
listenerCollection
.
add
(
port
,
'message'
,
({
data
,
ports
})
=>
{
if
(
isMessageEqual
(
data
,
{
...
...
@@ -130,41 +126,44 @@ describe('PortProvider-PortFinder-PortRPC integration', () => {
guestRPC
.
connect
(
ports
[
0
]);
}
});
port
.
start
();
// `start` method would be triggered by `hostRPC.connect(port)`
});
// host frame
port
.
start
();
// `start` is normally invoked by `hostRPC.connect(port)`
};
const
simulateHost
=
async
()
=>
{
await
delay
(
10
);
// simulate scenario when host frame is ready before the guest frame
const
portProvider
=
new
PortProvider
(
window
.
location
.
origin
);
portProvider
.
listen
();
};
return
promise
;
return
Promise
.
all
([
simulateGuest
(),
simulateSidebar
(),
simulateHost
()])
;
});
it
(
'enables the communication between sidebar-host'
,
async
()
=>
{
let
done
;
const
promise
=
new
Promise
(
resolve
=>
(
done
=
resolve
));
// sidebar frame
const
simulateSidebar
=
async
()
=>
{
const
portFinder
=
new
PortFinder
({
hostFrame
:
window
,
source
:
'sidebar'
,
});
const
hostRPC
=
new
PortRPC
(
);
const
port
=
await
portFinder
.
discover
(
'host'
);
portFinder
.
discover
(
'host'
).
then
(
port
=>
{
const
hostRPC
=
new
PortRPC
();
hostRPC
.
connect
(
port
);
await
new
Promise
(
resolve
=>
{
hostRPC
.
call
(
'ping'
,
response
=>
{
assert
.
equal
(
response
,
'pong'
);
don
e
();
resolv
e
();
});
});
};
// host frame
const
simulateHost
=
()
=>
{
const
portProvider
=
new
PortProvider
(
window
.
location
.
origin
);
portProvider
.
listen
();
const
sidebarRPC
=
new
PortRPC
();
// Register RPC method *before* connection
const
sidebarRPC
=
new
PortRPC
();
sidebarRPC
.
on
(
'ping'
,
cb
=>
cb
(
'pong'
));
portProvider
.
on
(
'frameConnected'
,
(
source
,
port
)
=>
{
...
...
@@ -172,7 +171,8 @@ describe('PortProvider-PortFinder-PortRPC integration', () => {
sidebarRPC
.
connect
(
port
);
}
});
};
return
promise
;
return
Promise
.
all
([
simulateSidebar
(),
simulateHost
()])
;
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment