first commit

This commit is contained in:
aschwarz
2023-04-25 13:25:59 +02:00
commit 086d1e1e9e
1774 changed files with 396049 additions and 0 deletions

View File

@ -0,0 +1,61 @@
define(['iframeResizer'], function(iFrameResize) {
describe('iFrame init', function() {
var iframe
var id = 'initTest'
beforeEach(function(done) {
loadIFrame('iframe600.html')
iframe = iFrameResize({
log: LOG,
id: id + '-',
autoResize: false,
bodyMargin: 1,
checkOrigin: false,
inPageLinks: true,
interval: 0,
maxHeight: 100,
minHeight: 10,
maxWidth: 100,
minWidth: 10,
scrolling: true,
sizeHeight: false,
sizeWidth: true,
tolerance: 1,
onInit: function() {
setTimeout(done, 1)
}
})[0]
})
afterEach(function() {
//tearDown(iframe);
})
it('should add an ID', function() {
expect(iframe.id.split('-')[0]).toBe(id)
})
describe('methods', function() {
it('should create iFrameResizer object', function() {
expect(iframe.iFrameResizer).toBeDefined()
})
it('should create a close method', function() {
expect(iframe.iFrameResizer.close).toBeDefined()
})
it('should create a resize method', function() {
expect(iframe.iFrameResizer.resize).toBeDefined()
})
it('should create a moveToAnchor method', function() {
expect(iframe.iFrameResizer.moveToAnchor).toBeDefined()
})
it('should create a sendMessage method', function() {
expect(iframe.iFrameResizer.sendMessage).toBeDefined()
})
})
})
})

View File

@ -0,0 +1,62 @@
define(['iframeResizer'], function(iFrameResize) {
describe('jump to anchor', function() {
var iframe
var log = LOG
var testId = 'anchor'
beforeEach(function() {
loadIFrame('iframe600.html')
})
afterEach(function() {
tearDown(iframe)
})
it('requested from host page', function(done) {
var iframe1 = iFrameResize({
log: log,
id: 'anchor1'
})[0]
spyOnIFramePostMessage(iframe1)
setTimeout(function() {
iframe1.iFrameResizer.moveToAnchor('testAnchor')
expect(iframe1.contentWindow.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]moveToAnchor:testAnchor',
getTarget(iframe1)
)
tearDown(iframe1)
done()
}, 100)
})
it('mock incoming message', function(done) {
iframe2 = iFrameResize({
log: log,
id: 'anchor2',
onScroll: function(position) {
expect(position.x).toBe(8)
expect(position.y).toBeGreaterThan(8)
done()
}
})[0]
mockMsgFromIFrame(iframe2, 'inPageLink:#anchorParentTest')
})
it('mock incoming message to parent', function(done) {
iframe3 = iFrameResize({
log: log,
id: 'anchor3'
})[0]
window.parentIFrame = {
moveToAnchor: function() {
done()
}
}
mockMsgFromIFrame(iframe3, 'inPageLink:#anchorParentTest2')
})
})
})

View File

