Bug 1621734 [wpt PR 22196] - Reveal only the initial frame URL in performance.measureMemory, a=testonly
authorUlan Degenbaev <ulan@chromium.org>
Sat, 14 Mar 2020 11:28:33 +0000
changeset 518840 b125b93d3bb2927328ca06551dd7d2dec038113e
parent 518839 5508fdda7dd9399556c7f503b25e34d9bdc121fc
child 518841 1d669ca911c7f09b386ede254594b7b9bf9e3447
push id37217
push userccoroiu@mozilla.com
push dateSun, 15 Mar 2020 21:37:59 +0000
treeherdermozilla-central@f9fc9427476e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1621734, 22196, 1049093, 2098722, 749663
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1621734 [wpt PR 22196] - Reveal only the initial frame URL in performance.measureMemory, a=testonly Automatic update from web-platform-tests Reveal only the initial frame URL in performance.measureMemory This changes the reporting in performance.measureMemory to reveal only the URL at the frame creation time for cross-origin iframes and thus prevents URL information leak if the iframe navigates after loading. This is done by saving the first cross-origin URL loaded in LocalFrame in LocalFrame::DidAttachDocument and using that URL for reporting. The patch also adds a new test for redirecting iframe and fixes the existing tests to wait until child iframes are loaded. Bug: 1049093 Change-Id: I0162efb82061f036450586dea0b191cacdce23f2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098722 Commit-Queue: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Kentaro Hara <haraken@chromium.org> Cr-Commit-Position: refs/heads/master@{#749663} -- wpt-commits: 9e8ef92c126116b4fb73361bbe60d7e1dad9a52e wpt-pr: 22196
testing/web-platform/tests/measure-memory/measure-memory-cross-origin-iframe.tentative.window.js
testing/web-platform/tests/measure-memory/measure-memory-cross-origin-redirecting-iframe.tentative.window.js
testing/web-platform/tests/measure-memory/measure-memory-same-origin-iframe.tentative.window.js
testing/web-platform/tests/measure-memory/resources/child.sub.html
testing/web-platform/tests/measure-memory/resources/common.js
testing/web-platform/tests/measure-memory/resources/grandchild.sub.html
testing/web-platform/tests/measure-memory/resources/redirecting-child.sub.html
--- a/testing/web-platform/tests/measure-memory/measure-memory-cross-origin-iframe.tentative.window.js
+++ b/testing/web-platform/tests/measure-memory/measure-memory-cross-origin-iframe.tentative.window.js
@@ -1,19 +1,25 @@
 // META: script=/common/get-host-info.sub.js
 // META: script=./resources/common.js
-// META: timeout=long
 'use strict';
 
 promise_test(async testCase => {
-  const frame = document.createElement("iframe");
-  const child = getUrl(CROSS_ORIGIN, "resources/child.sub.html");
-  const grandchild = getUrl(CROSS_ORIGIN, "resources/grandchild.sub.html");
+  const grandchildLoaded = new Promise(resolve => {
+    window.onmessage = function(message) {
+      if (message.data === 'grandchild-loaded') {
+        resolve(message);
+      }
+    }
+  });
+  const frame = document.createElement('iframe');
+  const child = getUrl(CROSS_ORIGIN, 'resources/child.sub.html');
   frame.src = child;
   document.body.append(frame);
+  await grandchildLoaded;
   try {
     let result = await performance.measureMemory();
     checkMeasureMemory(result, {
       allowed: [window.location.href, child]
     });
   } catch (error) {
     if (!(error instanceof DOMException)) {
       throw error;
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/measure-memory/measure-memory-cross-origin-redirecting-iframe.tentative.window.js
@@ -0,0 +1,29 @@
+// META: script=/common/get-host-info.sub.js
+// META: script=./resources/common.js
+'use strict';
+
+promise_test(async testCase => {
+  const grandchildLoaded = new Promise(resolve => {
+    window.onmessage = function(message) {
+      if (message.data === 'grandchild-loaded') {
+        resolve(message);
+      }
+    }
+  });
+  const frame = document.createElement('iframe');
+  const redirecting_child = getUrl(CROSS_ORIGIN, 'resources/redirecting-child.sub.html');
+  frame.src = redirecting_child;
+  document.body.append(frame);
+  await grandchildLoaded;
+  try {
+    let result = await performance.measureMemory();
+    checkMeasureMemory(result, {
+      allowed: [window.location.href, redirecting_child]
+    });
+  } catch (error) {
+    if (!(error instanceof DOMException)) {
+      throw error;
+    }
+    assert_equals(error.name, 'SecurityError');
+  }
+}, 'Well-formed result of performance.measureMemory with cross-origin iframe.');
--- a/testing/web-platform/tests/measure-memory/measure-memory-same-origin-iframe.tentative.window.js
+++ b/testing/web-platform/tests/measure-memory/measure-memory-same-origin-iframe.tentative.window.js
@@ -1,19 +1,26 @@
 // META: script=/common/get-host-info.sub.js
 // META: script=./resources/common.js
-// META: timeout=long
 'use strict';
 
 promise_test(async testCase => {
-  const frame = document.createElement("iframe");
-  const child = getUrl(SAME_ORIGIN, "resources/child.sub.html");
-  const grandchild = getUrl(SAME_ORIGIN, "resources/grandchild.sub.html");
+  const grandchildLoaded = new Promise(resolve => {
+    window.onmessage = function(message) {
+      if (message.data === 'grandchild-loaded') {
+        resolve(message);
+      }
+    }
+  });
+  const frame = document.createElement('iframe');
+  const child = getUrl(SAME_ORIGIN, 'resources/child.sub.html');
+  const grandchild = getUrl(SAME_ORIGIN, 'resources/grandchild.sub.html');
   frame.src = child;
   document.body.append(frame);
+  await grandchildLoaded;
   try {
     let result = await performance.measureMemory();
     checkMeasureMemory(result, {
       allowed: [window.location.href, child, grandchild],
     });
   } catch (error) {
     if (!(error instanceof DOMException)) {
       throw error;
--- a/testing/web-platform/tests/measure-memory/resources/child.sub.html
+++ b/testing/web-platform/tests/measure-memory/resources/child.sub.html
@@ -1,8 +1,17 @@
 <!doctype html>
 <meta charset=utf-8>
 <html>
+<script>
+window.onmessage = function (message) {
+  // Forward the message to the parent.
+  window.parent.postMessage(message.data, '*');
+}
+window.onload = function () {
+  window.parent.postMessage('grandchild-loaded', '*');
+}
+</script>
 <body>
   Hello from child iframe.
   <iframe src="grandchild.sub.html"></iframe>
 </body>
 </html>
--- a/testing/web-platform/tests/measure-memory/resources/common.js
+++ b/testing/web-platform/tests/measure-memory/resources/common.js
@@ -1,10 +1,10 @@
-const SAME_ORIGIN = {origin: get_host_info().HTTPS_ORIGIN, name: "SAME_ORIGIN"};
-const CROSS_ORIGIN = {origin: get_host_info().HTTPS_NOTSAMESITE_ORIGIN, name: "CROSS_ORIGIN"}
+const SAME_ORIGIN = {origin: get_host_info().HTTP_ORIGIN, name: "SAME_ORIGIN"};
+const CROSS_ORIGIN = {origin: get_host_info().HTTP_REMOTE_ORIGIN, name: "CROSS_ORIGIN"}
 
 function checkMeasureMemoryBreakdown(breakdown, options) {
   let allowed = new Set(options.allowed);
   assert_own_property(breakdown, 'bytes');
   assert_greater_than_equal(breakdown.bytes, 0);
   assert_own_property(breakdown, 'userAgentSpecificTypes');
   for (let userAgentSpecificType of breakdown.userAgentSpecificTypes) {
     assert_equals(typeof userAgentSpecificType, 'string');
@@ -26,10 +26,10 @@ function checkMeasureMemory(result, opti
       checkMeasureMemoryBreakdown(breakdown, options);
       bytes += breakdown.bytes;
     }
     assert_equals(bytes, result.bytes);
 }
 
 function getUrl(host, relativePath) {
   const path = new URL(relativePath, window.location).pathname;
-  return `${host.origin}/${path}`;
+  return `${host.origin}${path}`;
 }
\ No newline at end of file
--- a/testing/web-platform/tests/measure-memory/resources/grandchild.sub.html
+++ b/testing/web-platform/tests/measure-memory/resources/grandchild.sub.html
@@ -1,7 +1,12 @@
 <!doctype html>
 <meta charset=utf-8>
 <html>
+<script>
+window.onload = function () {
+  window.parent.postMessage('grandchild-loaded', '*');
+}
+</script>
 <body>
   Hello from grandchild iframe.
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/measure-memory/resources/redirecting-child.sub.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<meta charset=utf-8>
+<html>
+<script>
+window.onload = function () {
+  document.location.href = document.location.href.replace('redirecting-child', 'child');
+}
+</script>
+<body>
+  Hello from child iframe.
+</body>
+</html>