Add test verifying detached iframes cannot set IDB values
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jul 2016 21:14:28 +0000 (21:14 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Jul 2016 21:14:28 +0000 (21:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159736

Patch by Alex Christensen <achristensen@webkit.org> on 2016-07-13
Reviewed by Brady Eidson.

We match Chrome but not Firefox in this case.

* storage/indexeddb/detached-iframe-expected.txt: Added.
* storage/indexeddb/detached-iframe.html: Added.
* storage/indexeddb/resources/detached-iframe.html: Added.
* storage/indexeddb/resources/detached-iframe.js: Added.
(done):
(unexpectedErrorCallback):
(getRequestCallback):
(dbOpenedSecondTime):
(getValueFromIDB):
(makeDetachedFrame):
(prepareDatabase):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203188 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/storage/indexeddb/detached-iframe-expected.txt [new file with mode: 0644]
LayoutTests/storage/indexeddb/detached-iframe.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/resources/detached-iframe.html [new file with mode: 0644]
LayoutTests/storage/indexeddb/resources/detached-iframe.js [new file with mode: 0644]

index fb52788..9ade02e 100644 (file)
@@ -1,3 +1,24 @@
+2016-07-13  Alex Christensen  <achristensen@webkit.org>
+
+        Add test verifying detached iframes cannot set IDB values
+        https://bugs.webkit.org/show_bug.cgi?id=159736
+
+        Reviewed by Brady Eidson.
+        
+        We match Chrome but not Firefox in this case.
+
+        * storage/indexeddb/detached-iframe-expected.txt: Added.
+        * storage/indexeddb/detached-iframe.html: Added.
+        * storage/indexeddb/resources/detached-iframe.html: Added.
+        * storage/indexeddb/resources/detached-iframe.js: Added.
+        (done):
+        (unexpectedErrorCallback):
+        (getRequestCallback):
+        (dbOpenedSecondTime):
+        (getValueFromIDB):
+        (makeDetachedFrame):
+        (prepareDatabase):
+
 2016-07-12  Ryosuke Niwa  <rniwa@webkit.org>
 
         REGRESSION(r202953): Clicking on input[type=file] doesn't open a file picker
diff --git a/LayoutTests/storage/indexeddb/detached-iframe-expected.txt b/LayoutTests/storage/indexeddb/detached-iframe-expected.txt
new file mode 100644 (file)
index 0000000..d9b926a
--- /dev/null
@@ -0,0 +1,5 @@
+ALERT: original value
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/storage/indexeddb/detached-iframe.html b/LayoutTests/storage/indexeddb/detached-iframe.html
new file mode 100644 (file)
index 0000000..31ddd47
--- /dev/null
@@ -0,0 +1,16 @@
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/shared.js"></script>
+<script>
+function detachIframe() {
+    var testIframe = document.getElementById('testIframe');
+    testIframe.parentNode.remove(testIframe);
+}
+</script>
+</head>
+<body>
+<script src="resources/detached-iframe.js"></script>
+<iframe src="resources/detached-iframe.html" id="testIframe"></iframe>
+</body>
+</html>
diff --git a/LayoutTests/storage/indexeddb/resources/detached-iframe.html b/LayoutTests/storage/indexeddb/resources/detached-iframe.html
new file mode 100644 (file)
index 0000000..40a3c62
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<script>
+
+function databaseOpened(event) {
+    var getRequest = event.target.result.transaction(["foo"], "readwrite").objectStore("foo").put("value from detached iframe", "key");
+    getRequest.onsuccess = getRequestCallback;
+    getRequest.onerror = unexpectedErrorCallback;
+}
+
+function openDatabase(event) {
+    parent.detachIframe();
+    var openRequest = window.indexedDB.open("detached-iframe.html");
+    openRequest.onsuccess = databaseOpened;
+    openRequest.onblocked = openDatabase;
+}
+
+window.addEventListener("message", openDatabase, false);
+
+</script>
diff --git a/LayoutTests/storage/indexeddb/resources/detached-iframe.js b/LayoutTests/storage/indexeddb/resources/detached-iframe.js
new file mode 100644 (file)
index 0000000..587b5d5
--- /dev/null
@@ -0,0 +1,35 @@
+indexedDBTest(prepareDatabase);
+
+function done() { finishJSTest(); }
+
+function unexpectedErrorCallback() { alert("unexpected error"); done(); }
+
+function getRequestCallback(event) {
+    alert(event.target.result);
+    done();
+}
+
+function dbOpenedSecondTime(event) {
+    var getRequest = event.target.result.transaction(["foo"], "readonly").objectStore("foo").get("key");
+    getRequest.onsuccess = getRequestCallback;
+    getRequest.onerror = unexpectedErrorCallback;
+}
+
+function getValueFromIDB() {
+    var openRequest = window.indexedDB.open(dbname);
+    openRequest.onsuccess = dbOpenedSecondTime;
+    openRequest.onblocked = unexpectedErrorCallback;
+}
+
+function makeDetachedFrame() {
+    var iframe = document.getElementById('testIframe');
+    iframe.contentWindow.postMessage('value1inDB', '*');
+
+       setTimeout(getValueFromIDB, 500);
+}
+
+function prepareDatabase(event) {
+    var request = event.target.result.createObjectStore("foo").add("original value", "key");
+    request.onsuccess = makeDetachedFrame;
+    request.onerror = unexpectedErrorCallback;
+}