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

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: 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 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 webView->setInitialFocus(false); 1603 webView->setInitialFocus(false);
1604 frame->setEditableSelectionOffsets(4, 10); 1604 frame->setEditableSelectionOffsets(4, 10);
1605 EXPECT_TRUE(webView->isSelectionAnchorFirst()); 1605 EXPECT_TRUE(webView->isSelectionAnchorFirst());
1606 WebRect anchor; 1606 WebRect anchor;
1607 WebRect focus; 1607 WebRect focus;
1608 webView->selectionBounds(anchor, focus); 1608 webView->selectionBounds(anchor, focus);
1609 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y)); 1609 frame->selectRange(WebPoint(focus.x, focus.y), WebPoint(anchor.x, anchor.y));
1610 EXPECT_FALSE(webView->isSelectionAnchorFirst()); 1610 EXPECT_FALSE(webView->isSelectionAnchorFirst());
1611 } 1611 }
1612 1612
1613 TEST_P(
1614 WebViewTest,
1615 MoveFocusToNextFocusableElementInFormWithKeyEventListenersAndNonEditableElem ents) {
1616 const std::string testFile =
1617 "advance_focus_in_form_with_key_event_listeners.html";
1618 registerMockedHttpURLLoad(testFile);
1619 WebViewImpl* webViewImpl =
1620 m_webViewHelper.initializeAndLoad(m_baseURL + testFile);
1621 webViewImpl->setInitialFocus(false);
1622 // WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
1623 Document* document = webViewImpl->mainFrameImpl()->frame()->document();
1624 WebInputMethodController* activeInputMethodController =
1625 webViewImpl->mainFrameImpl()
1626 ->frameWidget()
1627 ->getActiveWebInputMethodController();
1628 const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
1629
1630 struct FocusedElement {
1631 const char* elementId;
1632 int textInputFlags;
1633 } focusedElements[] = {
1634 {"input1",
1635 defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement},
1636 {"contenteditable1", WebTextInputFlagHaveNextFocusableElement |
1637 WebTextInputFlagHavePreviousFocusableElement},
1638 {"input2", defaultTextInputFlags |
1639 WebTextInputFlagHaveNextFocusableElement |
1640 WebTextInputFlagHavePreviousFocusableElement |
1641 WebTextInputFlagListeningToKeyboardEvents},
1642 {"textarea1", defaultTextInputFlags |
1643 WebTextInputFlagHaveNextFocusableElement |
1644 WebTextInputFlagHavePreviousFocusableElement},
1645 {"input3", defaultTextInputFlags |
1646 WebTextInputFlagHaveNextFocusableElement |
1647 WebTextInputFlagHavePreviousFocusableElement},
1648 {"textarea2",
1649 defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableElement},
1650 };
1651
1652 // Forward Navigation in form1 with NEXT
1653 Element* input1 = document->getElementById("input1");
1654 input1->focus();
1655 Element* currentFocus = nullptr;
1656 WebTextInputInfo textInputInfo;
1657 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focusedElements); ++i) {
1658 currentFocus = document->getElementById(focusedElements[i].elementId);
1659 EXPECT_EQ(currentFocus, document->focusedElement());
1660 textInputInfo = activeInputMethodController->textInputInfo();
1661 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1662 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1663 }
1664 // Now focus will stay on previous focus itself, because it has no next
1665 // element.
1666 EXPECT_EQ(currentFocus, document->focusedElement());
1667
1668 // Backward Navigation in form1 with PREVIOUS
1669 for (size_t i = WTF_ARRAY_LENGTH(focusedElements); i-- > 0;) {
1670 currentFocus = document->getElementById(focusedElements[i].elementId);
1671 EXPECT_EQ(currentFocus, document->focusedElement());
1672 textInputInfo = activeInputMethodController->textInputInfo();
1673 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1674 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1675 }
1676 // Now focus will stay on previous focus itself, because it has no previous
1677 // element.
1678 EXPECT_EQ(currentFocus, document->focusedElement());
1679
1680 // Setting a non editable element as focus in form1, and ensuring editable
1681 // navigation is fine in forward and backward.
1682 Element* button1 = document->getElementById("button1");
1683 button1->focus();
1684 textInputInfo = activeInputMethodController->textInputInfo();
1685 // No Next/Previous element for elements outside form.
1686 EXPECT_EQ(0, textInputInfo.flags);
1687 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1688 Element* contenteditable1 = document->getElementById("contenteditable1");
1689 EXPECT_EQ(contenteditable1, document->focusedElement());
1690 button1->focus();
1691 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1692 EXPECT_EQ(input1, document->focusedElement());
1693
1694 Element* anchor1 = document->getElementById("anchor1");
1695 anchor1->focus();
1696 textInputInfo = activeInputMethodController->textInputInfo();
1697 // No Next/Previous element for elements outside form.
1698 EXPECT_EQ(0, textInputInfo.flags);
1699 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1700 // Since anchor is not a form control element, next/previous element will
1701 // be null, hence focus will stay same as it is.
1702 EXPECT_EQ(anchor1, document->focusedElement());
1703 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1704 EXPECT_EQ(anchor1, document->focusedElement());
1705
1706 // Navigation of elements which is not part of any forms.
1707 Element* textarea3 = document->getElementById("textarea3");
1708 textarea3->focus();
1709 textInputInfo = activeInputMethodController->textInputInfo();
1710 // No Next/Previous element for elements outside form.
1711 EXPECT_EQ(defaultTextInputFlags, textInputInfo.flags);
1712 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1713 // No Next/Previous element to this element because it's not part of any
1714 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1715 EXPECT_EQ(textarea3, document->focusedElement());
1716 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1717 EXPECT_EQ(textarea3, document->focusedElement());
1718
1719 // Navigation from an element which is part of a form but not an editable
1720 // element.
1721 Element* button2 = document->getElementById("button2");
1722 button2->focus();
1723 textInputInfo = activeInputMethodController->textInputInfo();
1724 // No Next element for this element, due to last element outside the form.
1725 EXPECT_EQ(0, textInputInfo.flags);
1726 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1727 // No Next element to this element because it's not part of any form.
1728 // Hence focus won't change wrt NEXT.
1729 EXPECT_EQ(button2, document->focusedElement());
1730 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1731 // Since button is a form control element from form1, ensuring focus is set
1732 // at correct position.
1733 Element* textarea2 = document->getElementById("textarea2");
1734 EXPECT_EQ(textarea2, document->focusedElement());
1735
1736 Element* contenteditable2 = document->getElementById("contenteditable2");
1737 document->setFocusedElement(
1738 contenteditable2,
1739 FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr));
1740 textInputInfo = activeInputMethodController->textInputInfo();
1741 // No Next/Previous element for elements outside form.
1742 EXPECT_EQ(0, textInputInfo.flags);
1743 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1744 // No Next/Previous element to this element because it's not part of any
1745 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1746 EXPECT_EQ(contenteditable2, document->focusedElement());
1747 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1748 EXPECT_EQ(contenteditable2, document->focusedElement());
1749
1750 // Navigation of elements which is having invalid form attribute and hence
1751 // not part of any forms.
1752 Element* textarea4 = document->getElementById("textarea4");
1753 textarea4->focus();
1754 textInputInfo = activeInputMethodController->textInputInfo();
1755 // No Next/Previous element for elements which is having invalid form
1756 // attribute.
1757 EXPECT_EQ(defaultTextInputFlags, textInputInfo.flags);
1758 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1759 // No Next/Previous element to this element because it's not part of any
1760 // form. Hence focus won't change wrt NEXT/PREVIOUS.
1761 EXPECT_EQ(textarea4, document->focusedElement());
1762 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1763 EXPECT_EQ(textarea4, document->focusedElement());
1764
1765 m_webViewHelper.reset();
1766 }
1767
1768 TEST_P(
1769 WebViewTest,
1770 MoveFocusToNextFocusableElementInFormWithNonEditableNonFormControlElements) {
1771 const std::string testFile =
1772 "advance_focus_in_form_with_key_event_listeners.html";
1773 registerMockedHttpURLLoad(testFile);
1774 WebViewImpl* webViewImpl =
1775 m_webViewHelper.initializeAndLoad(m_baseURL + testFile);
1776 webViewImpl->setInitialFocus(false);
1777 Document* document = webViewImpl->mainFrameImpl()->frame()->document();
1778 WebInputMethodController* activeInputMethodController =
1779 webViewImpl->mainFrameImpl()
1780 ->frameWidget()
1781 ->getActiveWebInputMethodController();
1782 const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
1783
1784 struct FocusedElement {
1785 const char* elementId;
1786 int textInputFlags;
1787 } focusedElements[] = {
1788 {"textarea5", defaultTextInputFlags |
1789 WebTextInputFlagListeningToKeyboardEvents |
1790 WebTextInputFlagHaveNextFocusableElement},
1791 {"input4", defaultTextInputFlags |
1792 WebTextInputFlagListeningToKeyboardEvents |
1793 WebTextInputFlagHaveNextFocusableElement |
1794 WebTextInputFlagHavePreviousFocusableElement},
1795 {"contenteditable3", WebTextInputFlagListeningToKeyboardEvents |
1796 WebTextInputFlagHavePreviousFocusableElement},
1797 };
1798
1799 // Forward Navigation in form2 with NEXT
1800 Element* textarea5 = document->getElementById("textarea5");
1801 textarea5->focus();
1802 Element* currentFocus = nullptr;
1803 WebTextInputInfo textInputInfo;
1804 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focusedElements); ++i) {
1805 currentFocus = document->getElementById(focusedElements[i].elementId);
1806 EXPECT_EQ(currentFocus, document->focusedElement());
1807 textInputInfo = activeInputMethodController->textInputInfo();
1808 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1809 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1810 }
1811 // Now focus will stay on previous focus itself, because it has no next
1812 // element.
1813 EXPECT_EQ(currentFocus, document->focusedElement());
1814
1815 // Backward Navigation in form1 with PREVIOUS
1816 for (size_t i = WTF_ARRAY_LENGTH(focusedElements); i-- > 0;) {
1817 currentFocus = document->getElementById(focusedElements[i].elementId);
1818 EXPECT_EQ(currentFocus, document->focusedElement());
1819 textInputInfo = activeInputMethodController->textInputInfo();
1820 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1821 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1822 }
1823 // Now focus will stay on previous focus itself, because it has no previous
1824 // element.
1825 EXPECT_EQ(currentFocus, document->focusedElement());
1826
1827 // Setting a non editable element as focus in form1, and ensuring editable
1828 // navigation is fine in forward and backward.
1829 Element* anchor2 = document->getElementById("anchor2");
1830 anchor2->focus();
1831 textInputInfo = activeInputMethodController->textInputInfo();
1832 // No Next/Previous element for elements outside form.
1833 EXPECT_EQ(0, textInputInfo.flags);
1834 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1835 // No editable element after this inside the form, hence focus won't change.
1836 EXPECT_EQ(anchor2, document->focusedElement());
1837 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1838 // Since anchor is not a form control element, next/previous element will
1839 // be null, hence focus will stay same as it is.
1840 EXPECT_EQ(anchor2, document->focusedElement());
1841
1842 m_webViewHelper.reset();
1843 }
1844
1845 TEST_P(WebViewTest, MoveFocusToNextFocusableElementInFormWithTabIndexElements) {
1846 const std::string testFile =
1847 "advance_focus_in_form_with_tabindex_elements.html";
1848 registerMockedHttpURLLoad(testFile);
1849 WebViewImpl* webViewImpl =
1850 m_webViewHelper.initializeAndLoad(m_baseURL + testFile);
1851 webViewImpl->setInitialFocus(false);
1852 // WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
1853 Document* document = webViewImpl->mainFrameImpl()->frame()->document();
1854 WebInputMethodController* activeInputMethodController =
1855 webViewImpl->mainFrameImpl()
1856 ->frameWidget()
1857 ->getActiveWebInputMethodController();
1858 const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
1859
1860 struct FocusedElement {
1861 const char* elementId;
1862 int textInputFlags;
1863 } focusedElements[] = {
1864 {"textarea6",
1865 defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement},
1866 {"input5", defaultTextInputFlags |
1867 WebTextInputFlagHaveNextFocusableElement |
1868 WebTextInputFlagHavePreviousFocusableElement},
1869 {"contenteditable4", WebTextInputFlagHaveNextFocusableElement |
1870 WebTextInputFlagHavePreviousFocusableElement},
1871 {"input6",
1872 defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableElement},
1873 };
1874
1875 // Forward Navigation in form with NEXT which has tabindex attribute
1876 // which differs visual order.
1877 Element* textarea6 = document->getElementById("textarea6");
1878 textarea6->focus();
1879 Element* currentFocus = nullptr;
1880 WebTextInputInfo textInputInfo;
1881 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focusedElements); ++i) {
1882 currentFocus = document->getElementById(focusedElements[i].elementId);
1883 EXPECT_EQ(currentFocus, document->focusedElement());
1884 textInputInfo = activeInputMethodController->textInputInfo();
1885 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1886 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1887 }
1888 // No next editable element which is focusable with proper tab index, hence
1889 // staying on previous focus.
1890 EXPECT_EQ(currentFocus, document->focusedElement());
1891
1892 // Backward Navigation in form with PREVIOUS which has tabindex attribute
1893 // which differs visual order.
1894 for (size_t i = WTF_ARRAY_LENGTH(focusedElements); i-- > 0;) {
1895 currentFocus = document->getElementById(focusedElements[i].elementId);
1896 EXPECT_EQ(currentFocus, document->focusedElement());
1897 textInputInfo = activeInputMethodController->textInputInfo();
1898 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1899 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1900 }
1901 // Now focus will stay on previous focus itself, because it has no previous
1902 // element.
1903 EXPECT_EQ(currentFocus, document->focusedElement());
1904
1905 // Setting an element which has invalid tabindex and ensuring it is not
1906 // modifying further navigation.
1907 Element* contenteditable5 = document->getElementById("contenteditable5");
1908 contenteditable5->focus();
1909 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1910 Element* input6 = document->getElementById("input6");
1911 EXPECT_EQ(input6, document->focusedElement());
1912 contenteditable5->focus();
1913 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1914 EXPECT_EQ(textarea6, document->focusedElement());
1915
1916 m_webViewHelper.reset();
1917 }
1918
1919 TEST_P(WebViewTest,
1920 MoveFocusToNextFocusableElementInFormWithDisabledAndReadonlyElements) {
1921 const std::string testFile =
1922 "advance_focus_in_form_with_disabled_and_readonly_elements.html";
1923 registerMockedHttpURLLoad(testFile);
1924 WebViewImpl* webViewImpl =
1925 m_webViewHelper.initializeAndLoad(m_baseURL + testFile);
1926 webViewImpl->setInitialFocus(false);
1927 // WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
1928 Document* document = webViewImpl->mainFrameImpl()->frame()->document();
1929 WebInputMethodController* activeInputMethodController =
1930 webViewImpl->mainFrameImpl()
1931 ->frameWidget()
1932 ->getActiveWebInputMethodController();
1933
1934 struct FocusedElement {
1935 const char* elementId;
1936 int textInputFlags;
1937 } focusedElements[] = {
1938 {"contenteditable6", WebTextInputFlagHaveNextFocusableElement},
1939 {"contenteditable7", WebTextInputFlagHavePreviousFocusableElement},
1940 };
1941 // Forward Navigation in form with NEXT which has has disabled/enabled
1942 // elements which will gets skipped during navigation.
1943 Element* contenteditable6 = document->getElementById("contenteditable6");
1944 contenteditable6->focus();
1945 Element* currentFocus = nullptr;
1946 WebTextInputInfo textInputInfo;
1947 for (size_t i = 0; i < WTF_ARRAY_LENGTH(focusedElements); ++i) {
1948 currentFocus = document->getElementById(focusedElements[i].elementId);
1949 EXPECT_EQ(currentFocus, document->focusedElement());
1950 textInputInfo = activeInputMethodController->textInputInfo();
1951 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1952 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
1953 }
1954 // No next editable element which is focusable, hence staying on previous
1955 // focus.
1956 EXPECT_EQ(currentFocus, document->focusedElement());
1957
1958 // Backward Navigation in form with PREVIOUS which has has
1959 // disabled/enabled elements which will gets skipped during navigation.
1960 for (size_t i = WTF_ARRAY_LENGTH(focusedElements); i-- > 0;) {
1961 currentFocus = document->getElementById(focusedElements[i].elementId);
1962 EXPECT_EQ(currentFocus, document->focusedElement());
1963 textInputInfo = activeInputMethodController->textInputInfo();
1964 EXPECT_EQ(focusedElements[i].textInputFlags, textInputInfo.flags);
1965 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
1966 }
1967 // Now focus will stay on previous focus itself, because it has no previous
1968 // element.
1969 EXPECT_EQ(currentFocus, document->focusedElement());
1970
1971 m_webViewHelper.reset();
1972 }
1973
1613 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) { 1974 TEST_P(WebViewTest, ExitingDeviceEmulationResetsPageScale) {
1614 registerMockedHttpURLLoad("200-by-300.html"); 1975 registerMockedHttpURLLoad("200-by-300.html");
1615 WebViewImpl* webViewImpl = 1976 WebViewImpl* webViewImpl =
1616 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html"); 1977 m_webViewHelper.initializeAndLoad(m_baseURL + "200-by-300.html");
1617 webViewImpl->resize(WebSize(200, 300)); 1978 webViewImpl->resize(WebSize(200, 300));
1618 1979
1619 float pageScaleExpected = webViewImpl->pageScaleFactor(); 1980 float pageScaleExpected = webViewImpl->pageScaleFactor();
1620 1981
1621 WebDeviceEmulationParams params; 1982 WebDeviceEmulationParams params;
1622 params.screenPosition = WebDeviceEmulationParams::Desktop; 1983 params.screenPosition = WebDeviceEmulationParams::Desktop;
(...skipping 2696 matching lines...) Expand 10 before | Expand all | Expand 10 after
4319 EXPECT_FALSE(frameView->visualViewportSuppliesScrollbars()); 4680 EXPECT_FALSE(frameView->visualViewportSuppliesScrollbars());
4320 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { 4681 if (RuntimeEnabledFeatures::rootLayerScrollingEnabled()) {
4321 EXPECT_NE(nullptr, 4682 EXPECT_NE(nullptr,
4322 frameView->layoutViewportScrollableArea()->verticalScrollbar()); 4683 frameView->layoutViewportScrollableArea()->verticalScrollbar());
4323 } else { 4684 } else {
4324 EXPECT_NE(nullptr, frameView->verticalScrollbar()); 4685 EXPECT_NE(nullptr, frameView->verticalScrollbar());
4325 } 4686 }
4326 } 4687 }
4327 4688
4328 } // namespace blink 4689 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698