@ -0,0 +1,510 @@
define(['iframeResizerContent', 'jquery'], function(mockMsgListener, $) {
function createMsg(msg) {
return {
data: '[iFrameSizer]' + msg,
source: {
postMessage: function(msg) {
if (log) {
console.log('PostMessage: ' + msg)
}
}
}
}
}
window.iFrameResizer = {
onMessage: function(msg) {
msgCalled = msg
},
onReady: function() {
this.readyCalled = true
},
targetOrigin: '*'
}
$(window.document.body).append('<a href="#foo" id="bar"></a>')
//test early message is ignored
mockMsgListener(createMsg('resize'))
var id = 'parentIFrameTests',
log = true,
childMsg =
'8:true:' +
log +
':9999:true:false:-8px:max:wheat:null:0:true:child:scroll'
;(msgObject = createMsg(id + ':' + childMsg)),
(win = mockMsgListener(msgObject))
//test reset is ignored during init
mockMsgListener(createMsg('reset'))
window.msgCalled = null
//window.readyCalled = null;
beforeEach(function() {
spyOn(msgObject.source, 'postMessage')
spyOn(window.iFrameResizer, 'onMessage')
spyOn(window.iFrameResizer, 'onReady')
spyOn(console, 'log')
spyOn(console, 'warn')
})
afterAll(function() {
win.parentIFrame.close()
})
describe('ParentIFrame methods: ', function() {
it('autoResize', function() {
win.parentIFrame.autoResize(true)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Animation Start'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Animation Iteration'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Animation End'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Orientation Change'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Input'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Print'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Transition End'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Mouse Up'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: Mouse Down'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Add event listener: IFrame Resized'
)
win.parentIFrame.autoResize(false)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Animation Start'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Animation Iteration'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Animation End'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Orientation Change'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Input'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Print'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Transition End'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Mouse Up'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: Mouse Down'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Remove event listener: IFrame Resized'
)
})
it('Get ID of iFrame is same as iFrame', function() {
expect(win.parentIFrame.getId()).toBe(id)
})
it('move to anchor', function() {
win.parentIFrame.moveToAnchor('foo')
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:0:0:inPageLink:#foo',
'*'
)
win.parentIFrame.moveToAnchor('bar')
expect(msgObject.source.postMessage.calls.argsFor(1)[0]).toContain(
':scrollToOffset'
)
})
it('reset', function() {
win.parentIFrame.reset()
expect(msgObject.source.postMessage.calls.argsFor(0)[0]).toContain(
':reset'
)
})
it('getPageInfo', function(done) {
win.parentIFrame.getPageInfo(function(pageInfo) {
expect(pageInfo.iframeHeight).toBe(500)
expect(pageInfo.iframeWidth).toBe(300)
expect(pageInfo.offsetLeft).toBe(20)
expect(pageInfo.offsetTop).toBe(85)
expect(pageInfo.scrollTop).toBe(0)
expect(pageInfo.scrollLeft).toBe(0)
expect(pageInfo.documentHeight).toBe(645)
expect(pageInfo.documentWidth).toBe(1295)
expect(pageInfo.windowHeight).toBe(645)
expect(pageInfo.windowWidth).toBe(1295)
expect(pageInfo.clientHeight).toBe(645)
expect(pageInfo.clientWidth).toBe(1295)
done()
})
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:0:0:pageInfo',
'*'
)
mockMsgListener(
createMsg(
'pageInfo:{"iframeHeight":500,"iframeWidth":300,"clientHeight":645,' +
'"clientWidth":1295,"offsetLeft":20,"offsetTop":85,"scrollLeft":0,' +
'"scrollTop":0,"documentHeight":645,"documentWidth":1295,' +
'"windowHeight":645,"windowWidth":1295}'
)
)
})
it('getPageInfoStop', function() {
win.parentIFrame.getPageInfo()
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:0:0:pageInfoStop',
'*'
)
})
it('scrollTo', function() {
win.parentIFrame.scrollTo(10, 10)
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:10:10:scrollTo',
'*'
)
})
it('scrollToOffset', function() {
win.parentIFrame.scrollToOffset(10, 10)
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:10:10:scrollToOffset',
'*'
)
})
it('sendMessage (string)', function() {
win.parentIFrame.sendMessage('foo:bar')
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:0:0:message:"foo:bar"',
'*'
)
})
it('sendMessage (object)', function() {
win.parentIFrame.sendMessage({ foo: 'bar' }, 'https://foo.bar:1337')
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:0:0:message:{"foo":"bar"}',
'https://foo.bar:1337'
)
})
xit('setTargetOrigin', function() {
var targetOrigin = 'https://foo.bar:1337'
win.parentIFrame.setTargetOrigin(targetOrigin)
win.parentIFrame.size(10, 10)
win.parentIFrame.setTargetOrigin('*')
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:10:10:size',
targetOrigin
)
})
})
describe('inbound message: ', function() {
it('readyCallack', function() {
expect(window.readyCalled).toEqual(true)
})
it('message (String)', function() {
var msg = 'foo'
mockMsgListener(createMsg('message:' + JSON.stringify(msg)))
expect(msgCalled).toBe(msg)
})
it('message (Object)', function() {
var msg = { foo: 'bar' }
mockMsgListener(createMsg('message:' + JSON.stringify(msg)))
expect(msgCalled.foo).toBe('bar')
})
xit('reset', function(done) {
// timing issue in Chrome
setTimeout(function() {
//Wait for init lock to clear
mockMsgListener(createMsg('reset'))
console.log('>> ', msgObject.source.postMessage.calls.argsFor(0))
expect(msgObject.source.postMessage.calls.argsFor(0)[0]).toContain(
':reset'
)
done()
}, 200)
})
it('resize(max)', function() {
win.parentIFrame.setHeightCalculationMethod('max')
mockMsgListener(createMsg('resize'))
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Trigger event: Parent window requested size check'
)
})
it('resize(lowestElement)', function() {
win.parentIFrame.setHeightCalculationMethod('lowestElement')
mockMsgListener(createMsg('resize'))
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Trigger event: Parent window requested size check'
)
})
it('resize(rightMostElement)', function() {
win.parentIFrame.setWidthCalculationMethod('rightMostElement')
mockMsgListener(createMsg('resize'))
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Trigger event: Parent window requested size check'
)
})
it('move to anchor', function() {
mockMsgListener(createMsg('moveToAnchor:foo'))
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:0:0:inPageLink:#foo',
'*'
)
})
xit('unexpected message', function() {
mockMsgListener(createMsg('foo'))
expect(console.warn).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] Unexpected message ([iFrameSizer]foo)'
)
})
})
describe('performance: ', function() {
it('trottles', function(done) {
win.parentIFrame.size(10, 10)
win.parentIFrame.size(20, 10)
win.parentIFrame.size(30, 10)
win.parentIFrame.size(40, 10)
win.parentIFrame.size(50, 10)
win.parentIFrame.size(60, 10)
setTimeout(function() {
// expect(msgObject.source.postMessage).toHaveBeenCalledWith('[iFrameSizer]parentIFrameTests:10:10:size', '*');
expect(msgObject.source.postMessage).not.toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:20:10:size',
'*'
)
expect(msgObject.source.postMessage).not.toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:30:10:size',
'*'
)
expect(msgObject.source.postMessage).not.toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:40:10:size',
'*'
)
expect(msgObject.source.postMessage).not.toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:50:10:size',
'*'
)
expect(msgObject.source.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentIFrameTests:60:10:size',
'*'
)
done()
}, 17)
})
})
describe('height calculation methods: ', function() {
it('invalid', function() {
win.parentIFrame.setHeightCalculationMethod('foo')
expect(console.warn).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] foo is not a valid option for heightCalculationMethod.'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] height calculation method set to "bodyOffset"'
)
win.parentIFrame.size()
})
it('bodyOffset', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('bodyOffset')
win.parentIFrame.size()
done()
}, 10)
})
it('offset', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('offset')
win.parentIFrame.size()
done()
}, 20)
})
it('bodyScroll', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('bodyScroll')
win.parentIFrame.size()
done()
}, 30)
})
it('documentElementOffset', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('documentElementOffset')
win.parentIFrame.size()
done()
}, 40)
})
it('documentElementScroll', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('documentElementScroll')
win.parentIFrame.size()
done()
}, 50)
})
it('max', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('max')
win.parentIFrame.size()
done()
}, 60)
})
it('min', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('min')
win.parentIFrame.size()
done()
}, 70)
})
it('grow', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('grow')
win.parentIFrame.size()
done()
}, 80)
})
it('lowestElement', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('lowestElement')
win.parentIFrame.size()
done()
}, 90)
})
it('taggedElement', function(done) {
setTimeout(function() {
win.parentIFrame.setHeightCalculationMethod('taggedElement')
win.parentIFrame.size()
done()
}, 100)
})
})
describe('width calculation methods: ', function() {
it('invalid', function() {
win.parentIFrame.setWidthCalculationMethod('foo')
expect(console.warn).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] foo is not a valid option for widthCalculationMethod.'
)
expect(console.log).toHaveBeenCalledWith(
'[iFrameSizer][parentIFrameTests] width calculation method set to "scroll"'
)
win.parentIFrame.size()
})
it('bodyOffset', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('bodyOffset')
win.parentIFrame.size()
done()
}, 110)
})
it('bodyScroll', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('bodyScroll')
win.parentIFrame.size()
done()
}, 120)
})
it('documentElementOffset', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('documentElementOffset')
win.parentIFrame.size()
done()
}, 130)
})
it('documentElementScroll:', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('documentElementScroll:')
win.parentIFrame.size()
done()
}, 140)
})
it('scroll', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('scroll')
win.parentIFrame.size()
done()
}, 150)
})
it('max', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('max')
win.parentIFrame.size()
done()
}, 160)
})
it('min', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('min')
win.parentIFrame.size()
done()
}, 170)
})
it('leftMostElement', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('leftMostElement')
win.parentIFrame.size()
done()
}, 180)
})
it('taggedElement', function(done) {
setTimeout(function() {
win.parentIFrame.setWidthCalculationMethod('taggedElement')
win.parentIFrame.size()
done()
}, 190)
})
})
})

