Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/misc/resource-timing-sizes-tags.html

Issue 2105713002: Render process changes for ResourceTiming sizes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resource_timing_sizes_browser_process
Patch Set: Initialise encoded_body_length for sync XHR to data: URLs Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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>

Powered by Google App Engine
This is Rietveld 408576698