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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebViewTest.cpp

Issue 2839993002: [Android] Adding Smart GO/NEXT feature in Chrome (Closed)
Patch Set: Moved the Focus movement logic from IMC to FocusController and addressed other review comments. Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 web_view->SetInitialFocus(false); 1617 web_view->SetInitialFocus(false);
1618 frame->SetEditableSelectionOffsets(4, 10); 1618 frame->SetEditableSelectionOffsets(4, 10);
1619 EXPECT_TRUE(web_view->IsSelectionAnchorFirst()); 1619 EXPECT_TRUE(web_view->IsSelectionAnchorFirst());
1620 WebRect anchor; 1620 WebRect anchor;
1621 WebRect focus; 1621 WebRect focus;
1622 web_view->SelectionBounds(anchor, focus); 1622 web_view->SelectionBounds(anchor, focus);
1623 frame->SelectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)); 1623 frame->SelectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y));
1624 EXPECT_FALSE(web_view->IsSelectionAnchorFirst()); 1624 EXPECT_FALSE(web_view->IsSelectionAnchorFirst());
1625 } 1625 }
1626 1626
1627 TEST_P(
1628 WebViewTest,
1629 MoveFocusToNextFocusableElementInFormWithKeyEventListenersAndNonEditableElem ents) {
1630 const std::string test_file =
1631 "advance_focus_in_form_with_key_event_listeners.html";
1632 RegisterMockedHttpURLLoad(test_file);
1633 WebViewImpl* web_view =
1634 web_view_helper_.InitializeAndLoad(base_url_ + test_file);
1635 web_view->SetInitialFocus(false);
1636 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
1637 WebInputMethodController* active_input_method_controller =
1638 web_view->MainFrameImpl()
1639 ->FrameWidget()
1640 ->GetActiveWebInputMethodController();
1641 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences;
1642
1643 struct FocusedElement {
1644 const char* element_id;
1645 int text_input_flags;
1646 } focused_elements[] = {
1647 {"input1",
1648 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement},
1649 {"contenteditable1", kWebTextInputFlagHaveNextFocusableElement |
1650 kWebTextInputFlagHavePreviousFocusableElement},
1651 {"input2", default_text_input_flags |
1652 kWebTextInputFlagHaveNextFocusableElement |
1653 kWebTextInputFlagHavePreviousFocusableElement},
1654 {"textarea1", default_text_input_flags |
1655 kWebTextInputFlagHaveNextFocusableElement |
1656 kWebTextInputFlagHavePreviousFocusableElement},
1657 {"input3", default_text_input_flags |
1658 kWebTextInputFlagHaveNextFocusableElement |
1659 kWebTextInputFlagHavePreviousFocusableElement},
1660 {"textarea2", default_text_input_flags |
1661 kWebTextInputFlagHavePreviousFocusableElement},
1662 };
1663
1664 // Forward Navigation in form1 with NEXT
1665 Element* input1 = document->getElementById("input1");
1666 input1->focus();
1667 Element* current_focus = nullptr;
1668 WebTextInputInfo text_input_info;
1669 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) {
1670 current_focus = document->getElementById(focused_elements[i].element_id);
1671 EXPECT_EQ(current_focus, document->FocusedElement());
1672 text_input_info = active_input_method_controller->TextInputInfo();
1673 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1674 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1675 }
1676 // Now focus will stay on previous focus itself, because it has no next
1677 // element.
1678 EXPECT_EQ(current_focus, document->FocusedElement());
1679
1680 // Backward Navigation in form1 with PREVIOUS
1681 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) {
1682 current_focus = document->getElementById(focused_elements[i].element_id);
1683 EXPECT_EQ(current_focus, document->FocusedElement());
1684 text_input_info = active_input_method_controller->TextInputInfo();
1685 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1686 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1687 }
1688 // Now focus will stay on previous focus itself, because it has no previous
1689 // element.
1690 EXPECT_EQ(current_focus, document->FocusedElement());
1691
1692 // Setting a non editable element as focus in form1, and ensuring editable
1693 // navigation is fine in forward and backward.
1694 Element* button1 = document->getElementById("button1");
1695 button1->focus();
1696 text_input_info = active_input_method_controller->TextInputInfo();
1697 // No Next/Previous element for elements outside form.
1698 EXPECT_EQ(0, text_input_info.flags);
1699 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1700 Element* content_editable1 = document->getElementById("contenteditable1");
1701 EXPECT_EQ(content_editable1, document->FocusedElement());
1702 button1->focus();
1703 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1704 EXPECT_EQ(input1, document->FocusedElement());
1705
1706 Element* anchor1 = document->getElementById("anchor1");
1707 anchor1->focus();
1708 text_input_info = active_input_method_controller->TextInputInfo();
1709 // No Next/Previous element for elements outside form.
1710 EXPECT_EQ(0, text_input_info.flags);
1711 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1712 // Since anchor is not a form control element, next/previous element will
1713 // be null, hence focus will stay same as it is.
1714 EXPECT_EQ(anchor1, document->FocusedElement());
1715 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1716 EXPECT_EQ(anchor1, document->FocusedElement());
1717
1718 // Navigation of elements which is not part of any forms.
1719 Element* text_area3 = document->getElementById("textarea3");
1720 text_area3->focus();
1721 text_input_info = active_input_method_controller->TextInputInfo();
1722 // No Next/Previous element for elements outside form.
1723 EXPECT_EQ(default_text_input_flags, text_input_info.flags);
1724 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1725 // No Next/Previous element to this element because it's not part of any
1726 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1727 EXPECT_EQ(text_area3, document->FocusedElement());
1728 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1729 EXPECT_EQ(text_area3, document->FocusedElement());
1730
1731 // Navigation from an element which is part of a form but not an editable
1732 // element.
1733 Element* button2 = document->getElementById("button2");
1734 button2->focus();
1735 text_input_info = active_input_method_controller->TextInputInfo();
1736 // No Next element for this element, due to last element outside the form.
1737 EXPECT_EQ(0, text_input_info.flags);
1738 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1739 // No Next element to this element because it's not part of any form.
1740 // Hence focus won't change wrt NEXT.
1741 EXPECT_EQ(button2, document->FocusedElement());
1742 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1743 // Since button is a form control element from form1, ensuring focus is set
1744 // at correct position.
1745 Element* text_area2 = document->getElementById("textarea2");
1746 EXPECT_EQ(text_area2, document->FocusedElement());
1747
1748 Element* content_editable2 = document->getElementById("contenteditable2");
1749 document->SetFocusedElement(
1750 content_editable2,
1751 FocusParams(SelectionBehaviorOnFocus::kNone, kWebFocusTypeNone, nullptr));
1752 text_input_info = active_input_method_controller->TextInputInfo();
1753 // No Next/Previous element for elements outside form.
1754 EXPECT_EQ(0, text_input_info.flags);
1755 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1756 // No Next/Previous element to this element because it's not part of any
1757 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1758 EXPECT_EQ(content_editable2, document->FocusedElement());
1759 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1760 EXPECT_EQ(content_editable2, document->FocusedElement());
1761
1762 // Navigation of elements which is having invalid form attribute and hence
1763 // not part of any forms.
1764 Element* text_area4 = document->getElementById("textarea4");
1765 text_area4->focus();
1766 text_input_info = active_input_method_controller->TextInputInfo();
1767 // No Next/Previous element for elements which is having invalid form
1768 // attribute.
1769 EXPECT_EQ(default_text_input_flags, text_input_info.flags);
1770 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1771 // No Next/Previous element to this element because it's not part of any
1772 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1773 EXPECT_EQ(text_area4, document->FocusedElement());
1774 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1775 EXPECT_EQ(text_area4, document->FocusedElement());
1776
1777 web_view_helper_.Reset();
1778 }
1779
1780 TEST_P(
1781 WebViewTest,
1782 MoveFocusToNextFocusableElementInFormWithNonEditableNonFormControlElements) {
1783 const std::string test_file =
1784 "advance_focus_in_form_with_key_event_listeners.html";
1785 RegisterMockedHttpURLLoad(test_file);
1786 WebViewImpl* web_view =
1787 web_view_helper_.InitializeAndLoad(base_url_ + test_file);
1788 web_view->SetInitialFocus(false);
1789 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
1790 WebInputMethodController* active_input_method_controller =
1791 web_view->MainFrameImpl()
1792 ->FrameWidget()
1793 ->GetActiveWebInputMethodController();
1794 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences;
1795
1796 struct FocusedElement {
1797 const char* element_id;
1798 int text_input_flags;
1799 } focused_elements[] = {
1800 {"textarea5",
1801 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement},
1802 {"input4", default_text_input_flags |
1803 kWebTextInputFlagHaveNextFocusableElement |
1804 kWebTextInputFlagHavePreviousFocusableElement},
1805 {"contenteditable3", kWebTextInputFlagHavePreviousFocusableElement},
1806 };
1807
1808 // Forward Navigation in form2 with NEXT
1809 Element* text_area5 = document->getElementById("textarea5");
1810 text_area5->focus();
1811 Element* current_focus = nullptr;
1812 WebTextInputInfo text_input_info;
1813 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) {
1814 current_focus = document->getElementById(focused_elements[i].element_id);
1815 EXPECT_EQ(current_focus, document->FocusedElement());
1816 text_input_info = active_input_method_controller->TextInputInfo();
1817 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1818 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1819 }
1820 // Now focus will stay on previous focus itself, because it has no next
1821 // element.
1822 EXPECT_EQ(current_focus, document->FocusedElement());
1823
1824 // Backward Navigation in form1 with PREVIOUS
1825 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) {
1826 current_focus = document->getElementById(focused_elements[i].element_id);
1827 EXPECT_EQ(current_focus, document->FocusedElement());
1828 text_input_info = active_input_method_controller->TextInputInfo();
1829 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1830 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1831 }
1832 // Now focus will stay on previous focus itself, because it has no previous
1833 // element.
1834 EXPECT_EQ(current_focus, document->FocusedElement());
1835
1836 // Setting a non editable element as focus in form1, and ensuring editable
1837 // navigation is fine in forward and backward.
1838 Element* anchor2 = document->getElementById("anchor2");
1839 anchor2->focus();
1840 text_input_info = active_input_method_controller->TextInputInfo();
1841 // No Next/Previous element for elements outside form.
1842 EXPECT_EQ(0, text_input_info.flags);
1843 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1844 // No editable element after this inside the form, hence focus won't change.
1845 EXPECT_EQ(anchor2, document->FocusedElement());
1846 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1847 // Since anchor is not a form control element, next/previous element will
1848 // be null, hence focus will stay same as it is.
1849 EXPECT_EQ(anchor2, document->FocusedElement());
1850
1851 web_view_helper_.Reset();
1852 }
1853
1854 TEST_P(WebViewTest, MoveFocusToNextFocusableElementInFormWithTabIndexElements) {
1855 const std::string test_file =
1856 "advance_focus_in_form_with_tabindex_elements.html";
1857 RegisterMockedHttpURLLoad(test_file);
1858 WebViewImpl* web_view =
1859 web_view_helper_.InitializeAndLoad(base_url_ + test_file);
1860 web_view->SetInitialFocus(false);
1861 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
1862 WebInputMethodController* active_input_method_controller =
1863 web_view->MainFrameImpl()
1864 ->FrameWidget()
1865 ->GetActiveWebInputMethodController();
1866 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences;
1867
1868 struct FocusedElement {
1869 const char* element_id;
1870 int text_input_flags;
1871 } focused_elements[] = {
1872 {"textarea6",
1873 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement},
1874 {"input5", default_text_input_flags |
1875 kWebTextInputFlagHaveNextFocusableElement |
1876 kWebTextInputFlagHavePreviousFocusableElement},
1877 {"contenteditable4", kWebTextInputFlagHaveNextFocusableElement |
1878 kWebTextInputFlagHavePreviousFocusableElement},
1879 {"input6", default_text_input_flags |
1880 kWebTextInputFlagHavePreviousFocusableElement},
1881 };
1882
1883 // Forward Navigation in form with NEXT which has tabindex attribute
1884 // which differs visual order.
1885 Element* text_area6 = document->getElementById("textarea6");
1886 text_area6->focus();
1887 Element* current_focus = nullptr;
1888 WebTextInputInfo text_input_info;
1889 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) {
1890 current_focus = document->getElementById(focused_elements[i].element_id);
1891 EXPECT_EQ(current_focus, document->FocusedElement());
1892 text_input_info = active_input_method_controller->TextInputInfo();
1893 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1894 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1895 }
1896 // No next editable element which is focusable with proper tab index, hence
1897 // staying on previous focus.
1898 EXPECT_EQ(current_focus, document->FocusedElement());
1899
1900 // Backward Navigation in form with PREVIOUS which has tabindex attribute
1901 // which differs visual order.
1902 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) {
1903 current_focus = document->getElementById(focused_elements[i].element_id);
1904 EXPECT_EQ(current_focus, document->FocusedElement());
1905 text_input_info = active_input_method_controller->TextInputInfo();
1906 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1907 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1908 }
1909 // Now focus will stay on previous focus itself, because it has no previous
1910 // element.
1911 EXPECT_EQ(current_focus, document->FocusedElement());
1912
1913 // Setting an element which has invalid tabindex and ensuring it is not
1914 // modifying further navigation.
1915 Element* content_editable5 = document->getElementById("contenteditable5");
1916 content_editable5->focus();
1917 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1918 Element* input6 = document->getElementById("input6");
1919 EXPECT_EQ(input6, document->FocusedElement());
1920 content_editable5->focus();
1921 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1922 EXPECT_EQ(text_area6, document->FocusedElement());
1923
1924 web_view_helper_.Reset();
1925 }
1926
1927 TEST_P(WebViewTest,
1928 MoveFocusToNextFocusableElementInFormWithDisabledAndReadonlyElements) {
1929 const std::string test_file =
1930 "advance_focus_in_form_with_disabled_and_readonly_elements.html";
1931 RegisterMockedHttpURLLoad(test_file);
1932 WebViewImpl* web_view =
1933 web_view_helper_.InitializeAndLoad(base_url_ + test_file);
1934 web_view->SetInitialFocus(false);
1935 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
1936 WebInputMethodController* active_input_method_controller =
1937 web_view->MainFrameImpl()
1938 ->FrameWidget()
1939 ->GetActiveWebInputMethodController();
1940
1941 struct FocusedElement {
1942 const char* element_id;
1943 int text_input_flags;
1944 } focused_elements[] = {
1945 {"contenteditable6", kWebTextInputFlagHaveNextFocusableElement},
1946 {"contenteditable7", kWebTextInputFlagHavePreviousFocusableElement},
1947 };
1948 // Forward Navigation in form with NEXT which has has disabled/enabled
1949 // elements which will gets skipped during navigation.
1950 Element* content_editable6 = document->getElementById("contenteditable6");
1951 content_editable6->focus();
1952 Element* current_focus = nullptr;
1953 WebTextInputInfo text_input_info;
1954 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) {
1955 current_focus = document->getElementById(focused_elements[i].element_id);
1956 EXPECT_EQ(current_focus, document->FocusedElement());
1957 text_input_info = active_input_method_controller->TextInputInfo();
1958 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1959 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1960 }
1961 // No next editable element which is focusable, hence staying on previous
1962 // focus.
1963 EXPECT_EQ(current_focus, document->FocusedElement());
1964
1965 // Backward Navigation in form with PREVIOUS which has has
1966 // disabled/enabled elements which will gets skipped during navigation.
1967 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) {
1968 current_focus = document->getElementById(focused_elements[i].element_id);
1969 EXPECT_EQ(current_focus, document->FocusedElement());
1970 text_input_info = active_input_method_controller->TextInputInfo();
1971 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1972 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1973 }
1974 // Now focus will stay on previous focus itself, because it has no previous
1975 // element.
1976 EXPECT_EQ(current_focus, document->FocusedElement());
1977
1978 web_view_helper_.Reset();
1979 }
1980
1627 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) { 1981 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) {
1628 RegisterMockedHttpURLLoad("200-by-300.html"); 1982 RegisterMockedHttpURLLoad("200-by-300.html");
1629 WebViewImpl* web_view_impl = 1983 WebViewImpl* web_view_impl =
1630 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html"); 1984 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html");
1631 web_view_impl->Resize(WebSize(200, 300)); 1985 web_view_impl->Resize(WebSize(200, 300));
1632 1986
1633 float page_scale_expected = web_view_impl->PageScaleFactor(); 1987 float page_scale_expected = web_view_impl->PageScaleFactor();
1634 1988
1635 WebDeviceEmulationParams params; 1989 WebDeviceEmulationParams params;
1636 params.screen_position = WebDeviceEmulationParams::kDesktop; 1990 params.screen_position = WebDeviceEmulationParams::kDesktop;
(...skipping 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after
4344 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars()); 4698 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars());
4345 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 4699 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
4346 EXPECT_NE(nullptr, 4700 EXPECT_NE(nullptr,
4347 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar()); 4701 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar());
4348 } else { 4702 } else {
4349 EXPECT_NE(nullptr, frame_view->VerticalScrollbar()); 4703 EXPECT_NE(nullptr, frame_view->VerticalScrollbar());
4350 } 4704 }
4351 } 4705 }
4352 4706
4353 } // namespace blink 4707 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698