View File

@ -0,0 +1,40 @@
define(['iframeResizer'], function(iFrameResize) {
describe('Close iFrame', function() {
var iframe
beforeEach(function() {
loadIFrame('iframe600.html')
})
it('closes from parent', function(done) {
var evtCounter = 0
iframe = iFrameResize({
log: LOG,
id: 'close1',
onClosed: function() {
setTimeout(done, 0)
}
})[0]
setTimeout(iframe.iFrameResizer.close, 1)
})
it('closes from iframe', function(done) {
var evtCounter = 0
iframe = iFrameResize({
log: LOG,
id: 'close2',
onClosed: function() {
setTimeout(done, 0)
},
onInit: function(iframe) {
iframe.iFrameResizer.sendMessage('close')
}
})[0]
mockMsgFromIFrame(iframe, 'close')
})
})
})

View File

@ -0,0 +1,86 @@
define(['iframeResizer'], function(iFrameResize) {
describe('Get Page info', function() {
var log = LOG
var testId = 'anchor'
beforeEach(function() {
loadIFrame('iframe600.html')
})
it('requested from iFrame', function(done) {
var iframe1 = iFrameResize({
log: log,
id: 'getPageInfo'
})[0]
spyOn(iframe1.contentWindow, 'postMessage').and.callFake(function(msg) {
if (0 !== msg.indexOf('pageInfo')) {
expect(
msg.indexOf(
'"offsetTop":0,"offsetLeft":0,"scrollTop":0,"scrollLeft":0'
)
).not.toEqual(0)
}
if (0 !== msg.indexOf('pageInfoStop')) {
tearDown(iframe1)
done()
}
})
mockMsgFromIFrame(iframe1, 'pageInfo')
mockMsgFromIFrame(iframe1, 'pageInfoStop')
})
})
describe('Get Page info with multiple frames', function() {
var log = LOG
beforeEach(function() {
loadIFrame('twoIFrame600WithId.html')
})
xit('must send pageInfo to second frame', function(done) {
var iframes = iFrameResize({
log: log,
id: '#frame1,#frame2',
onInit: function(iframe) {
iframe.iFrameResizer.sendMessage('getPageInfo')
}
})
var iframe1 = iframes[0],
iframe2 = iframes[1]
setTimeout(function() {
var counter = 0,
frame1Called = false,
frame2Called = false
function checkCounter() {
if (counter === 2) {
expect(frame1Called && frame2Called).toBeTruthy()
tearDown(iframe1)
tearDown(iframe2)
done()
}
}
iframe1.contentWindow.postMessage = function(msg) {
if (0 < msg.indexOf('pageInfo')) {
frame1Called = true
counter++
checkCounter()
}
}
iframe2.contentWindow.postMessage = function(msg) {
if (0 < msg.indexOf('pageInfo')) {
frame2Called = true
counter++
checkCounter()
}
}
window.dispatchEvent(new Event('resize'))
}, 200)
})
})
})

