<http://webkit.org/b/82558> Toggling <input type="range"> readonly or disabled state...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2012 18:11:40 +0000 (18:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2012 18:11:40 +0000 (18:11 +0000)
Source/WebCore:

Test: fast/forms/range/range-drag-when-toggled-disabled.html

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2012-03-29
Reviewed by Kent Tamura.

* html/shadow/SliderThumbElement.cpp:
(WebCore::SliderThumbElement::defaultEventHandler):
A slider can toggle its readonly or disabled state while in the middle
of dragging, in those cases we should cancel the drag and perform cleanup.

LayoutTests:

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2012-03-29
Reviewed by Kent Tamura.

* fast/forms/range/range-drag-when-toggled-disabled-expected.txt: Added.
* fast/forms/range/range-drag-when-toggled-disabled.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/range/range-drag-when-toggled-disabled-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/range/range-drag-when-toggled-disabled.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/shadow/SliderThumbElement.cpp

index 549e5f2..9461ade 100644 (file)
@@ -1,3 +1,12 @@
+2012-03-29  Joseph Pecoraro  <pecoraro@apple.com>
+
+        <http://webkit.org/b/82558> Toggling <input type="range"> readonly or disabled state while active breaks all click events
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/range/range-drag-when-toggled-disabled-expected.txt: Added.
+        * fast/forms/range/range-drag-when-toggled-disabled.html: Added.
+
 2012-03-29  Enrica Casucci  <enrica@apple.com>
 
         Updating test_expectations with new failures after r112484.
diff --git a/LayoutTests/fast/forms/range/range-drag-when-toggled-disabled-expected.txt b/LayoutTests/fast/forms/range/range-drag-when-toggled-disabled-expected.txt
new file mode 100644 (file)
index 0000000..f485a0a
--- /dev/null
@@ -0,0 +1,26 @@
+Test for dragging operations of <input type=range> when readonly or disabled are toggled.
+
+Tests for range dragging while it toggles to be readonly.
+readOnly=false, disabled=false
+PASS input.value is "100"
+PASS changeEventCounter is >= lastChangeEventCounter + 1
+PASS input.value is "0"
+PASS changeEventCounter is >= lastChangeEventCounter + 1
+readOnly=true
+PASS input.value is "0"
+PASS lastChangeEventCounter is changeEventCounter
+
+Tests for range dragging while it toggles to be disabled.
+readOnly=false, disabled=false
+PASS input.value is "100"
+PASS changeEventCounter is >= lastChangeEventCounter + 1
+PASS input.value is "0"
+PASS changeEventCounter is >= lastChangeEventCounter + 1
+disabled=true
+PASS input.value is "0"
+PASS lastChangeEventCounter is changeEventCounter
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
diff --git a/LayoutTests/fast/forms/range/range-drag-when-toggled-disabled.html b/LayoutTests/fast/forms/range/range-drag-when-toggled-disabled.html
new file mode 100644 (file)
index 0000000..307e054
--- /dev/null
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description">Test for dragging operations of &lt;input type=range&gt; when <code>readonly</code> or <code>disabled</code> are toggled.</p>
+<div id="console"></div>
+<input type="range" id="range1" min="0" max="100" value="50">
+<input type="range" id="range2" min="0" max="100" value="50">
+<script>
+
+var changeEventCounter = 0;
+var lastChangeEventCounter = changeEventCounter;
+function handleChange() {
+    changeEventCounter++;
+}
+
+var input = null;
+
+function testInput(id, field) {
+    if (!window.eventSender)
+        return;
+
+    input = document.getElementById(id);
+    input.onchange = handleChange;
+    input.focus();
+
+    var centerY = input.offsetTop + input.offsetHeight / 2;
+    var centerX = input.offsetLeft + input.offsetWidth / 2;
+    var leftEdgeX = input.offsetLeft + 1;
+    var rightEdgeX = input.offsetLeft + input.offsetWidth - 1;
+
+    function dragToLeftEdge() { eventSender.mouseMoveTo(leftEdgeX, centerY); }
+    function dragToRightEdge() { eventSender.mouseMoveTo(rightEdgeX, centerY); }
+    function dragToCenter() { eventSender.mouseMoveTo(centerX, centerY); }
+
+    function startDragFromCenter() {
+        eventSender.mouseMoveTo(centerX, centerY);
+        eventSender.mouseDown();
+    }
+
+    function stopDrag() {
+        eventSender.mouseUp();
+    }
+
+    startDragFromCenter();
+
+    // Drag from center, to right edge, to left edge.
+    debug('readOnly=false, disabled=false');
+    input.valueAsNumber = 50;
+    lastChangeEventCounter = changeEventCounter;
+    dragToRightEdge();
+    shouldBe('input.value', '"100"');
+    shouldBeGreaterThanOrEqual('changeEventCounter', 'lastChangeEventCounter + 1');
+    lastChangeEventCounter = changeEventCounter;
+    dragToLeftEdge();
+    shouldBe('input.value', '"0"');
+    shouldBeGreaterThanOrEqual('changeEventCounter', 'lastChangeEventCounter + 1');
+
+    // Toggle (readonly | disabled).
+    debug(field + '=true');
+    input[field] = true;
+
+    // Attempt to drag to right edge. Should not change.
+    lastChangeEventCounter = changeEventCounter;
+    dragToRightEdge();
+    shouldBe('input.value', '"0"');
+    shouldBe('lastChangeEventCounter', 'changeEventCounter');
+
+    stopDrag();
+}
+
+
+// We want all mouse moves sent immediately.
+window.eventSender.dragMode = false;
+
+debug('Tests for range dragging while it toggles to be readonly.');
+testInput('range1', 'readOnly');
+debug('');
+
+debug('Tests for range dragging while it toggles to be disabled.');
+testInput('range2', 'disabled');
+debug('');
+
+</script>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
index 39452a9..7414f00 100644 (file)
@@ -1,3 +1,16 @@
+2012-03-29  Joseph Pecoraro  <pecoraro@apple.com>
+
+        <http://webkit.org/b/82558> Toggling <input type="range"> readonly or disabled state while active breaks all click events
+
+        Test: fast/forms/range/range-drag-when-toggled-disabled.html
+
+        Reviewed by Kent Tamura.
+
+        * html/shadow/SliderThumbElement.cpp:
+        (WebCore::SliderThumbElement::defaultEventHandler):
+        A slider can toggle its readonly or disabled state while in the middle
+        of dragging, in those cases we should cancel the drag and perform cleanup.
+
 2012-03-29  Adam Klein  <adamk@chromium.org>
 
         Factor out common post-insertion logic in ContainerNode
index 164cbfb..f8af39f 100644 (file)
@@ -278,6 +278,7 @@ void SliderThumbElement::defaultEventHandler(Event* event)
     // Missing this kind of check is likely to occur elsewhere if adding it in each shadow element.
     HTMLInputElement* input = hostInput();
     if (!input || input->isReadOnlyFormControl() || !input->isEnabledFormControl()) {
+        stopDragging();
         HTMLDivElement::defaultEventHandler(event);
         return;
     }