Chromium Code Reviews| Index: Source/web/tests/WebViewTest.cpp |
| diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp |
| index 57f1518362aead8102f356cf26af1845aa0e1af0..bb69e0cd0b881a4f86b9591f4d8206e7d6358f1c 100644 |
| --- a/Source/web/tests/WebViewTest.cpp |
| +++ b/Source/web/tests/WebViewTest.cpp |
| @@ -3029,4 +3029,136 @@ TEST_F(WebViewTest, TestRecordFrameTimingEvents) |
| } |
| } |
| +TEST_F(WebViewTest, MoveFocusToNextFocusableElementInForm) |
| +{ |
| + const std::string testFile = "advance_focus_in_form.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()); |
| + 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* contenteditable1 = document->getElementById("contenteditable1"); |
| + 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* 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()); |
| + |
| + // Navigation of elements which is not part of any forms. |
| + Element* contenteditable2 = document->getElementById("contenteditable2"); |
| + document->setFocusedElement(contenteditable2); |
| + textInputInfo = webViewImpl->textInputInfo(); |
| + // No Next/Previous element for elements outside form. |
| + EXPECT_NE(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, 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/PREVIOS. |
|
kochi
2015/07/28 08:43:02
nit: s/PREVIOS/PREVIOUS/
AKV
2015/08/05 08:55:55
Done.
|
| + EXPECT_EQ(contenteditable2, document->focusedElement()); |
| + webViewImpl->advanceFocusInForm(WebFocusTypeBackward); |
| + EXPECT_EQ(contenteditable2, document->focusedElement()); |
| + |
| + Element* textarea3 = document->getElementById("textarea3"); |
| + textarea3->focus(); |
| + textInputInfo = webViewImpl->textInputInfo(); |
| + // No Next/Previous element for elements outside form. |
| + EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, 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/PREVIOS. |
|
kochi
2015/07/28 08:43:02
nit: s/PREVIOS/PREVIOUS/
AKV
2015/08/05 08:55:55
Done.
|
| + EXPECT_EQ(textarea3, document->focusedElement()); |
| + webViewImpl->advanceFocusInForm(WebFocusTypeBackward); |
| + EXPECT_EQ(textarea3, 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 outside form. |
| + EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, 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/PREVIOS. |
|
kochi
2015/07/28 08:43:03
nit: s/PREVIOS/PREVIOUS/
AKV
2015/08/05 08:55:55
Done.
|
| + EXPECT_EQ(textarea4, document->focusedElement()); |
| + webViewImpl->advanceFocusInForm(WebFocusTypeBackward); |
| + EXPECT_EQ(textarea4, document->focusedElement()); |
| + |
| + // Forward Navigation in form2 with NEXT |
| + Element* textarea5 = document->getElementById("textarea5"); |
| + textarea5->focus(); |
| + 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); |
| + // 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()); |
| + |
| + m_webViewHelper.reset(); |
| +} |
| + |
| } // namespace blink |