View File

@ -0,0 +1,38 @@
/* jshint undef: false, unused: true */
'use strict'
define(['iframeResizer'], function(iFrameResize) {
describe('iFrame init(CSS Selector)', function() {
var iframe
beforeAll(function(done) {
loadIFrame('iframe600.html')
iframe = iFrameResize(
{
log: LOG,
minHeight: 99999,
onResized: done,
checkOrigin: [
'https://localhost',
'https://localhost',
location.href
.split('/')
.slice(0, 3)
.join('/')
]
},
'iframe'
)[0]
})
afterAll(function() {
tearDown(iframe)
})
it('should create iFrameResizer object', function() {
expect(iframe.iFrameResizer).toBeDefined()
})
})
})

View File

@ -0,0 +1,28 @@
/* jshint undef: false, unused: true */
'use strict'
define(['iframeResizer'], function(iFrameResize) {
describe('iFrame init(DOM Object)', function() {
var iframe
beforeAll(function() {
loadIFrame('iframe600.html')
iframe = iFrameResize(
{
log: LOG
},
document.getElementsByTagName('iframe')[0]
)[0]
})
afterAll(function() {
tearDown(iframe)
})
it('should create iFrameResizer object', function() {
expect(iframe.iFrameResizer).toBeDefined()
})
})
})

