Bug 1508904 [wpt PR 14152] - IndexedDB: Handle the opaque origin case for IDBFactory.databases(), a=testonly
authorAndreas Butler <andreasbutler@google.com>
Tue, 27 Nov 2018 20:12:01 +0000
changeset 507936 e93fd4f50dd100d515cc84b92832b9e9fa5889bc
parent 507935 33848f48c13677e4deaf92fbf734ef925e0da8bb
child 507937 48ab9c0a88dd621d6ab0bbecd20746943a6383dc
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1508904, 14152, 1344629, 610143
milestone65.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 1508904 [wpt PR 14152] - IndexedDB: Handle the opaque origin case for IDBFactory.databases(), a=testonly Automatic update from web-platform-testsIndexedDB: Handle the opaque origin case for IDBFactory.databases() Implemented the proper throwing behaviour for handling the case of an opaque origin for IDBFactory.databases(). Also included is a WPT for verifying the behaviour written by jsbell@. Spec PR: https://github.com/w3c/IndexedDB/pull/250 Change-Id: I506f82bf69b27d34b499eacbe12aaa18a69b63be Reviewed-on: https://chromium-review.googlesource.com/c/1344629 Commit-Queue: Andreas Butler <andreasbutler@google.com> Reviewed-by: Joshua Bell <jsbell@chromium.org> Reviewed-by: Victor Costan <pwnall@chromium.org> Cr-Commit-Position: refs/heads/master@{#610143} -- wpt-commits: 909109663818a4abe194324356208644d5602ddc wpt-pr: 14152
testing/web-platform/tests/IndexedDB/idbfactory-databases-opaque-origin.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/IndexedDB/idbfactory-databases-opaque-origin.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<meta charset=utf-8>
+<title>IDBFactory.databases() and opaque origins</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+function load_iframe(src, sandbox) {
+  return new Promise(resolve => {
+    const iframe = document.createElement('iframe');
+    iframe.onload = () => { resolve(iframe); };
+    if (sandbox)
+      iframe.sandbox = sandbox;
+    iframe.srcdoc = src;
+    iframe.style.display = 'none';
+    document.documentElement.appendChild(iframe);
+  });
+}
+
+function wait_for_message(iframe) {
+  return new Promise(resolve => {
+    self.addEventListener('message', function listener(e) {
+      if (e.source === iframe.contentWindow) {
+        resolve(e.data);
+        self.removeEventListener('message', listener);
+      }
+    });
+  });
+}
+
+const script =
+  '<script>' +
+  '  window.onmessage = () => {' +
+  '    indexedDB.databases().then(' +
+  '      () => window.parent.postMessage({result: "no exception"}, "*"),' +
+  '      ex => window.parent.postMessage({result: ex.name}, "*"));' +
+  '  };' +
+  '<\/script>';
+
+promise_test(async t => {
+  const iframe = await load_iframe(script);
+  iframe.contentWindow.postMessage({}, '*');
+  const message = await wait_for_message(iframe);
+  assert_equals(message.result, 'no exception',
+                'IDBFactory.databases() should not reject');
+}, 'IDBFactory.databases() in non-sandboxed iframe should not reject');
+
+promise_test(async t => {
+  const iframe = await load_iframe(script, 'allow-scripts');
+  iframe.contentWindow.postMessage({}, '*');
+  const message = await wait_for_message(iframe);
+  assert_equals(message.result, 'SecurityError',
+                'Exception should be SecurityError');
+}, 'IDBFactory.databases() in sandboxed iframe should reject');
+</script>