Index: third_party/WebKit/Source/web/tests/WebFrameTest.cpp |
diff --git a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp |
index a9b73309056902de3f12819f47739c725b990ebf..a4a760a5a0b6d70e1866d274819e7d07fa34e0ad 100644 |
--- a/third_party/WebKit/Source/web/tests/WebFrameTest.cpp |
+++ b/third_party/WebKit/Source/web/tests/WebFrameTest.cpp |
@@ -4237,6 +4237,52 @@ TEST_P(ParameterizedWebFrameTest, ClearFocusedNodeTest) { |
EXPECT_EQ(0, webViewHelper.webView()->focusedElement()); |
} |
+class ChangedSelectionCounter : public FrameTestHelpers::TestWebFrameClient { |
+ public: |
+ ChangedSelectionCounter() : m_callCount(0) {} |
+ void didChangeSelection(bool isSelectionEmpty) { m_callCount++; } |
yosin_UTC9
2017/02/09 13:02:17
nit: It is OK to use post-increment, but I prefer
|
+ int count() const { return m_callCount; } |
+ void reset() { m_callCount = 0; } |
+ |
+ private: |
+ int m_callCount; |
+}; |
+ |
+TEST_P(ParameterizedWebFrameTest, OneFocusChangeMeansOneSelectionChange) { |
+ ChangedSelectionCounter counter; |
+ FrameTestHelpers::WebViewHelper webViewHelper; |
+ registerMockedHttpURLLoad("editable_elements.html"); |
+ webViewHelper.initializeAndLoad(m_baseURL + "editable_elements.html", true, |
+ &counter); |
+ |
+ WebLocalFrameImpl* frame = webViewHelper.webView()->mainFrameImpl(); |
+ Document* document = frame->frame()->document(); |
+ |
+ // Move to a text-field. |
+ Element* firstField = document->getElementById("input1"); |
+ counter.reset(); |
+ firstField->focus(); |
+ EXPECT_EQ(1, counter.count()); |
+ |
+ // Move to another text-field. |
+ Element* secondField = document->getElementById("input2"); |
+ counter.reset(); |
+ secondField->focus(); |
+ EXPECT_EQ(1, counter.count()); |
+ |
+ // Move to a number-field. |
+ Element* numberField = document->getElementById("input3"); |
+ counter.reset(); |
+ numberField->focus(); |
+ EXPECT_EQ(1, counter.count()); |
+ |
+ // Move to an editable element. |
+ Element* editableP = document->getElementById("p1"); |
+ counter.reset(); |
+ editableP->focus(); |
+ EXPECT_EQ(1, counter.count()); |
+} |
+ |
// Implementation of WebFrameClient that tracks the v8 contexts that are created |
// and destroyed for verification. |
class ContextLifetimeTestWebFrameClient |