View File

@ -0,0 +1,31 @@
/* jshint undef: false, unused: true */
'use strict'
define(['iframeResizer'], function(iFrameResize) {
describe('iFrame init(Double)', function() {
var iframe
beforeAll(function() {
loadIFrame('iframe600WithId.html')
//spyOn(console,'warn');
})
afterAll(function() {
tearDown(iframe)
})
it('should create iFrameResizer object', function() {
window.parentIFrame = {
getId: function() {
return 'getIdTest'
}
}
iframe = iFrameResize({ log: LOG }, '#doubleTest')[0]
iFrameResize({ log: LOG }, '#doubleTest')
expect(iframe.iFrameResizer).toBeDefined()
expect(console.warn).toHaveBeenCalled()
delete window.parentIFrame
})
})
})

View File

@ -0,0 +1,65 @@
define(['iframeResizer'], function(iFrameResize) {
describe('Setup error', function() {
var iframe
var log = LOG
beforeEach(function() {
loadIFrame('iframe600.html')
})
it('min > max', function() {
expect(function() {
iFrameResize({
log: log,
id: 'error1',
maxHeight: 100,
minHeight: 999
})
}).toThrow(
new Error('Value for minHeight can not be greater than maxHeight')
)
})
it('Unexpected data type', function() {
expect(function() {
iFrameResize(
{
log: log,
id: 'error2'
},
1
)
}).toThrow(new TypeError('Unexpected data type (number)'))
})
it('Expected <IFRAME> tag', function() {
expect(function() {
iFrameResize(
{
log: log,
id: 'error3'
},
'div'
)
}).toThrow(new TypeError('Expected <IFRAME> tag, found <DIV>'))
})
it('Object is not a valid DOM element', function() {
expect(function() {
iFrameResize(
{
log: log,
id: 'error4'
},
{}
)
}).toThrow(new TypeError('Object is not a valid DOM element'))
})
it('Options is not an object', function() {
expect(function() {
iFrameResize('ERROR')
}).toThrow(new TypeError('Options is not an object'))
})
})
})

View File

@ -0,0 +1,25 @@
/* jshint undef: false, unused: true */
'use strict'
define(['iframeResizer', 'jquery'], function(iFrameResize, $) {
describe('iFrame init(jQuery)', function() {
var iframe
beforeAll(function() {
loadIFrame('iframe600.html')
var $iframes = $('iframe').iFrameResize()
iframe = $iframes.get(0)
})
afterAll(function() {
tearDown(iframe)
})
it('should create iFrameResizer object', function() {
expect(iframe.iFrameResizer).toBeDefined()
})
})
})

View File

@ -0,0 +1,26 @@
/* jshint undef: false, unused: true */
'use strict'
define(['iframeResizer'], function(iFrameResize) {
describe('iFrame init(DOM Object)', function() {
var iframe
beforeAll(function() {
loadIFrame('iframe600.html')
iframe = iFrameResize(
undefined,
document.getElementsByTagName('iframe')[0]
)[0]
})
afterAll(function() {
tearDown(iframe)
})
it('should create iFrameResizer object', function() {
expect(iframe.iFrameResizer).toBeDefined()
})
})
})

View File

@ -0,0 +1,3 @@
<iframe src="/base/spec/resources/blank.html" width="100%" scrolling="no"></iframe>

View File

