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

Unified Diff: Source/web/tests/WebViewTest.cpp

Issue 939603002: Adding support for Smart GO NEXT feature in Android Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Made all test case as deterministic with EXPECT_EQ Created 5 years, 4 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: Source/web/tests/WebViewTest.cpp
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp
index 79f771b8c0a88d38d292a956dd8528edc921014c..b7c498c7d2200446c6277b95445dc5d9831535c6 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -3029,4 +3029,302 @@ TEST_F(WebViewTest, TestRecordFrameTimingEvents)
}
}
+TEST_F(WebViewTest, MoveFocusToNextFocusableElementInFormWithKeyEventListenersAndNonEditableElements)
+{
+ const std::string testFile = "advance_focus_in_form_with_key_event_listeners.html";
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(testFile.c_str()));
+ WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFile, true, 0);
tkent 2015/08/07 01:40:58 The last argument should be |nullptr|, or you can
AKV 2015/08/08 09:25:02 Done.
+ webViewImpl->setInitialFocus(false);
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
+ HTMLDocument* document = toHTMLDocument(frame->frame()->document());
+ const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
+
+ // Forward Navigation in form1 with NEXT
+ Element* input1 = document->getElementById("input1");
+ input1->focus();
+ WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* button1 = document->getElementById("button1");
+ EXPECT_NE(button1, document->focusedElement());
+
+ Element* contenteditable1 = document->getElementById("contenteditable1");
tkent 2015/08/07 01:40:58 Repeating similar code is not fun. How about maki
AKV 2015/08/07 06:56:53 @tkent - Could you provide little more details abo
tkent 2015/08/07 07:05:48 Something like: for (int i = 0; i < WTF_ARRAY_LEN
AKV 2015/08/08 09:25:03 @tkent - Thanks for the quick response. I have tak
+ EXPECT_EQ(contenteditable1, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* input2 = document->getElementById("input2");
+ EXPECT_EQ(input2, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement | WebTextInputFlagListeningToKeyboardEvents, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* anchor1 = document->getElementById("anchor1");
+ EXPECT_NE(anchor1, document->focusedElement());
+
+ Element* textarea1 = document->getElementById("textarea1");
+ EXPECT_EQ(textarea1, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* input3 = document->getElementById("input3");
+ EXPECT_EQ(input3, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* textarea2 = document->getElementById("textarea2");
+ EXPECT_EQ(textarea2, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // No next element, hence focus will stay on same element.
+ EXPECT_EQ(textarea2, document->focusedElement());
+
+ // Backward Navigation in form1 with PREVIOUS
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(input3, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(textarea1, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(input2, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(contenteditable1, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(input1, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ // No previous element, hence focus will stay on same element.
+ EXPECT_EQ(input1, document->focusedElement());
+
+ // Setting a non editable element as focus in form1, and ensuring editable navigation is fine in forward and backward.
tkent 2015/08/07 01:40:58 nit: I recommend to wrap code comments in 80 colum
AKV 2015/08/08 09:25:03 Done.
+ button1->focus();
+ textInputInfo = webViewImpl->textInputInfo();
+ // No Next/Previous element for elements outside form.
+ EXPECT_EQ(0, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ EXPECT_EQ(contenteditable1, document->focusedElement());
+ button1->focus();
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(input1, document->focusedElement());
+
+ anchor1->focus();
+ textInputInfo = webViewImpl->textInputInfo();
+ // No Next/Previous element for elements outside form.
+ EXPECT_EQ(0, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // Since anchor is not a form control element, next/previous element will be null, hence focus will stay same as it is.
+ EXPECT_EQ(anchor1, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(anchor1, document->focusedElement());
+
+ // Navigation of elements which is not part of any forms.
+ Element* textarea3 = document->getElementById("textarea3");
+ textarea3->focus();
+ textInputInfo = webViewImpl->textInputInfo();
+ // No Next/Previous element for elements outside form.
+ EXPECT_EQ(defaultTextInputFlags, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // No Next/Previous element to this element because it's not part of any form. Hence focus won't change wrt NEXT/PREVIOUS.
+ EXPECT_EQ(textarea3, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(textarea3, document->focusedElement());
+
+ // Navigation from an element which is part of a form but not an editable element.
+ Element* button2 = document->getElementById("button2");
+ button2->focus();
+ textInputInfo = webViewImpl->textInputInfo();
+ // No Next element for this element, due to last element outside the form.
+ EXPECT_EQ(0, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // No Next element to this element because it's not part of any form. Hence focus won't change wrt NEXT.
+ EXPECT_EQ(button2, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ // Since button is a form control element from form1, ensuring focus is set at correct position.
+ EXPECT_EQ(textarea2, document->focusedElement());
+
+ Element* contenteditable2 = document->getElementById("contenteditable2");
+ document->setFocusedElement(contenteditable2);
+ textInputInfo = webViewImpl->textInputInfo();
+ // No Next/Previous element for elements outside form.
+ EXPECT_EQ(0, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // No Next/Previous element to this element because it's not part of any form. Hence focus won't change wrt NEXT/PREVIOUS.
+ EXPECT_EQ(contenteditable2, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(contenteditable2, document->focusedElement());
+
+ // Navigation of elements which is having invalid form attribute and hence not part of any forms.
+ Element* textarea4 = document->getElementById("textarea4");
+ textarea4->focus();
+ textInputInfo = webViewImpl->textInputInfo();
+ // No Next/Previous element for elements which is having invalid form attribute.
+ EXPECT_EQ(defaultTextInputFlags, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // No Next/Previous element to this element because it's not part of any form. Hence focus won't change wrt NEXT/PREVIOUS.
+ EXPECT_EQ(textarea4, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(textarea4, document->focusedElement());
+
+ m_webViewHelper.reset();
+}
+
+TEST_F(WebViewTest, MoveFocusToNextFocusableElementInFormWithNonEditableNonFormControlElements)
+{
+ const std::string testFile = "advance_focus_in_form_with_key_event_listeners.html";
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(testFile.c_str()));
+ WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFile, true, 0);
tkent 2015/08/07 01:40:58 0 should be nullptr or omitted.
AKV 2015/08/08 09:25:03 Done.
+ webViewImpl->setInitialFocus(false);
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
+ HTMLDocument* document = toHTMLDocument(frame->frame()->document());
+ const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
+
+ // Forward Navigation in form2 with NEXT
+ Element* textarea5 = document->getElementById("textarea5");
+ textarea5->focus();
+ WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* input4 = document->getElementById("input4");
+ EXPECT_EQ(input4, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* contenteditable3 = document->getElementById("contenteditable3");
+ EXPECT_EQ(contenteditable3, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ // Anchor is not an editable navigation element, hence skipping in traversal.
+ Element* anchor2 = document->getElementById("anchor2");
+ EXPECT_NE(anchor2, document->focusedElement());
+ // No next element, hence focus will stay on same element.
+ EXPECT_EQ(contenteditable3, document->focusedElement());
+
+ // Backward Navigation in form2 with PREVIOUS
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(input4, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(textarea5, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ // No previous element, hence focus will stay on same element.
+ EXPECT_EQ(textarea5, document->focusedElement());
+
+ // Setting a non editable element as focus in form1, and ensuring editable navigation is fine in forward and backward.
+ anchor2->focus();
+ textInputInfo = webViewImpl->textInputInfo();
+ // No Next/Previous element for elements outside form.
+ EXPECT_EQ(0, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // No editable element after this inside the form, hence focus won't change.
+ EXPECT_EQ(anchor2, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ // Since anchor is not a form control element, next/previous element will be null, hence focus will stay same as it is.
+ EXPECT_EQ(anchor2, document->focusedElement());
+
+ m_webViewHelper.reset();
+}
+
+TEST_F(WebViewTest, MoveFocusToNextFocusableElementInFormWithTabIndexElements)
+{
+ const std::string testFile = "advance_focus_in_form_with_tabindex_elements.html";
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(testFile.c_str()));
+ WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFile, true, 0);
tkent 2015/08/07 01:40:58 0 should be nullptr or omitted.
AKV 2015/08/08 09:25:03 Done.
+ webViewImpl->setInitialFocus(false);
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
+ HTMLDocument* document = toHTMLDocument(frame->frame()->document());
+ const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
+
+ // Forward Navigation in form3 with NEXT which has tabindex attribute which differs visual order.
+ Element* textarea6 = document->getElementById("textarea6");
+ textarea6->focus();
+ WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* input5 = document->getElementById("input5");
+ EXPECT_EQ(input5, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* contenteditable4 = document->getElementById("contenteditable4");
+ EXPECT_EQ(contenteditable4, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* input6 = document->getElementById("input6");
+ EXPECT_EQ(input6, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* contenteditable5 = document->getElementById("contenteditable5");
+ EXPECT_NE(contenteditable5, document->focusedElement());
+ // No next editable element which is focusable with proper tab index, hence staying on previous focus.
+ EXPECT_EQ(input6, document->focusedElement());
+
+ // Backward Navigation in form3 with PREVIOUS which has tabindex attribute which differs visual order.
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(contenteditable4, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(input5, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(textarea6, document->focusedElement());
+
+ // Setting an element which has invalid tabindex and ensuring it is not modifying further navigation.
+ contenteditable5->focus();
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ EXPECT_EQ(input6, document->focusedElement());
+ contenteditable5->focus();
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ EXPECT_EQ(textarea6, document->focusedElement());
+
+ m_webViewHelper.reset();
+}
+
+TEST_F(WebViewTest, MoveFocusToNextFocusableElementInFormWithDisabledAndReadonlyElements)
+{
+ const std::string testFile = "advance_focus_in_form_with_disabled_and_readonly_elements.html";
+ URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c_str()), WebString::fromUTF8(testFile.c_str()));
+ WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFile, true, 0);
+ webViewImpl->setInitialFocus(false);
+ WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
+ HTMLDocument* document = toHTMLDocument(frame->frame()->document());
+
+ // Forward Navigation in form4 with NEXT which has has disabled/enabled elements which will gets skipped during navigation.
+ Element* contenteditable6 = document->getElementById("contenteditable6");
+ contenteditable6->focus();
+ WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+
+ Element* input7 = document->getElementById("input7");
+ EXPECT_NE(input7, document->focusedElement());
+ Element* contenteditable7 = document->getElementById("contenteditable7");
+ EXPECT_EQ(contenteditable7, document->focusedElement());
+ textInputInfo = webViewImpl->textInputInfo();
+ EXPECT_EQ(WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
+ webViewImpl->advanceFocusInForm(WebFocusTypeForward);
+ // No more elements present further in the form in forward direction, so focus won't change.
+ EXPECT_EQ(contenteditable7, document->focusedElement());
+
+ // Backward Navigation in form4 with PREVIOUS which has has disabled/enabled elements which will gets skipped during navigation.
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ Element* textarea7 = document->getElementById("textarea7");
+ EXPECT_NE(textarea7, document->focusedElement());
+ EXPECT_EQ(contenteditable6, document->focusedElement());
+ webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
+ // No more elements present further in the form in backward direction, so focus won't change.
+ EXPECT_EQ(contenteditable6, document->focusedElement());
+
+ m_webViewHelper.reset();
+}
+
} // namespace blink
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/advance_focus_in_form_with_disabled_and_readonly_elements.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698