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

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

Powered by Google App Engine
This is Rietveld 408576698