@ -0,0 +1,6 @@
<div id="iframe-fixture" style="width:600px;">
<iframe src="/base/spec/resources/frame.content.html" width="100%" scrolling="no"></iframe>
</div>
<a name="anchorParentTest"></a>

View File

@ -0,0 +1,7 @@
<div id="iframe-fixture" style="width:600px;">
<iframe id="doubleTest" src="/base/spec/resources/frame.content.html" width="100%" scrolling="no"></iframe>
</div>
<a name="anchorParentTest"></a>

View File

@ -0,0 +1,8 @@
<div id="iframe-fixture" style="width:600px;">
<iframe id="frame1" src="/base/spec/resources/frame.content.html" width="100%" scrolling="no"></iframe>
</div>
<div id="iframe-fixture" style="width:600px;">
<iframe id="frame2" src="/base/spec/resources/frame.content.html" width="100%" scrolling="no"></iframe>
</div>

View File

@ -0,0 +1,67 @@
'use strict';
var LOG = true;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 4000;
jasmine.getFixtures().fixturesPath = 'base/spec/javascripts/fixtures';
function tearDown(iframe) {
if (iframe) setTimeout(iframe.iFrameResizer.close, 1);
window.parentIFrame = undefined;
}
function loadIFrame(filename) {
loadFixtures(filename);
}
function getTarget(iframe) {
return iframe.src
.split('/')
.slice(0, 3)
.join('/');
}
function mockPostMsgViaHook(testIFrame, id, msg, callback) {
return testIFrame('[iFrameSizer]' + id + ':' + msg, callback);
}
function mockPostMsg(id, msg) {
var message = '[iFrameSizer]' + id + ':' + msg;
console.log('Mork postMessage: ', message);
window.postMessage(message, '*');
}
function mockMsgFromIFrame(iframe, msg) {
mockPostMsg(iframe.id, '0:0:' + msg);
}
function mockInitFromParent(testIFrame, id, log, callback) {
return mockPostMsgViaHook(
testIFrame,
id,
'8:false:' + log + ':0:true:false:null:max:wheat:null:0:true:child:scroll',
callback
);
}
function spyOnPostMessage(target) {
spyOn(target, 'postMessage');
}
function spyOnWindowPostMessage() {
spyOnPostMessage(window.parent);
return window.parent.postMessage;
}
function spyOnIFramePostMessage(iframe) {
spyOnPostMessage(iframe.contentWindow);
}
function closeChild(window, done) {
window.parentIFrame.close();
done();
}
function strEnd(str, num) {
return str.substr(str.length - num);
}

View File

@ -0,0 +1,88 @@
define(['iframeResizer'], function(iFrameResize) {
describe('Parent Page', function() {
describe('default resize', function() {
var iframe
var log = LOG
var testId = 'defaultResize3'
var ready
beforeEach(function(done) {
loadIFrame('iframe600.html')
iframe = iFrameResize({
log: log,
id: testId,
onResized: function() {
ready = true
done()
}
})[0]
mockMsgFromIFrame(iframe, 'foo')
})
afterEach(function() {
tearDown(iframe)
})
it('receive message', function() {
expect(ready).toBe(true)
})
})
describe('reset Page', function() {
var iframe
var log = LOG
var testId = 'parentPage1'
beforeEach(function(done) {
loadIFrame('iframe600.html')
iframe = iFrameResize({
log: log,
id: testId
})[0]
spyOn(iframe.contentWindow, 'postMessage').and.callFake(done)
mockMsgFromIFrame(iframe, 'reset')
})
afterEach(function() {
tearDown(iframe)
})
it('receive message', function() {
expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]reset',
'https://localhost:9876'
)
})
})
describe('late load msg received', function() {
var iframe
var log = LOG
var testId = 'parentPage2'
beforeEach(function(done) {
loadIFrame('iframe600.html')
iframe = iFrameResize({
log: log,
id: testId
})[0]
spyOn(iframe.contentWindow, 'postMessage').and.callFake(done)
window.postMessage('[iFrameResizerChild]Ready', '*')
})
afterEach(function() {
tearDown(iframe)
})
it('receive message', function() {
expect(iframe.contentWindow.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]parentPage2:8:false:true:32:true:true:null:bodyOffset:null:null:0:false:parent:scroll',
'https://localhost:9876'
)
})
})
})
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

