OLD | NEW |
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 #include "core/frame/Settings.h" | 52 #include "core/frame/Settings.h" |
53 #include "core/frame/VisualViewport.h" | 53 #include "core/frame/VisualViewport.h" |
54 #include "core/frame/WebLocalFrameBase.h" | 54 #include "core/frame/WebLocalFrameBase.h" |
55 #include "core/html/HTMLIFrameElement.h" | 55 #include "core/html/HTMLIFrameElement.h" |
56 #include "core/html/HTMLInputElement.h" | 56 #include "core/html/HTMLInputElement.h" |
57 #include "core/html/HTMLTextAreaElement.h" | 57 #include "core/html/HTMLTextAreaElement.h" |
58 #include "core/inspector/DevToolsEmulator.h" | 58 #include "core/inspector/DevToolsEmulator.h" |
59 #include "core/layout/api/LayoutViewItem.h" | 59 #include "core/layout/api/LayoutViewItem.h" |
60 #include "core/loader/DocumentLoader.h" | 60 #include "core/loader/DocumentLoader.h" |
61 #include "core/loader/FrameLoadRequest.h" | 61 #include "core/loader/FrameLoadRequest.h" |
| 62 #include "core/page/FocusController.h" |
62 #include "core/page/Page.h" | 63 #include "core/page/Page.h" |
63 #include "core/page/PrintContext.h" | 64 #include "core/page/PrintContext.h" |
64 #include "core/page/ScopedPageSuspender.h" | 65 #include "core/page/ScopedPageSuspender.h" |
65 #include "core/paint/PaintLayer.h" | 66 #include "core/paint/PaintLayer.h" |
66 #include "core/paint/PaintLayerPainter.h" | 67 #include "core/paint/PaintLayerPainter.h" |
67 #include "core/timing/DOMWindowPerformance.h" | 68 #include "core/timing/DOMWindowPerformance.h" |
68 #include "core/timing/Performance.h" | 69 #include "core/timing/Performance.h" |
69 #include "platform/KeyboardCodes.h" | 70 #include "platform/KeyboardCodes.h" |
70 #include "platform/geometry/IntRect.h" | 71 #include "platform/geometry/IntRect.h" |
71 #include "platform/geometry/IntSize.h" | 72 #include "platform/geometry/IntSize.h" |
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 web_view->SetInitialFocus(false); | 1625 web_view->SetInitialFocus(false); |
1625 frame->SetEditableSelectionOffsets(4, 10); | 1626 frame->SetEditableSelectionOffsets(4, 10); |
1626 EXPECT_TRUE(web_view->IsSelectionAnchorFirst()); | 1627 EXPECT_TRUE(web_view->IsSelectionAnchorFirst()); |
1627 WebRect anchor; | 1628 WebRect anchor; |
1628 WebRect focus; | 1629 WebRect focus; |
1629 web_view->SelectionBounds(anchor, focus); | 1630 web_view->SelectionBounds(anchor, focus); |
1630 frame->SelectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)); | 1631 frame->SelectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)); |
1631 EXPECT_FALSE(web_view->IsSelectionAnchorFirst()); | 1632 EXPECT_FALSE(web_view->IsSelectionAnchorFirst()); |
1632 } | 1633 } |
1633 | 1634 |
| 1635 TEST_P( |
| 1636 WebViewTest, |
| 1637 MoveFocusToNextFocusableElementInFormWithKeyEventListenersAndNonEditableElem
ents) { |
| 1638 const std::string test_file = |
| 1639 "advance_focus_in_form_with_key_event_listeners.html"; |
| 1640 RegisterMockedHttpURLLoad(test_file); |
| 1641 WebViewBase* web_view = |
| 1642 web_view_helper_.InitializeAndLoad(base_url_ + test_file); |
| 1643 web_view->SetInitialFocus(false); |
| 1644 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument(); |
| 1645 WebInputMethodController* active_input_method_controller = |
| 1646 web_view->MainFrameImpl() |
| 1647 ->FrameWidget() |
| 1648 ->GetActiveWebInputMethodController(); |
| 1649 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences; |
| 1650 |
| 1651 struct FocusedElement { |
| 1652 AtomicString element_id; |
| 1653 int text_input_flags; |
| 1654 } focused_elements[] = { |
| 1655 {"input1", |
| 1656 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement}, |
| 1657 {"contenteditable1", kWebTextInputFlagHaveNextFocusableElement | |
| 1658 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1659 {"input2", default_text_input_flags | |
| 1660 kWebTextInputFlagHaveNextFocusableElement | |
| 1661 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1662 {"textarea1", default_text_input_flags | |
| 1663 kWebTextInputFlagHaveNextFocusableElement | |
| 1664 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1665 {"input3", default_text_input_flags | |
| 1666 kWebTextInputFlagHaveNextFocusableElement | |
| 1667 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1668 {"textarea2", default_text_input_flags | |
| 1669 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1670 }; |
| 1671 |
| 1672 // Forward Navigation in form1 with NEXT |
| 1673 Element* input1 = document->getElementById("input1"); |
| 1674 input1->focus(); |
| 1675 Element* current_focus = nullptr; |
| 1676 Element* next_focus = nullptr; |
| 1677 WebTextInputInfo text_input_info; |
| 1678 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 1679 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1680 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1681 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1682 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1683 next_focus = |
| 1684 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1685 current_focus, kWebFocusTypeForward); |
| 1686 if (next_focus) { |
| 1687 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1688 focused_elements[i + 1].element_id); |
| 1689 } |
| 1690 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1691 } |
| 1692 // Now focus will stay on previous focus itself, because it has no next |
| 1693 // element. |
| 1694 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1695 |
| 1696 // Backward Navigation in form1 with PREVIOUS |
| 1697 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 1698 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1699 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1700 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1701 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1702 next_focus = |
| 1703 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1704 current_focus, kWebFocusTypeBackward); |
| 1705 if (next_focus) { |
| 1706 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1707 focused_elements[i - 1].element_id); |
| 1708 } |
| 1709 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1710 } |
| 1711 // Now focus will stay on previous focus itself, because it has no previous |
| 1712 // element. |
| 1713 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1714 |
| 1715 // Setting a non editable element as focus in form1, and ensuring editable |
| 1716 // navigation is fine in forward and backward. |
| 1717 Element* button1 = document->getElementById("button1"); |
| 1718 button1->focus(); |
| 1719 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1720 EXPECT_EQ(kWebTextInputFlagHaveNextFocusableElement | |
| 1721 kWebTextInputFlagHavePreviousFocusableElement, |
| 1722 text_input_info.flags); |
| 1723 next_focus = |
| 1724 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1725 button1, kWebFocusTypeForward); |
| 1726 EXPECT_EQ(next_focus->GetIdAttribute(), "contenteditable1"); |
| 1727 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1728 Element* content_editable1 = document->getElementById("contenteditable1"); |
| 1729 EXPECT_EQ(content_editable1, document->FocusedElement()); |
| 1730 button1->focus(); |
| 1731 next_focus = |
| 1732 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1733 button1, kWebFocusTypeBackward); |
| 1734 EXPECT_EQ(next_focus->GetIdAttribute(), "input1"); |
| 1735 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1736 EXPECT_EQ(input1, document->FocusedElement()); |
| 1737 |
| 1738 Element* anchor1 = document->getElementById("anchor1"); |
| 1739 anchor1->focus(); |
| 1740 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1741 // No Next/Previous element for elements outside form. |
| 1742 EXPECT_EQ(0, text_input_info.flags); |
| 1743 next_focus = |
| 1744 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1745 anchor1, kWebFocusTypeForward); |
| 1746 EXPECT_EQ(next_focus, nullptr); |
| 1747 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1748 // Since anchor is not a form control element, next/previous element will |
| 1749 // be null, hence focus will stay same as it is. |
| 1750 EXPECT_EQ(anchor1, document->FocusedElement()); |
| 1751 |
| 1752 next_focus = |
| 1753 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1754 anchor1, kWebFocusTypeBackward); |
| 1755 EXPECT_EQ(next_focus, nullptr); |
| 1756 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1757 EXPECT_EQ(anchor1, document->FocusedElement()); |
| 1758 |
| 1759 // Navigation of elements which is not part of any forms. |
| 1760 Element* text_area3 = document->getElementById("textarea3"); |
| 1761 text_area3->focus(); |
| 1762 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1763 // No Next/Previous element for elements outside form. |
| 1764 EXPECT_EQ(default_text_input_flags, text_input_info.flags); |
| 1765 next_focus = |
| 1766 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1767 text_area3, kWebFocusTypeForward); |
| 1768 EXPECT_EQ(next_focus, nullptr); |
| 1769 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1770 // No Next/Previous element to this element because it's not part of any |
| 1771 // form. Hence focus won't change wrt NEXT/PREVIOUS. |
| 1772 EXPECT_EQ(text_area3, document->FocusedElement()); |
| 1773 next_focus = |
| 1774 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1775 text_area3, kWebFocusTypeBackward); |
| 1776 EXPECT_EQ(next_focus, nullptr); |
| 1777 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1778 EXPECT_EQ(text_area3, document->FocusedElement()); |
| 1779 |
| 1780 // Navigation from an element which is part of a form but not an editable |
| 1781 // element. |
| 1782 Element* button2 = document->getElementById("button2"); |
| 1783 button2->focus(); |
| 1784 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1785 // No Next element for this element, due to last element outside the form. |
| 1786 EXPECT_EQ(kWebTextInputFlagHavePreviousFocusableElement, |
| 1787 text_input_info.flags); |
| 1788 next_focus = |
| 1789 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1790 button2, kWebFocusTypeForward); |
| 1791 EXPECT_EQ(next_focus, nullptr); |
| 1792 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1793 // No Next element to this element because it's not part of any form. |
| 1794 // Hence focus won't change wrt NEXT. |
| 1795 EXPECT_EQ(button2, document->FocusedElement()); |
| 1796 Element* text_area2 = document->getElementById("textarea2"); |
| 1797 next_focus = |
| 1798 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1799 button2, kWebFocusTypeBackward); |
| 1800 EXPECT_EQ(next_focus, text_area2); |
| 1801 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1802 // Since button is a form control element from form1, ensuring focus is set |
| 1803 // at correct position. |
| 1804 EXPECT_EQ(text_area2, document->FocusedElement()); |
| 1805 |
| 1806 Element* content_editable2 = document->getElementById("contenteditable2"); |
| 1807 document->SetFocusedElement( |
| 1808 content_editable2, |
| 1809 FocusParams(SelectionBehaviorOnFocus::kNone, kWebFocusTypeNone, nullptr)); |
| 1810 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1811 // No Next/Previous element for elements outside form. |
| 1812 EXPECT_EQ(0, text_input_info.flags); |
| 1813 next_focus = |
| 1814 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1815 content_editable2, kWebFocusTypeForward); |
| 1816 EXPECT_EQ(next_focus, nullptr); |
| 1817 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1818 // No Next/Previous element to this element because it's not part of any |
| 1819 // form. Hence focus won't change wrt NEXT/PREVIOUS. |
| 1820 EXPECT_EQ(content_editable2, document->FocusedElement()); |
| 1821 next_focus = |
| 1822 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1823 content_editable2, kWebFocusTypeBackward); |
| 1824 EXPECT_EQ(next_focus, nullptr); |
| 1825 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1826 EXPECT_EQ(content_editable2, document->FocusedElement()); |
| 1827 |
| 1828 // Navigation of elements which is having invalid form attribute and hence |
| 1829 // not part of any forms. |
| 1830 Element* text_area4 = document->getElementById("textarea4"); |
| 1831 text_area4->focus(); |
| 1832 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1833 // No Next/Previous element for elements which is having invalid form |
| 1834 // attribute. |
| 1835 EXPECT_EQ(default_text_input_flags, text_input_info.flags); |
| 1836 next_focus = |
| 1837 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1838 text_area4, kWebFocusTypeForward); |
| 1839 EXPECT_EQ(next_focus, nullptr); |
| 1840 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1841 // No Next/Previous element to this element because it's not part of any |
| 1842 // form. Hence focus won't change wrt NEXT/PREVIOUS. |
| 1843 EXPECT_EQ(text_area4, document->FocusedElement()); |
| 1844 next_focus = |
| 1845 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1846 text_area4, kWebFocusTypeBackward); |
| 1847 EXPECT_EQ(next_focus, nullptr); |
| 1848 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1849 EXPECT_EQ(text_area4, document->FocusedElement()); |
| 1850 |
| 1851 web_view_helper_.Reset(); |
| 1852 } |
| 1853 |
| 1854 TEST_P( |
| 1855 WebViewTest, |
| 1856 MoveFocusToNextFocusableElementInFormWithNonEditableNonFormControlElements)
{ |
| 1857 const std::string test_file = |
| 1858 "advance_focus_in_form_with_key_event_listeners.html"; |
| 1859 RegisterMockedHttpURLLoad(test_file); |
| 1860 WebViewBase* 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 {"textarea5", |
| 1875 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement}, |
| 1876 {"input4", default_text_input_flags | |
| 1877 kWebTextInputFlagHaveNextFocusableElement | |
| 1878 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1879 {"contenteditable3", kWebTextInputFlagHaveNextFocusableElement | |
| 1880 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1881 {"input5", kWebTextInputFlagHavePreviousFocusableElement}, |
| 1882 }; |
| 1883 |
| 1884 // Forward Navigation in form2 with NEXT |
| 1885 Element* text_area5 = document->getElementById("textarea5"); |
| 1886 text_area5->focus(); |
| 1887 Element* current_focus = nullptr; |
| 1888 Element* next_focus = nullptr; |
| 1889 WebTextInputInfo text_input_info; |
| 1890 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 1891 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1892 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1893 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1894 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1895 next_focus = |
| 1896 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1897 current_focus, kWebFocusTypeForward); |
| 1898 if (next_focus) { |
| 1899 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1900 focused_elements[i + 1].element_id); |
| 1901 } |
| 1902 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1903 } |
| 1904 // Now focus will stay on previous focus itself, because it has no next |
| 1905 // element. |
| 1906 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1907 |
| 1908 // Backward Navigation in form1 with PREVIOUS |
| 1909 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 1910 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1911 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1912 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1913 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1914 next_focus = |
| 1915 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1916 current_focus, kWebFocusTypeBackward); |
| 1917 if (next_focus) { |
| 1918 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1919 focused_elements[i - 1].element_id); |
| 1920 } |
| 1921 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1922 } |
| 1923 // Now focus will stay on previous focus itself, because it has no previous |
| 1924 // element. |
| 1925 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1926 |
| 1927 // Setting a non editable element as focus in form1, and ensuring editable |
| 1928 // navigation is fine in forward and backward. |
| 1929 Element* anchor2 = document->getElementById("anchor2"); |
| 1930 anchor2->focus(); |
| 1931 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1932 // No Next/Previous element for non-form control elements inside form. |
| 1933 EXPECT_EQ(0, text_input_info.flags); |
| 1934 next_focus = |
| 1935 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1936 anchor2, kWebFocusTypeForward); |
| 1937 EXPECT_EQ(next_focus, nullptr); |
| 1938 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 1939 // Since anchor is not a form control element, next/previous element will |
| 1940 // be null, hence focus will stay same as it is. |
| 1941 EXPECT_EQ(anchor2, document->FocusedElement()); |
| 1942 next_focus = |
| 1943 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1944 anchor2, kWebFocusTypeBackward); |
| 1945 EXPECT_EQ(next_focus, nullptr); |
| 1946 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 1947 EXPECT_EQ(anchor2, document->FocusedElement()); |
| 1948 |
| 1949 web_view_helper_.Reset(); |
| 1950 } |
| 1951 |
| 1952 TEST_P(WebViewTest, MoveFocusToNextFocusableElementInFormWithTabIndexElements) { |
| 1953 const std::string test_file = |
| 1954 "advance_focus_in_form_with_tabindex_elements.html"; |
| 1955 RegisterMockedHttpURLLoad(test_file); |
| 1956 WebViewBase* web_view = |
| 1957 web_view_helper_.InitializeAndLoad(base_url_ + test_file); |
| 1958 web_view->SetInitialFocus(false); |
| 1959 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument(); |
| 1960 WebInputMethodController* active_input_method_controller = |
| 1961 web_view->MainFrameImpl() |
| 1962 ->FrameWidget() |
| 1963 ->GetActiveWebInputMethodController(); |
| 1964 const int default_text_input_flags = kWebTextInputFlagAutocapitalizeSentences; |
| 1965 |
| 1966 struct FocusedElement { |
| 1967 const char* element_id; |
| 1968 int text_input_flags; |
| 1969 } focused_elements[] = { |
| 1970 {"textarea6", |
| 1971 default_text_input_flags | kWebTextInputFlagHaveNextFocusableElement}, |
| 1972 {"input5", default_text_input_flags | |
| 1973 kWebTextInputFlagHaveNextFocusableElement | |
| 1974 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1975 {"contenteditable4", kWebTextInputFlagHaveNextFocusableElement | |
| 1976 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1977 {"input6", default_text_input_flags | |
| 1978 kWebTextInputFlagHavePreviousFocusableElement}, |
| 1979 }; |
| 1980 |
| 1981 // Forward Navigation in form with NEXT which has tabindex attribute |
| 1982 // which differs visual order. |
| 1983 Element* text_area6 = document->getElementById("textarea6"); |
| 1984 text_area6->focus(); |
| 1985 Element* current_focus = nullptr; |
| 1986 Element* next_focus = nullptr; |
| 1987 WebTextInputInfo text_input_info; |
| 1988 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 1989 current_focus = document->getElementById(focused_elements[i].element_id); |
| 1990 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 1991 text_input_info = active_input_method_controller->TextInputInfo(); |
| 1992 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 1993 next_focus = |
| 1994 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 1995 current_focus, kWebFocusTypeForward); |
| 1996 if (next_focus) { |
| 1997 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 1998 focused_elements[i + 1].element_id); |
| 1999 } |
| 2000 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 2001 } |
| 2002 // No next editable element which is focusable with proper tab index, hence |
| 2003 // staying on previous focus. |
| 2004 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2005 |
| 2006 // Backward Navigation in form with PREVIOUS which has tabindex attribute |
| 2007 // which differs visual order. |
| 2008 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 2009 current_focus = document->getElementById(focused_elements[i].element_id); |
| 2010 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2011 text_input_info = active_input_method_controller->TextInputInfo(); |
| 2012 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 2013 next_focus = |
| 2014 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2015 current_focus, kWebFocusTypeBackward); |
| 2016 if (next_focus) { |
| 2017 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 2018 focused_elements[i - 1].element_id); |
| 2019 } |
| 2020 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 2021 } |
| 2022 // Now focus will stay on previous focus itself, because it has no previous |
| 2023 // element. |
| 2024 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2025 |
| 2026 // Setting an element which has invalid tabindex and ensuring it is not |
| 2027 // modifying further navigation. |
| 2028 Element* content_editable5 = document->getElementById("contenteditable5"); |
| 2029 content_editable5->focus(); |
| 2030 Element* input6 = document->getElementById("input6"); |
| 2031 next_focus = |
| 2032 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2033 content_editable5, kWebFocusTypeForward); |
| 2034 EXPECT_EQ(next_focus, input6); |
| 2035 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 2036 EXPECT_EQ(input6, document->FocusedElement()); |
| 2037 content_editable5->focus(); |
| 2038 next_focus = |
| 2039 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2040 content_editable5, kWebFocusTypeBackward); |
| 2041 EXPECT_EQ(next_focus, text_area6); |
| 2042 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 2043 EXPECT_EQ(text_area6, document->FocusedElement()); |
| 2044 |
| 2045 web_view_helper_.Reset(); |
| 2046 } |
| 2047 |
| 2048 TEST_P(WebViewTest, |
| 2049 MoveFocusToNextFocusableElementInFormWithDisabledAndReadonlyElements) { |
| 2050 const std::string test_file = |
| 2051 "advance_focus_in_form_with_disabled_and_readonly_elements.html"; |
| 2052 RegisterMockedHttpURLLoad(test_file); |
| 2053 WebViewBase* web_view = |
| 2054 web_view_helper_.InitializeAndLoad(base_url_ + test_file); |
| 2055 web_view->SetInitialFocus(false); |
| 2056 Document* document = web_view->MainFrameImpl()->GetFrame()->GetDocument(); |
| 2057 WebInputMethodController* active_input_method_controller = |
| 2058 web_view->MainFrameImpl() |
| 2059 ->FrameWidget() |
| 2060 ->GetActiveWebInputMethodController(); |
| 2061 |
| 2062 struct FocusedElement { |
| 2063 const char* element_id; |
| 2064 int text_input_flags; |
| 2065 } focused_elements[] = { |
| 2066 {"contenteditable6", kWebTextInputFlagHaveNextFocusableElement}, |
| 2067 {"contenteditable7", kWebTextInputFlagHavePreviousFocusableElement}, |
| 2068 }; |
| 2069 // Forward Navigation in form with NEXT which has has disabled/enabled |
| 2070 // elements which will gets skipped during navigation. |
| 2071 Element* content_editable6 = document->getElementById("contenteditable6"); |
| 2072 content_editable6->focus(); |
| 2073 Element* current_focus = nullptr; |
| 2074 Element* next_focus = nullptr; |
| 2075 WebTextInputInfo text_input_info; |
| 2076 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focused_elements); ++i) { |
| 2077 current_focus = document->getElementById(focused_elements[i].element_id); |
| 2078 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2079 text_input_info = active_input_method_controller->TextInputInfo(); |
| 2080 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 2081 next_focus = |
| 2082 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2083 current_focus, kWebFocusTypeForward); |
| 2084 if (next_focus) { |
| 2085 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 2086 focused_elements[i + 1].element_id); |
| 2087 } |
| 2088 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeForward); |
| 2089 } |
| 2090 // No next editable element which is focusable, hence staying on previous |
| 2091 // focus. |
| 2092 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2093 |
| 2094 // Backward Navigation in form with PREVIOUS which has has |
| 2095 // disabled/enabled elements which will gets skipped during navigation. |
| 2096 for (size_t i = WTF_ARRAY_LENGTH(focused_elements); i-- > 0;) { |
| 2097 current_focus = document->getElementById(focused_elements[i].element_id); |
| 2098 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2099 text_input_info = active_input_method_controller->TextInputInfo(); |
| 2100 EXPECT_EQ(focused_elements[i].text_input_flags, text_input_info.flags); |
| 2101 next_focus = |
| 2102 document->GetPage()->GetFocusController().NextFocusableElementInForm( |
| 2103 current_focus, kWebFocusTypeBackward); |
| 2104 if (next_focus) { |
| 2105 EXPECT_EQ(next_focus->GetIdAttribute(), |
| 2106 focused_elements[i - 1].element_id); |
| 2107 } |
| 2108 web_view->MainFrameImpl()->AdvanceFocusInForm(kWebFocusTypeBackward); |
| 2109 } |
| 2110 // Now focus will stay on previous focus itself, because it has no previous |
| 2111 // element. |
| 2112 EXPECT_EQ(current_focus, document->FocusedElement()); |
| 2113 |
| 2114 web_view_helper_.Reset(); |
| 2115 } |
| 2116 |
1634 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) { | 2117 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) { |
1635 RegisterMockedHttpURLLoad("200-by-300.html"); | 2118 RegisterMockedHttpURLLoad("200-by-300.html"); |
1636 WebViewBase* web_view_impl = | 2119 WebViewBase* web_view_impl = |
1637 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html"); | 2120 web_view_helper_.InitializeAndLoad(base_url_ + "200-by-300.html"); |
1638 web_view_impl->Resize(WebSize(200, 300)); | 2121 web_view_impl->Resize(WebSize(200, 300)); |
1639 | 2122 |
1640 float page_scale_expected = web_view_impl->PageScaleFactor(); | 2123 float page_scale_expected = web_view_impl->PageScaleFactor(); |
1641 | 2124 |
1642 WebDeviceEmulationParams params; | 2125 WebDeviceEmulationParams params; |
1643 params.screen_position = WebDeviceEmulationParams::kDesktop; | 2126 params.screen_position = WebDeviceEmulationParams::kDesktop; |
(...skipping 2692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4336 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars()); | 4819 EXPECT_FALSE(frame_view->VisualViewportSuppliesScrollbars()); |
4337 if (RuntimeEnabledFeatures::RootLayerScrollingEnabled()) { | 4820 if (RuntimeEnabledFeatures::RootLayerScrollingEnabled()) { |
4338 EXPECT_NE(nullptr, | 4821 EXPECT_NE(nullptr, |
4339 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar()); | 4822 frame_view->LayoutViewportScrollableArea()->VerticalScrollbar()); |
4340 } else { | 4823 } else { |
4341 EXPECT_NE(nullptr, frame_view->VerticalScrollbar()); | 4824 EXPECT_NE(nullptr, frame_view->VerticalScrollbar()); |
4342 } | 4825 } |
4343 } | 4826 } |
4344 | 4827 |
4345 } // namespace blink | 4828 } // namespace blink |
OLD | NEW |