Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2056)

Unified Diff: third_party/WebKit/Source/web/tests/WebFrameTest.cpp

Issue 2616623002: Do not send redundant selectionchange-events (decouple focus) (Closed)
Patch Set: Fix spatnav tests (clear selection when focus goes to non editable element). Remove now invalid keeā€¦ Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698