View File

@ -0,0 +1,259 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>iFrame message passing test</title>
<meta name="description" content="iFrame message passing test">
<style>
a { float:right; }
</style>
</head>
<body>
<b>iFrame</b>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p name="testAnchor">
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will
give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the
master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but
because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.
Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because
occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial
example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who
has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who
avoids a pain that produces no resultant pleasure?
</p>
<p>
On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the
charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound
to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as
saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free
hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best,
every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty
or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted.
The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure
other greater pleasures, or else he endures pains to avoid worse pains.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will
give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the
master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but
because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.
Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because
occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial
example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who
has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who
avoids a pain that produces no resultant pleasure?
</p>
<p>
On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the
charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound
to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as
saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free
hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best,
every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty
or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted.
The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure
other greater pleasures, or else he endures pains to avoid worse pains.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will
give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the
master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but
because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.
Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because
occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial
example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who
has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who
avoids a pain that produces no resultant pleasure?
</p>
<p>
On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the
charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound
to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as
saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free
hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best,
every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty
or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted.
The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure
other greater pleasures, or else he endures pains to avoid worse pains.
</p>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will
give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the
master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but
because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful.
Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because
occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial
example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who
has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who
avoids a pain that produces no resultant pleasure?
</p>
<p>
On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the
charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound
to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as
saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free
hour, when our power of choice is untrammelled and when nothing prevents our being able to do what we like best,
every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty
or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted.
The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure
other greater pleasures, or else he endures pains to avoid worse pains.
</p>
<script type="text/javascript">
(function () {
var logging = true;
try {
function addEventListener(e, func) {
if (window.addEventListener) {
window.addEventListener(e, func, false);
} else if (window.attachEvent) {
window.attachEvent('on' + e, func);
}
}
function log(msg) {
if (logging && window.console) {
console.info('[Test] ' + msg);
}
}
function warn(msg) {
if (window.console) {
console.warn('[Test] ' + msg);
}
}
function init(test) {
function changeContent() {
$('p').eq(0).remove();
}
function callMethod(methodName, val1, val2) {
if ('parentIFrame' in window)
window.parentIFrame[methodName](val1, val2);
else
warn('window.parentIFrame methods not enabled.')
}
console.info(test);
switch (test) {
case 'changeContent':
setInterval(function () { changeContent(); }, 2);
break;
case 'close':
callMethod('close');
break;
case 'pageChange':
location.href = '/base/example/frame.hover.html';
break;
case 'nested':
location.href = 'frame.nested.html';
break;
case 'size':
changeContent();
callMethod('size');
break;
case 'autoResize':
callMethod('setAutoResize', true);
setTimeout(function () {
changeContent();
}, 500);
break;
case 'size100':
callMethod('size', 100);
break;
case 'size200300':
callMethod('size', 200, 300);
break;
case 'jsTrigger':
changeContent();
callMethod('trigger');
break;
case 'chkHeight':
callMethod('sendMessage', document.body.offsetHeight);
break;
case 'chkBackground':
callMethod('sendMessage', document.body.style.backgroundColor);
break;
case 'chkSendMsg':
callMethod('sendMessage', 'message: test string');
break;
case 'chkSendObj':
callMethod('sendMessage', { message: 'test object' });
break;
case 'chkGetId':
if ('parentIFrame' in window)
callMethod('sendMessage', window.parentIFrame.getId());
break;
case 'setHeightCalculationMethod':
if ('parentIFrame' in window) {
parentIFrame.setHeightCalculationMethod('max');
callMethod('size');
}
break;
case 'width':
$('p').width(3000);
break;
case 'image':
$('p').html('<img src="djb.jpg">');
break;
case 'getPageInfo':
callMethod('getPageInfo', function (pageInfo) {
});
}
}
window.iFrameResizer = {
onMessage: init
}
}
catch (e) {
warn(e);
}
})();
</script>
<script type="text/javascript" src="/base/js/iframeResizer.contentWindow.min.js"></script>
</body>
</html>

