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

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: Added inputType check in ImeTest 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) {
Changwan Ryu 2017/05/11 22:57:13 This test is not strong enough. You need to actual
AKVT 2017/05/12 13:26:25 Done.
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 EXPECT_EQ(kWebTextInputFlagHaveNextFocusableElement |
1698 kWebTextInputFlagHavePreviousFocusableElement,
1699 text_input_info.flags);
1700 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1701 Element* content_editable1 = document->getElementById("contenteditable1");
1702 EXPECT_EQ(content_editable1, document->FocusedElement());
1703 button1->focus();
1704 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1705 EXPECT_EQ(input1, document->FocusedElement());
1706
1707 Element* anchor1 = document->getElementById("anchor1");
1708 anchor1->focus();
1709 text_input_info = active_input_method_controller->TextInputInfo();
1710 // No Next/Previous element for elements outside form.
1711 EXPECT_EQ(0, text_input_info.flags);
1712 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1713 // Since anchor is not a form control element, next/previous element will
1714 // be null, hence focus will stay same as it is.
1715 EXPECT_EQ(anchor1, document->FocusedElement());
1716 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1717 EXPECT_EQ(anchor1, document->FocusedElement());
1718
1719 // Navigation of elements which is not part of any forms.
1720 Element* text_area3 = document->getElementById("textarea3");
1721 text_area3->focus();
1722 text_input_info = active_input_method_controller->TextInputInfo();
1723 // No Next/Previous element for elements outside form.
1724 EXPECT_EQ(default_text_input_flags, text_input_info.flags);
1725 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1726 // No Next/Previous element to this element because it's not part of any
1727 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1728 EXPECT_EQ(text_area3, document->FocusedElement());
1729 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1730 EXPECT_EQ(text_area3, document->FocusedElement());
1731
1732 // Navigation from an element which is part of a form but not an editable
1733 // element.
1734 Element* button2 = document->getElementById("button2");
1735 button2->focus();
1736 text_input_info = active_input_method_controller->TextInputInfo();
1737 // No Next element for this element, due to last element outside the form.
1738 EXPECT_EQ(kWebTextInputFlagHavePreviousFocusableElement,
1739 text_input_info.flags);
1740 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1741 // No Next element to this element because it's not part of any form.
1742 // Hence focus won't change wrt NEXT.
1743 EXPECT_EQ(button2, document->FocusedElement());
1744 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1745 // Since button is a form control element from form1, ensuring focus is set
1746 // at correct position.
1747 Element* text_area2 = document->getElementById("textarea2");
1748 EXPECT_EQ(text_area2, document->FocusedElement());
1749
1750 Element* content_editable2 = document->getElementById("contenteditable2");
1751 document->SetFocusedElement(
1752 content_editable2,
1753 FocusParams(SelectionBehaviorOnFocus::kNone, kWebFocusTypeNone, nullptr));
1754 text_input_info = active_input_method_controller->TextInputInfo();
1755 // No Next/Previous element for elements outside form.
1756 EXPECT_EQ(0, text_input_info.flags);
1757 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1758 // No Next/Previous element to this element because it's not part of any
1759 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1760 EXPECT_EQ(content_editable2, document->FocusedElement());
1761 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1762 EXPECT_EQ(content_editable2, document->FocusedElement());
1763
1764 // Navigation of elements which is having invalid form attribute and hence
1765 // not part of any forms.
1766 Element* text_area4 = document->getElementById("textarea4");
1767 text_area4->focus();
1768 text_input_info = active_input_method_controller->TextInputInfo();
1769 // No Next/Previous element for elements which is having invalid form
1770 // attribute.
1771 EXPECT_EQ(default_text_input_flags, text_input_info.flags);
1772 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1773 // No Next/Previous element to this element because it's not part of any
1774 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1775 EXPECT_EQ(text_area4, document->FocusedElement());
1776 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1777 EXPECT_EQ(text_area4, document->FocusedElement());
1778
1779 web_view_helper_.Reset();
1780 }
1781
1782 TEST_P(
1783 WebViewTest,
1784 MoveFocusToNextFocusableElementInFormWithNonEditableNonFormControlElements) {
1785 const std::string test_file =
1786 "advance_focus_in_form_with_key_event_listeners.html";
1787 RegisterMockedHttpURLLoad(test_file);
1788 WebViewImpl* web_view =
1789 web_view_helper_.InitializeAndLoad(base_url_ + test_file);
1790 web_view->SetInitialFocus(false);
1791 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
1792 WebInputMethodController* active_input_method_controller =
1793 web_view->MainFrameImpl()
1794 ->FrameWidget()
1795 ->GetActiveWebInputMethodController();
1796 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences;
1797
1798 struct FocusedElement {
1799 const char* element_id;
1800 int text_input_flags;
1801 } focused_elements[] = {
1802 {"textarea5",
1803 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement},
1804 {"input4", default_text_input_flags |
1805 kWebTextInputFlagHaveNextFocusableElement |
1806 kWebTextInputFlagHavePreviousFocusableElement},
1807 {"contenteditable3", kWebTextInputFlagHavePreviousFocusableElement},
1808 };
1809
1810 // Forward Navigation in form2 with NEXT
1811 Element* text_area5 = document->getElementById("textarea5");
1812 text_area5->focus();
1813 Element* current_focus = nullptr;
1814 WebTextInputInfo text_input_info;
1815 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) {
1816 current_focus = document->getElementById(focused_elements[i].element_id);
1817 EXPECT_EQ(current_focus, document->FocusedElement());
1818 text_input_info = active_input_method_controller->TextInputInfo();
1819 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1820 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1821 }
1822 // Now focus will stay on previous focus itself, because it has no next
1823 // element.
1824 EXPECT_EQ(current_focus, document->FocusedElement());
1825
1826 // Backward Navigation in form1 with PREVIOUS
1827 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) {
1828 current_focus = document->getElementById(focused_elements[i].element_id);
1829 EXPECT_EQ(current_focus, document->FocusedElement());
1830 text_input_info = active_input_method_controller->TextInputInfo();
1831 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1832 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1833 }
1834 // Now focus will stay on previous focus itself, because it has no previous
1835 // element.
1836 EXPECT_EQ(current_focus, document->FocusedElement());
1837
1838 // Setting a non editable element as focus in form1, and ensuring editable
1839 // navigation is fine in forward and backward.
1840 Element* anchor2 = document->getElementById("anchor2");
1841 anchor2->focus();
1842 text_input_info = active_input_method_controller->TextInputInfo();
1843 // No Next/Previous element for elements outside form.
1844 EXPECT_EQ(0, text_input_info.flags);
1845 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1846 // No editable element after this inside the form, hence focus won't change.
1847 EXPECT_EQ(anchor2, document->FocusedElement());
1848 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1849 // Since anchor is not a form control element, next/previous element will
1850 // be null, hence focus will stay same as it is.
1851 EXPECT_EQ(anchor2, document->FocusedElement());
1852
1853 web_view_helper_.Reset();
1854 }
1855
1856 TEST_P(WebViewTest, MoveFocusToNextFocusableElementInFormWithTabIndexElements) {
1857 const std::string test_file =
1858 "advance_focus_in_form_with_tabindex_elements.html";
1859 RegisterMockedHttpURLLoad(test_file);
1860 WebViewImpl* web_view =
1861 web_view_helper_.InitializeAndLoad(base_url_ + test_file);
1862 web_view->SetInitialFocus(false);
1863 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
1864 WebInputMethodController* active_input_method_controller =
1865 web_view->MainFrameImpl()
1866 ->FrameWidget()
1867 ->GetActiveWebInputMethodController();
1868 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences;
1869
1870 struct FocusedElement {
1871 const char* element_id;
1872 int text_input_flags;
1873 } focused_elements[] = {
1874 {"textarea6",
1875 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement},
1876 {"input5", default_text_input_flags |
1877 kWebTextInputFlagHaveNextFocusableElement |
1878 kWebTextInputFlagHavePreviousFocusableElement},
1879 {"contenteditable4", kWebTextInputFlagHaveNextFocusableElement |
1880 kWebTextInputFlagHavePreviousFocusableElement},
1881 {"input6", default_text_input_flags |
1882 kWebTextInputFlagHavePreviousFocusableElement},
1883 };
1884
1885 // Forward Navigation in form with NEXT which has tabindex attribute
1886 // which differs visual order.
1887 Element* text_area6 = document->getElementById("textarea6");
1888 text_area6->focus();
1889 Element* current_focus = nullptr;
1890 WebTextInputInfo text_input_info;
1891 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) {
1892 current_focus = document->getElementById(focused_elements[i].element_id);
1893 EXPECT_EQ(current_focus, document->FocusedElement());
1894 text_input_info = active_input_method_controller->TextInputInfo();
1895 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1896 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1897 }
1898 // No next editable element which is focusable with proper tab index, hence
1899 // staying on previous focus.
1900 EXPECT_EQ(current_focus, document->FocusedElement());
1901
1902 // Backward Navigation in form with PREVIOUS which has tabindex attribute
1903 // which differs visual order.
1904 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) {
1905 current_focus = document->getElementById(focused_elements[i].element_id);
1906 EXPECT_EQ(current_focus, document->FocusedElement());
1907 text_input_info = active_input_method_controller->TextInputInfo();
1908 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1909 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1910 }
1911 // Now focus will stay on previous focus itself, because it has no previous
1912 // element.
1913 EXPECT_EQ(current_focus, document->FocusedElement());
1914
1915 // Setting an element which has invalid tabindex and ensuring it is not
1916 // modifying further navigation.
1917 Element* content_editable5 = document->getElementById("contenteditable5");
1918 content_editable5->focus();
1919 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1920 Element* input6 = document->getElementById("input6");
1921 EXPECT_EQ(input6, document->FocusedElement());
1922 content_editable5->focus();
1923 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1924 EXPECT_EQ(text_area6, document->FocusedElement());
1925
1926 web_view_helper_.Reset();
1927 }
1928
1929 TEST_P(WebViewTest,
1930 MoveFocusToNextFocusableElementInFormWithDisabledAndReadonlyElements) {
1931 const std::string test_file =
1932 "advance_focus_in_form_with_disabled_and_readonly_elements.html";
1933 RegisterMockedHttpURLLoad(test_file);
1934 WebViewImpl* web_view =
1935 web_view_helper_.InitializeAndLoad(base_url_ + test_file);
1936 web_view->SetInitialFocus(false);
1937 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument();
1938 WebInputMethodController* active_input_method_controller =
1939 web_view->MainFrameImpl()
1940 ->FrameWidget()
1941 ->GetActiveWebInputMethodController();
1942
1943 struct FocusedElement {
1944 const char* element_id;
1945 int text_input_flags;
1946 } focused_elements[] = {
1947 {"contenteditable6", kWebTextInputFlagHaveNextFocusableElement},
1948 {"contenteditable7", kWebTextInputFlagHavePreviousFocusableElement},
1949 };
1950 // Forward Navigation in form with NEXT which has has disabled/enabled
1951 // elements which will gets skipped during navigation.
1952 Element* content_editable6 = document->getElementById("contenteditable6");
1953 content_editable6->focus();
1954 Element* current_focus = nullptr;
1955 WebTextInputInfo text_input_info;
1956 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) {
1957 current_focus = document->getElementById(focused_elements[i].element_id);
1958 EXPECT_EQ(current_focus, document->FocusedElement());
1959 text_input_info = active_input_method_controller->TextInputInfo();
1960 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1961 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward);
1962 }
1963 // No next editable element which is focusable, hence staying on previous
1964 // focus.
1965 EXPECT_EQ(current_focus, document->FocusedElement());
1966
1967 // Backward Navigation in form with PREVIOUS which has has
1968 // disabled/enabled elements which will gets skipped during navigation.
1969 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) {
1970 current_focus = document->getElementById(focused_elements[i].element_id);
1971 EXPECT_EQ(current_focus, document->FocusedElement());
1972 text_input_info = active_input_method_controller->TextInputInfo();
1973 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags);
1974 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward);
1975 }
1976 // Now focus will stay on previous focus itself, because it has no previous
1977 // element.
1978 EXPECT_EQ(current_focus, document->FocusedElement());
1979
1980 web_view_helper_.Reset();
1981 }
1982
1627 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) { 1983 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) {
1628 RegisterMockedHttpURLLoad("200-by-300.html"); 1984 RegisterMockedHttpURLLoad("200-by-300.html");
1629 WebViewImpl* web_view_impl = 1985 WebViewImpl* web_view_impl =
1630 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html"); 1986 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html");
1631 web_view_impl->Resize(WebSize(200, 300)); 1987 web_view_impl->Resize(WebSize(200, 300));
1632 1988
1633 float page_scale_expected = web_view_impl->PageScaleFactor(); 1989 float page_scale_expected = web_view_impl->PageScaleFactor();
1634 1990
1635 WebDeviceEmulationParams params; 1991 WebDeviceEmulationParams params;
1636 params.screen_position = WebDeviceEmulationParams::kDesktop; 1992 params.screen_position = WebDeviceEmulationParams::kDesktop;
(...skipping 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after
4344 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars()); 4700 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars());
4345 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 4701 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
4346 EXPECT_NE(nullptr, 4702 EXPECT_NE(nullptr,
4347 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar()); 4703 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar());
4348 } else { 4704 } else {
4349 EXPECT_NE(nullptr, frame_view->VerticalScrollbar()); 4705 EXPECT_NE(nullptr, frame_view->VerticalScrollbar());
4350 } 4706 }
4351 } 4707 }
4352 4708
4353 } // namespace blink 4709 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698