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
3f7a87e3
Commit
3f7a87e3
authored
Jun 11, 2017
by
Juan Corona
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add integration test that tests the handling of multiple iframe detection
parent
758fc27f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
172 additions
and
0 deletions
+172
-0
multi-frame-test.js
src/annotator/test/integration/multi-frame-test.js
+172
-0
No files found.
src/annotator/test/integration/multi-frame-test.js
0 → 100644
View file @
3f7a87e3
'use strict'
;
var
proxyquire
=
require
(
'proxyquire'
);
var
isLoaded
=
require
(
'../../util/frame-util.js'
).
isLoaded
;
describe
(
'CrossFrame multi-frame scenario'
,
function
()
{
var
fakeAnnotationSync
;
var
fakeBridge
;
var
proxyAnnotationSync
;
var
proxyBridge
;
var
container
;
var
crossFrame
;
var
options
;
var
sandbox
=
sinon
.
sandbox
.
create
();
beforeEach
(
function
()
{
fakeBridge
=
{
createChannel
:
sandbox
.
stub
(),
call
:
sandbox
.
stub
(),
destroy
:
sandbox
.
stub
(),
};
fakeAnnotationSync
=
{};
proxyAnnotationSync
=
sandbox
.
stub
().
returns
(
fakeAnnotationSync
);
proxyBridge
=
sandbox
.
stub
().
returns
(
fakeBridge
);
var
CrossFrame
=
proxyquire
(
'../../plugin/cross-frame'
,
{
'../annotation-sync'
:
proxyAnnotationSync
,
'../../shared/bridge'
:
proxyBridge
,
});
container
=
document
.
createElement
(
'div'
);
document
.
body
.
appendChild
(
container
);
options
=
{
enableMultiFrameSupport
:
true
,
embedScriptUrl
:
'data:,'
,
// empty data uri
on
:
sandbox
.
stub
(),
emit
:
sandbox
.
stub
(),
};
crossFrame
=
new
CrossFrame
(
container
,
options
);
});
afterEach
(
function
()
{
sandbox
.
restore
();
crossFrame
.
destroy
();
container
.
parentNode
.
removeChild
(
container
);
});
it
(
'detects frames on page'
,
function
()
{
// Create a frame before initializing
var
validFrame
=
document
.
createElement
(
'iframe'
);
container
.
appendChild
(
validFrame
);
// Create another that mimics the sidebar frame
// This one should should not be detected
var
invalidFrame
=
document
.
createElement
(
'iframe'
);
invalidFrame
.
className
=
'h-sidebar-iframe'
;
container
.
appendChild
(
invalidFrame
);
// Now initialize
crossFrame
.
pluginInit
();
var
validFramePromise
=
new
Promise
(
function
(
resolve
)
{
isLoaded
(
validFrame
,
function
()
{
assert
(
validFrame
.
contentDocument
.
body
.
hasChildNodes
(),
'expected valid frame to be modified'
);
resolve
();
});
});
var
invalidFramePromise
=
new
Promise
(
function
(
resolve
)
{
isLoaded
(
invalidFrame
,
function
()
{
assert
(
!
invalidFrame
.
contentDocument
.
body
.
hasChildNodes
(),
'expected invalid frame to not be modified'
);
resolve
();
});
});
return
Promise
.
all
([
validFramePromise
,
invalidFramePromise
]);
});
it
(
'detects removed frames'
,
function
()
{
// Create a frame before initializing
var
frame
=
document
.
createElement
(
'iframe'
);
container
.
appendChild
(
frame
);
// Now initialize
crossFrame
.
pluginInit
();
// Remove the frame
frame
.
remove
();
assert
.
calledWith
(
fakeBridge
.
call
,
'destroyFrame'
);
});
it
(
'injects embed script in frame'
,
function
()
{
var
frame
=
document
.
createElement
(
'iframe'
);
container
.
appendChild
(
frame
);
crossFrame
.
pluginInit
();
return
new
Promise
(
function
(
resolve
)
{
isLoaded
(
frame
,
function
()
{
var
scriptElement
=
frame
.
contentDocument
.
querySelector
(
'script[src]'
);
assert
(
scriptElement
,
'expected embed script to be injected'
);
assert
.
equal
(
scriptElement
.
src
,
options
.
embedScriptUrl
,
'unexpected embed script source'
);
resolve
();
});
});
});
it
(
'excludes injection from already injected frames'
,
function
()
{
var
frame
=
document
.
createElement
(
'iframe'
);
frame
.
srcdoc
=
'<script>window.__hypothesis_frame = true;</script>'
;
container
.
appendChild
(
frame
);
crossFrame
.
pluginInit
();
return
new
Promise
(
function
(
resolve
)
{
isLoaded
(
frame
,
function
()
{
var
scriptElement
=
frame
.
contentDocument
.
querySelector
(
'script[src]'
);
assert
(
!
scriptElement
,
'expected embed script to not be injected'
);
resolve
();
});
});
});
it
(
'detects dynamically added frames'
,
function
()
{
// Initialize with no initial frame, unlike before
crossFrame
.
pluginInit
();
// Add a frame to the DOM
var
frame
=
document
.
createElement
(
'iframe'
);
container
.
appendChild
(
frame
);
return
new
Promise
(
function
(
resolve
)
{
// Yield to let the DOM and CrossFrame catch up
setTimeout
(
function
()
{
isLoaded
(
frame
,
function
()
{
assert
(
frame
.
contentDocument
.
body
.
hasChildNodes
(),
'expected dynamically added frame to be modified'
);
resolve
();
});
},
0
);
});
});
it
(
'detects dynamically removed frames'
,
function
()
{
// Create a frame before initializing
var
frame
=
document
.
createElement
(
'iframe'
);
container
.
appendChild
(
frame
);
// Now initialize
crossFrame
.
pluginInit
();
return
new
Promise
(
function
(
resolve
)
{
// Yield to let the DOM and CrossFrame catch up
setTimeout
(
function
()
{
frame
.
remove
();
// Yield again
setTimeout
(
function
()
{
assert
.
calledWith
(
fakeBridge
.
call
,
'destroyFrame'
);
resolve
();
},
0
);
},
0
);
});
});
});
\ No newline at end of file
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