Pointer Lock requestPointerLock rejects locking an element not in a document.
authorscheib@chromium.org <scheib@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jul 2012 00:08:36 +0000 (00:08 +0000)
committerscheib@chromium.org <scheib@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Jul 2012 00:08:36 +0000 (00:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=90821

Reviewed by Adrienne Walker.

Source/WebCore:

Test: pointer-lock/lock-element-not-in-dom.html

* page/PointerLockController.cpp:
(WebCore::PointerLockController::requestPointerLock):

LayoutTests:

* pointer-lock/lock-element-not-in-dom-expected.txt: Added.
* pointer-lock/lock-element-not-in-dom.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/pointer-lock/lock-element-not-in-dom-expected.txt [new file with mode: 0644]
LayoutTests/pointer-lock/lock-element-not-in-dom.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/page/PointerLockController.cpp

index aad9692..a949bb3 100644 (file)
@@ -1,3 +1,13 @@
+2012-07-09  Vincent Scheib  <scheib@chromium.org>
+
+        Pointer Lock requestPointerLock rejects locking an element not in a document.
+        https://bugs.webkit.org/show_bug.cgi?id=90821
+
+        Reviewed by Adrienne Walker.
+
+        * pointer-lock/lock-element-not-in-dom-expected.txt: Added.
+        * pointer-lock/lock-element-not-in-dom.html: Added.
+
 2012-07-09  Eric Seidel  <eric@webkit.org>
 
         document.write of scripts that also document.write sometimes writes async
diff --git a/LayoutTests/pointer-lock/lock-element-not-in-dom-expected.txt b/LayoutTests/pointer-lock/lock-element-not-in-dom-expected.txt
new file mode 100644 (file)
index 0000000..adc0438
--- /dev/null
@@ -0,0 +1,13 @@
+Test locking an element not in a document is rejected and pointerlockerror event dispatched.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS targetDiv1.parentElement is not null
+     Remove targetDiv1 from document, and try to lock it.
+PASS targetDiv1.parentElement is null
+PASS onwebkitpointerlockerror received after: Remove targetDiv1 from document, and try to lock it.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/pointer-lock/lock-element-not-in-dom.html b/LayoutTests/pointer-lock/lock-element-not-in-dom.html
new file mode 100644 (file)
index 0000000..97a99a8
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+<script src="resources/pointer-lock-test-harness.js"></script>
+</head>
+<body>
+<div>
+  <div id="target1"></div>
+</div>
+<script>
+    description("Test locking an element not in a document is rejected and pointerlockerror event dispatched.")
+    window.jsTestIsAsync = true;
+
+    targetDiv1 = document.getElementById("target1");
+
+    todo = [
+        function () {
+            shouldNotBe("targetDiv1.parentElement", "null");
+            expectOnlyErrorEvent("Remove targetDiv1 from document, and try to lock it.");
+            targetDiv1.parentElement.removeChild(targetDiv1);
+            shouldBe("targetDiv1.parentElement", "null");
+            targetDiv1.webkitRequestPointerLock();
+            // doNextStep called by event handler.
+        },
+    ];
+    doNextStepWithUserGesture();
+</script>
+<script src="../fast/js/resources/js-test-post.js"></script>
+</body>
+</html>
index c37ecc1..afac97b 100644 (file)
@@ -1,3 +1,15 @@
+2012-07-09  Vincent Scheib  <scheib@chromium.org>
+
+        Pointer Lock requestPointerLock rejects locking an element not in a document.
+        https://bugs.webkit.org/show_bug.cgi?id=90821
+
+        Reviewed by Adrienne Walker.
+
+        Test: pointer-lock/lock-element-not-in-dom.html
+
+        * page/PointerLockController.cpp:
+        (WebCore::PointerLockController::requestPointerLock):
+
 2012-07-09  Eric Seidel  <eric@webkit.org>
 
         document.write of scripts that also document.write sometimes writes async
index 5c70dcf..c250cb7 100644 (file)
@@ -51,6 +51,11 @@ void PointerLockController::requestPointerLock(Element* target, PassRefPtr<VoidC
     if (!target)
         return;
 
+    if (!target->inDocument()) {
+        enqueueEvent(eventNames().webkitpointerlockerrorEvent, target);
+        return;
+    }
+
     if (isLocked()) {
         // FIXME: Keep enqueueEvent usage. (https://bugs.webkit.org/show_bug.cgi?id=84402)
         enqueueEvent(eventNames().webkitpointerlockchangeEvent, target);