Correct handling of changing input type
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Nov 2016 20:14:02 +0000 (20:14 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Nov 2016 20:14:02 +0000 (20:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=164759
<rdar://problem/29211174>

Reviewed by Darin Adler.

Source/WebCore:

Test: fast/forms/search-cancel-button-change-input.html

It is possible for JavaScript to change the type property of an input field. WebKit
needs to gracefully handle this case.

Add a type traits specialization so we can properly downcast InputType elements.
Use this to only call search functions on actual search input types.

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::onSearch): Only perform search functions if the
input type is actually a search field.
* html/InputType.h: Add type traits specialization for 'downcast' template.
* html/SearchInputType.h: Ditto.

LayoutTests:

* fast/forms/search-cancel-button-change-input-expected.txt: Added.
* fast/forms/search-cancel-button-change-input.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/forms/search-cancel-button-change-input-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/search-cancel-button-change-input.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.order
Source/WebCore/html/HTMLInputElement.cpp
Source/WebCore/html/InputType.h
Source/WebCore/html/SearchInputType.h

index 9ff96ee..6822264 100644 (file)
@@ -1,3 +1,14 @@
+2016-11-14  Brent Fulgham  <bfulgham@apple.com>
+
+        Correct handling of changing input type
+        https://bugs.webkit.org/show_bug.cgi?id=164759
+        <rdar://problem/29211174>
+
+        Reviewed by Darin Adler.
+
+        * fast/forms/search-cancel-button-change-input-expected.txt: Added.
+        * fast/forms/search-cancel-button-change-input.html: Added.
+
 2016-11-15  Antti Koivisto  <antti@apple.com>
 
         slot doesn't work as a flex container
diff --git a/LayoutTests/fast/forms/search-cancel-button-change-input-expected.txt b/LayoutTests/fast/forms/search-cancel-button-change-input-expected.txt
new file mode 100644 (file)
index 0000000..d6e9d8a
--- /dev/null
@@ -0,0 +1,10 @@
+Tests that changing input type in a cancel button handler works properly.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS Search event was not triggered.
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/search-cancel-button-change-input.html b/LayoutTests/fast/forms/search-cancel-button-change-input.html
new file mode 100644 (file)
index 0000000..4a9110d
--- /dev/null
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/common.js"></script>
+<script>
+description('Tests that changing input type in a cancel button handler works properly.');
+
+window.jsTestIsAsync = true;
+
+var inputElement;
+var workProduct = [];
+
+function finish() {
+    testPassed("Search event was not triggered.");
+    finishJSTest();
+}
+
+function handleSearch(e) {
+    testFailed("A search event was triggered.");
+    finishJSTest();
+}
+
+function changeType(e) {
+    inputElement["type"] = "image"
+    setTimeout(function() {
+        finish();
+    }, 0);
+}
+
+function clickCancel() {
+    var cancelButtonPosition = searchCancelButtonPosition(inputElement);
+
+    eventSender.mouseMoveTo(cancelButtonPosition.x, cancelButtonPosition.y);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+}
+
+function runTest() {
+    if (!window.testRunner) {
+        testRunner.dumpAsText(true);
+        testRunner.waitUntilDone();
+    }
+
+    inputElement = document.getElementById("target");
+
+    inputElement.addEventListener("input", changeType);
+
+    setTimeout(function() {
+        clickCancel();
+    }, 0);
+}
+</script>
+</head>
+<body onload="runTest()">
+    <input id="target" type="search" onSearch="handleSearch();" value="Click the cancel button."></input>
+</body>
+</html>
index 60a78ab..cf60ecf 100644 (file)
@@ -1,3 +1,25 @@
+2016-11-14  Brent Fulgham  <bfulgham@apple.com>
+
+        Correct handling of changing input type
+        https://bugs.webkit.org/show_bug.cgi?id=164759
+        <rdar://problem/29211174>
+
+        Reviewed by Darin Adler.
+
+        Test: fast/forms/search-cancel-button-change-input.html
+
+        It is possible for JavaScript to change the type property of an input field. WebKit
+        needs to gracefully handle this case.
+
+        Add a type traits specialization so we can properly downcast InputType elements.
+        Use this to only call search functions on actual search input types.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::onSearch): Only perform search functions if the
+        input type is actually a search field.
+        * html/InputType.h: Add type traits specialization for 'downcast' template.
+        * html/SearchInputType.h: Ditto.
+
 2016-11-15  Zalan Bujtas  <zalan@apple.com>
 
         CounterNode::insertAfter and ::removeChild should take references.
index b86e737..f6e786c 100644 (file)
@@ -5834,7 +5834,6 @@ __ZN7WebCore17MarkupAccumulator17appendStartMarkupERN3WTF13StringBuilderEPKNS_4N
 __ZN7WebCore17MarkupAccumulator13appendElementERN3WTF13StringBuilderEPNS_7ElementEPNS1_7HashMapIPNS1_16AtomicStringImplES8_NS1_7PtrHashIS8_EENS1_10HashTraitsIS8_EESC_EE
 __ZN7WebCore17MarkupAccumulator13appendOpenTagERN3WTF13StringBuilderEPNS_7ElementEPNS1_7HashMapIPNS1_16AtomicStringImplES8_NS1_7PtrHashIS8_EENS1_10HashTraitsIS8_EESC_EE
 __ZNK7WebCore7Element22nodeNamePreservingCaseEv
-__ZNK7WebCore13QualifiedName8toStringEv
 __ZNK7WebCore7Element13hasAttributesEv
 __ZN7WebCore17MarkupAccumulator22appendCustomAttributesERN3WTF13StringBuilderEPNS_7ElementEPNS1_7HashMapIPNS1_16AtomicStringImplES8_NS1_7PtrHashIS8_EENS1_10HashTraitsIS8_EESC_EE
 __ZN7WebCore17MarkupAccumulator14appendCloseTagERN3WTF13StringBuilderEPNS_7ElementE
index f7ad668..7a10f7d 100644 (file)
@@ -1459,9 +1459,13 @@ void HTMLInputElement::addSearchResult()
 
 void HTMLInputElement::onSearch()
 {
-    ASSERT(isSearchField());
+    // The type of the input element could have changed during event handling. If we are no longer
+    // a search field, don't try to do search things.
+    if (!isSearchField())
+        return;
+
     if (m_inputType)
-        static_cast<SearchInputType*>(m_inputType.get())->stopSearchEventTimer();
+        downcast<SearchInputType>(*m_inputType.get()).stopSearchEventTimer();
     dispatchEvent(Event::create(eventNames().searchEvent, true, false));
 }
 
index 6dec731..fc30519 100644 (file)
@@ -322,3 +322,8 @@ private:
 };
 
 } // namespace WebCore
+
+#define SPECIALIZE_TYPE_TRAITS_INPUT_TYPE(ToValueTypeName, predicate) \
+SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
+static bool isType(const WebCore::InputType& input) { return input.predicate; } \
+SPECIALIZE_TYPE_TRAITS_END()
index f36d3ce..ed04a40 100644 (file)
@@ -70,3 +70,5 @@ private:
 };
 
 } // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_INPUT_TYPE(SearchInputType, isSearchField())