View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>iFrame message passing test</title>
<meta name="description" content="iFrame message passing test">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
*,
*:before,
*:after {
box-model: border-box;
}
a {
float: right;
margin-left: 10px;
}
h2 {
margin-top: 0;
}
</style>
</head>
<body>
<h2>Late load JS test</h2>
<p>Load JS with require after load event has fired.</p>
<div style="margin:20px;">
</div>
<script src="jquery.js"></script>
<script>
$(document).ready(function () {
setTimeout(function () {
console.log('Load Script');
$.getScript('../../js/iframeResizer.contentWindow.min.js');
}, 500);
});
</script>
</body>
</html>

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>iFrame message passing test</title>
<meta name="description" content="iFrame message passing test">
<meta name="viewport" content="width=device-width">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<style>
*, *:before, *:after {box-model: border-box;}
a { float:right; margin-left:10px;}
h2 {margin-top: 0;}
</style>
</head>
<body>
<h2>Nested iFrame</h2>
<p>Resize window or click one of the links in the nested iFrame to watch it resize.</p>
<div style="margin:20px;">
<iframe id="nestedIFrame" src="frame.content.html" width="100%" scrolling="no"></iframe>
</div>
<p id="callback">
</p>
<script type="text/javascript" src="../../js/iframeResizer.contentWindow.min.js"></script>
<script src="jquery.js"></script>
<script type="text/javascript" src="../../js/iframeResizer.min.js"></script>
<script type="text/javascript" src="../../js/ie8.polyfils.min.js"></script>
<script type="text/javascript">
iFrameResize({
log: true, // Enable console logging
onResized: function (messageData) { // Callback fn when message is received
setTimeout(function () { parentIFrame.sendMessage('nested') }, 50);
}
});
</script>
</body>
</html>

View File

@ -0,0 +1,48 @@
define(['iframeResizer'], function(iFrameResize) {
describe('Scroll Page', function() {
var iframe
var log = LOG
beforeEach(function() {
loadIFrame('iframe600.html')
})
afterEach(function() {
tearDown(iframe)
})
it('mock incoming message', function(done) {
iframe = iFrameResize({
log: log,
id: 'scroll1'
})[0]
window.parentIFrame = {
scrollTo: function(x, y) {
expect(x).toBe(0)
expect(y).toBe(0)
done()
}
}
mockMsgFromIFrame(iframe, 'scrollTo')
})
it('mock incoming message', function(done) {
iframe = iFrameResize({
log: log,
id: 'scroll2'
})[0]
window.parentIFrame = {
scrollToOffset: function(x, y) {
expect(x).toBe(8)
expect(y).toBe(8)
done()
}
}
mockMsgFromIFrame(iframe, 'scrollToOffset')
})
})
})

View File

@ -0,0 +1,59 @@
define(['iframeResizer'], function(iFrameResize) {
describe('Send Message from Host Page', function() {
var iframe
var log = LOG
beforeEach(function() {
loadIFrame('iframe600.html')
})
afterEach(function() {
tearDown(iframe)
})
it('send message to iframe', function(done) {
var iframe1 = iFrameResize({
log: log,
id: 'sendMessage1'
})[0]
spyOnIFramePostMessage(iframe1)
setTimeout(function() {
iframe1.iFrameResizer.sendMessage('chkSendMsg:test')
expect(iframe1.contentWindow.postMessage).toHaveBeenCalledWith(
'[iFrameSizer]message:"chkSendMsg:test"',
getTarget(iframe1)
)
tearDown(iframe1)
done()
}, 100)
})
it('mock incoming message', function(done) {
iframe = iFrameResize({
log: log,
id: 'sendMessage2',
onMessage: function(messageData) {
expect(messageData.message).toBe('test:test')
done()
}
})[0]
mockMsgFromIFrame(iframe, 'message:"test:test"')
})
it('send message and get response', function(done) {
iframe = iFrameResize({
log: log,
id: 'sendMessage3',
onInit: function(iframe) {
iframe.iFrameResizer.sendMessage('chkSendMsg')
},
onMessage: function(messageData) {
expect(messageData.message).toBe('message: test string')
done()
}
})[0]
})
})
})

View File

@ -0,0 +1,5 @@
{
"spec_dir": "spec",
"spec_files": ["**/*[sS]pec.js"],
"helpers": ["helpers/**/*.js"]
}