Index: third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-tags.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-tags.html b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-tags.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c06b441b3281906dd34079fcc2cf6ad909580249 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-tags.html |
@@ -0,0 +1,91 @@ |
+<!DOCTYPE html> |
+<script src="/resources/testharness.js"></script> |
+<script src="/resources/testharnessreport.js"></script> |
+<style> |
+/* "display: none" prevents loading of <object> resources, so use */ |
+/* "visibility: hidden" instead. */ |
+.invisible { visibility: hidden; } |
+</style> |
+<script> |
+const urls = { |
+ '/resources/square20.jpg': ['img', 529], |
+ '/resources/square20.gif': ['img', 50], |
+ '/resources/square20.png': ['img', 150], |
+ '/resources/test.ogv': ['video', 103746], |
+ '/resources/test.oga': ['audio', 20787], |
+ '/resources/dummy.html': ['iframe', 34], |
+ '/resources/dummy.js': ['script', 7], |
+ '/resources/dummy.css': ['link', 8], |
+ '/svg/resources/greenSquare.svg': ['object', 244], |
+}; |
+ |
+const srcFieldExceptions = { |
+ 'object': 'data', |
+ 'link': 'href', |
+}; |
+ |
+const totalResourceCount = Object.keys(urls).length; |
+const cacheBuster = '?cb=' + Math.random().toString().substr(2); |
+var seenResourceCount = 0; |
+var t = async_test('PerformanceResourceTiming sizes tags test'); |
+ |
+function isMediaTag(tag) { |
+ return tag === 'video' || tag === 'audio'; |
+} |
+ |
+function addTag(url, tag) { |
+ var element = document.createElement(tag); |
+ var srcfield = srcFieldExceptions[tag]; |
+ if (!srcfield) { |
+ srcfield = 'src'; |
+ } |
+ element.setAttribute(srcfield, url + cacheBuster); |
+ element.setAttribute('class', 'invisible'); |
+ if (tag === 'link') { |
+ element.setAttribute('rel', 'stylesheet'); |
+ } |
+ var onloadevent = isMediaTag(tag) ? 'oncanplaythrough' : 'onload'; |
+ element[onloadevent] = t.step_func(() => { |
+ // The entry is not guaranteed to be added synchronously by the spec, |
+ // although the current implementation does. |
+ setTimeout(t.step_func(loaded), 0); |
+ }); |
+ document.body.appendChild(element); |
+} |
+ |
+// Postpone checking until everything is loaded so that the checks will be done |
+// in a deterministic order. |
+function loaded() { |
+ ++seenResourceCount; |
+ if (seenResourceCount === totalResourceCount) |
+ checkAllResources(); |
+} |
+ |
+function checkAllResources() { |
+ for (relativeUrl of Object.keys(urls).sort()) { |
+ checkResourceSizes(relativeUrl + cacheBuster, urls[relativeUrl][1]); |
+ } |
+ t.done(); |
+} |
+ |
+function checkResourceSizes(relativeUrl, expectedSize) { |
+ var absoluteUrl = new URL(relativeUrl, location.href).href; |
+ var entry = performance.getEntriesByName(absoluteUrl, 'resource')[0]; |
+ decodedBodySize = entry.decodedBodySize; |
+ assert_equals(entry.decodedBodySize, expectedSize, |
+ relativeUrl + ' decodedBodySize'); |
+ assert_equals(entry.encodedBodySize, expectedSize, |
+ relativeUrl + ' encodedBodySize'); |
+ transferSize = entry.transferSize; |
+ assert_greater_than(entry.transferSize, expectedSize, |
+ relativeUrl + ' transferSize'); |
+} |
+ |
+function runTest() { |
+ for (var url in urls) { |
+ addTag(url, urls[url][0]); |
+ } |
+} |
+ |
+window.onload = t.step_func(runTest); |
+</script> |