forked from bluesmoon/boomerang
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ResourceTiming: Additional checks and fixes for non-supported browsers
- Loading branch information
Showing
4 changed files
with
140 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<%= header %> | ||
<%= boomerangScript %> | ||
<script src="08-cross-origin.js" type="text/javascript"></script> | ||
<script src="../../vendor/resourcetiming-compression/src/resourcetiming-decompression.js" type="text/javascript"></script> | ||
<img src="/assets/img.jpg?beforeiframe" /> | ||
<script> | ||
BOOMR_test.init({ | ||
testAfterOnBeacon: true, | ||
ResourceTiming: { | ||
enabled: true | ||
}, | ||
autorun: false, | ||
History: { | ||
enabled: true, | ||
auto: true | ||
} | ||
}); | ||
</script> | ||
|
||
<!-- won't be able to get any resources from this frame --> | ||
<iframe id="cross-origin"></iframe> | ||
<script> | ||
var host = window.location.hostname; | ||
var port = (parseInt(window.location.port) || 4002) + 1; | ||
window.crossOriginPort = port; | ||
document.getElementById("cross-origin").src = "//" + host + ":" + port + "/pages/11-restiming/support/iframe.html?cross-origin"; | ||
</script> | ||
|
||
<!-- should be able to get resources from this one --> | ||
<iframe id="same-origin" src="support/iframe.html?same-origin"></iframe> | ||
<img src="/assets/img.jpg?afteriframe" /> | ||
<%= footer %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/*eslint-env mocha*/ | ||
/*eslint-disable no-loop-func*/ | ||
/*global BOOMR_test,assert*/ | ||
|
||
describe("e2e/11-restiming/06-iframes", function() { | ||
var t = BOOMR_test; | ||
var tf = BOOMR.plugins.TestFramework; | ||
|
||
it("Should pass basic beacon validation", function(done) { | ||
t.validateBeaconWasSent(done); | ||
}); | ||
|
||
it("Should have a restiming parameter on the beacon (if ResourceTiming is supported)", function() { | ||
if (t.isResourceTimingSupported()) { | ||
var b = tf.lastBeacon(); | ||
assert.isDefined(b.restiming); | ||
} | ||
}); | ||
|
||
it("Should have all of the resouces on the page", function() { | ||
if (t.isResourceTimingSupported()) { | ||
var b = tf.lastBeacon(); | ||
|
||
var resources = ResourceTimingDecompression.decompressResources(JSON.parse(b.restiming)); | ||
var pageResources = window.performance.getEntriesByType("resource"); | ||
|
||
for (var i = 0; i < pageResources.length; i++) { | ||
var url = pageResources[i].name; | ||
|
||
// skip beacon URL | ||
if (url.indexOf("blackhole") !== -1) { | ||
continue; | ||
} | ||
|
||
assert.isDefined(resources.find(function(r) { | ||
return r.name === url; | ||
}), "Finding " + url); | ||
} | ||
} | ||
}); | ||
|
||
it("Should have the same-origin IFRAME", function() { | ||
if (t.isResourceTimingSupported()) { | ||
var b = tf.lastBeacon(); | ||
|
||
var resources = ResourceTimingDecompression.decompressResources(JSON.parse(b.restiming)); | ||
|
||
assert.isDefined(resources.find(function(r) { | ||
return r.name.indexOf("support/iframe.html?same-origin") !== -1; | ||
}), "Finding support/iframe.html?same-origin"); | ||
} | ||
}); | ||
|
||
it("Should have the IMG from the same-origin IFRAME", function() { | ||
if (t.isResourceTimingSupported()) { | ||
var b = tf.lastBeacon(); | ||
|
||
var resources = ResourceTimingDecompression.decompressResources(JSON.parse(b.restiming)); | ||
|
||
assert.isDefined(resources.find(function(r) { | ||
return r.name.indexOf("/assets/img.jpg?iframe") !== -1; | ||
}), "Finding /assets/img.jpg?iframe in the IFRAME"); | ||
} | ||
}); | ||
|
||
it("Should have the cross-origin IFRAME", function() { | ||
if (t.isResourceTimingSupported()) { | ||
var b = tf.lastBeacon(); | ||
|
||
var resources = ResourceTimingDecompression.decompressResources(JSON.parse(b.restiming)); | ||
|
||
assert.isDefined(resources.find(function(r) { | ||
return r.name.indexOf("support/iframe.html?cross-origin") !== -1; | ||
}), "Finding support/iframe.html?cross-origin"); | ||
} | ||
}); | ||
|
||
it("Should not have the IMG from the cross-origin IFRAME", function() { | ||
if (t.isResourceTimingSupported()) { | ||
var b = tf.lastBeacon(); | ||
|
||
var resources = ResourceTimingDecompression.decompressResources(JSON.parse(b.restiming)); | ||
|
||
assert.isUndefined(resources.find(function(r) { | ||
return r.name.indexOf("/assets/img.jpg?afteriframe") !== -1 && | ||
r.name.indexOf(":" + window.crossOriginPort) !== -1; | ||
}), "Not finding /assets/img.jpg?afteriframe from cross-origin iframe"); | ||
} | ||
}); | ||
}); |