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
7b82c713
Commit
7b82c713
authored
Feb 02, 2015
by
Gerben
Committed by
Aron Carroll
Feb 04, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix indentation
parent
0726b355
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
129 deletions
+129
-129
cross-frame-discovery-test.coffee
tests/js/cross-frame-discovery-test.coffee
+129
-129
No files found.
tests/js/cross-frame-discovery-test.coffee
View file @
7b82c713
...
...
@@ -38,136 +38,136 @@ describe 'CrossFrameDiscovery', ->
assert
.
called
(
fakeTopWindow
.
addEventListener
)
assert
.
calledWith
(
fakeTopWindow
.
addEventListener
,
'message'
,
sinon
.
match
.
func
,
false
)
describe
'when acting as a server (options.server = true)'
,
->
server
=
null
beforeEach
->
server
=
createDiscovery
(
fakeFrameWindow
,
server
:
true
)
it
'sends out a "offer" message to every frame'
,
->
server
.
startDiscovery
(
->
)
assert
.
called
(
fakeTopWindow
.
postMessage
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
'__cross_frame_dhcp_offer'
,
'*'
)
it
'allows the origin to be provided'
,
->
server
=
createDiscovery
(
fakeFrameWindow
,
server
:
true
,
origin
:
'foo'
)
server
.
startDiscovery
(
->
)
assert
.
called
(
fakeTopWindow
.
postMessage
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
'__cross_frame_dhcp_offer'
,
'foo'
)
it
'does not send the message to itself'
,
->
server
.
startDiscovery
(
->
)
assert
.
notCalled
(
fakeFrameWindow
.
postMessage
)
it
'sends an "ack" on receiving a "request"'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_request'
source
:
fakeTopWindow
origin
:
'top'
})
server
.
startDiscovery
(
->
)
assert
.
called
(
fakeTopWindow
.
postMessage
)
matcher
=
sinon
.
match
(
/__cross_frame_dhcp_ack:\d+/
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
matcher
,
'top'
)
it
'calls the discovery callback on receiving "request"'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_request'
source
:
fakeTopWindow
origin
:
'top'
})
handler
=
sandbox
.
stub
()
describe
'when acting as a server (options.server = true)'
,
->
server
=
null
beforeEach
->
server
=
createDiscovery
(
fakeFrameWindow
,
server
:
true
)
it
'sends out a "offer" message to every frame'
,
->
server
.
startDiscovery
(
->
)
assert
.
called
(
fakeTopWindow
.
postMessage
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
'__cross_frame_dhcp_offer'
,
'*'
)
it
'allows the origin to be provided'
,
->
server
=
createDiscovery
(
fakeFrameWindow
,
server
:
true
,
origin
:
'foo'
)
server
.
startDiscovery
(
->
)
assert
.
called
(
fakeTopWindow
.
postMessage
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
'__cross_frame_dhcp_offer'
,
'foo'
)
it
'does not send the message to itself'
,
->
server
.
startDiscovery
(
->
)
assert
.
notCalled
(
fakeFrameWindow
.
postMessage
)
it
'sends an "ack" on receiving a "request"'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_request'
source
:
fakeTopWindow
origin
:
'top'
})
server
.
startDiscovery
(
->
)
assert
.
called
(
fakeTopWindow
.
postMessage
)
matcher
=
sinon
.
match
(
/__cross_frame_dhcp_ack:\d+/
)
assert
.
calledWith
(
fakeTopWindow
.
postMessage
,
matcher
,
'top'
)
it
'calls the discovery callback on receiving "request"'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_request'
source
:
fakeTopWindow
origin
:
'top'
})
handler
=
sandbox
.
stub
()
server
.
startDiscovery
(
handler
)
assert
.
called
(
handler
)
assert
.
calledWith
(
handler
,
fakeTopWindow
,
'top'
,
sinon
.
match
(
/\d+/
))
it
'raises an error if it recieves an event from another server'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeTopWindow
origin
:
'top'
})
handler
=
sandbox
.
stub
()
assert
.
throws
->
server
.
startDiscovery
(
handler
)
assert
.
called
(
handler
)
assert
.
calledWith
(
handler
,
fakeTopWindow
,
'top'
,
sinon
.
match
(
/\d+/
))
it
'raises an error if it recieves an event from another server'
,
->
fakeFrameWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeTopWindow
origin
:
'top'
})
handler
=
sandbox
.
stub
()
assert
.
throws
->
server
.
startDiscovery
(
handler
)
describe
'when acting as a client (options.client = false)'
,
->
client
=
null
beforeEach
->
client
=
createDiscovery
(
fakeTopWindow
)
it
'sends out a discovery message to every frame'
,
->
client
.
startDiscovery
(
->
)
assert
.
called
(
fakeFrameWindow
.
postMessage
)
assert
.
calledWith
(
fakeFrameWindow
.
postMessage
,
'__cross_frame_dhcp_discovery'
,
'*'
)
it
'does not send the message to itself'
,
->
client
.
startDiscovery
(
->
)
assert
.
notCalled
(
fakeTopWindow
.
postMessage
)
it
'sends a "request" in response to an "offer"'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe'
})
client
.
startDiscovery
(
->
)
assert
.
called
(
fakeFrameWindow
.
postMessage
)
assert
.
calledWith
(
fakeFrameWindow
.
postMessage
,
'__cross_frame_dhcp_request'
,
'iframe'
)
it
'does not respond to an "offer" if a "request" is already in progress'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe1'
})
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe2'
})
client
.
startDiscovery
(
->
)
# Twice, once for discovery, once for offer.
assert
.
calledTwice
(
fakeFrameWindow
.
postMessage
)
lastCall
=
fakeFrameWindow
.
postMessage
.
lastCall
assert
(
lastCall
.
notCalledWith
(
sinon
.
match
.
string
,
'iframe2'
))
it
'allows responding to a "request" once a previous "request" has completed'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe1'
})
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_ack:1234'
source
:
fakeFrameWindow
origin
:
'iframe1'
})
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe2'
})
client
.
startDiscovery
(
->
)
assert
.
called
(
fakeFrameWindow
.
postMessage
)
assert
.
calledWith
(
fakeFrameWindow
.
postMessage
,
'__cross_frame_dhcp_request'
,
'iframe2'
)
it
'calls the discovery callback on receiving an "ack"'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_ack:1234'
source
:
fakeFrameWindow
origin
:
'iframe'
})
callback
=
sandbox
.
stub
()
client
.
startDiscovery
(
callback
)
assert
.
called
(
callback
)
assert
.
calledWith
(
callback
,
fakeFrameWindow
,
'iframe'
,
'1234'
)
describe
'when acting as a client (options.client = false)'
,
->
client
=
null
beforeEach
->
client
=
createDiscovery
(
fakeTopWindow
)
it
'sends out a discovery message to every frame'
,
->
client
.
startDiscovery
(
->
)
assert
.
called
(
fakeFrameWindow
.
postMessage
)
assert
.
calledWith
(
fakeFrameWindow
.
postMessage
,
'__cross_frame_dhcp_discovery'
,
'*'
)
it
'does not send the message to itself'
,
->
client
.
startDiscovery
(
->
)
assert
.
notCalled
(
fakeTopWindow
.
postMessage
)
it
'sends a "request" in response to an "offer"'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe'
})
client
.
startDiscovery
(
->
)
assert
.
called
(
fakeFrameWindow
.
postMessage
)
assert
.
calledWith
(
fakeFrameWindow
.
postMessage
,
'__cross_frame_dhcp_request'
,
'iframe'
)
it
'does not respond to an "offer" if a "request" is already in progress'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe1'
})
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe2'
})
client
.
startDiscovery
(
->
)
# Twice, once for discovery, once for offer.
assert
.
calledTwice
(
fakeFrameWindow
.
postMessage
)
lastCall
=
fakeFrameWindow
.
postMessage
.
lastCall
assert
(
lastCall
.
notCalledWith
(
sinon
.
match
.
string
,
'iframe2'
))
it
'allows responding to a "request" once a previous "request" has completed'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe1'
})
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_ack:1234'
source
:
fakeFrameWindow
origin
:
'iframe1'
})
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_offer'
source
:
fakeFrameWindow
origin
:
'iframe2'
})
client
.
startDiscovery
(
->
)
assert
.
called
(
fakeFrameWindow
.
postMessage
)
assert
.
calledWith
(
fakeFrameWindow
.
postMessage
,
'__cross_frame_dhcp_request'
,
'iframe2'
)
it
'calls the discovery callback on receiving an "ack"'
,
->
fakeTopWindow
.
addEventListener
.
yields
({
data
:
'__cross_frame_dhcp_ack:1234'
source
:
fakeFrameWindow
origin
:
'iframe'
})
callback
=
sandbox
.
stub
()
client
.
startDiscovery
(
callback
)
assert
.
called
(
callback
)
assert
.
calledWith
(
callback
,
fakeFrameWindow
,
'iframe'
,
'1234'
)
describe
'stopDiscovery'
,
->
it
'removes the "message" listener from the window'
,
->
...
...
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