Chromium Code Reviews| Index: android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/DropDownListTest.java |
| diff --git a/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/DropDownListTest.java b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/DropDownListTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b5d87ed1b5ebcebeb55f69fe7ff070f2c4091f25 |
| --- /dev/null |
| +++ b/android_webview/tools/automated_ui_tests/javatests/src/org/chromium/webview_ui_test/test/DropDownListTest.java |
| @@ -0,0 +1,156 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.webview_ui_test.test; |
| + |
| +import static android.support.test.espresso.Espresso.onView; |
| +import static android.support.test.espresso.action.ViewActions.click; |
| +import static android.support.test.espresso.matcher.ViewMatchers.withId; |
| +import static android.support.test.espresso.web.assertion.WebViewAssertions.webMatches; |
| +import static android.support.test.espresso.web.sugar.Web.onWebView; |
| +import static android.support.test.espresso.web.webdriver.DriverAtoms.findElement; |
| + |
| +import static org.hamcrest.CoreMatchers.is; |
| +import static org.junit.Assert.assertEquals; |
| + |
| +import android.graphics.Point; |
| +import android.support.test.espresso.web.sugar.Web; |
| +import android.support.test.espresso.web.webdriver.Locator; |
| +import android.test.suitebuilder.annotation.SmallTest; |
| +import android.view.View; |
| +import android.webkit.WebView; |
| + |
| +import org.junit.Before; |
| +import org.junit.Rule; |
| +import org.junit.Test; |
| +import org.junit.runner.RunWith; |
| + |
| +import org.chromium.base.test.BaseJUnit4ClassRunner; |
| +import org.chromium.webview_ui_test.R; |
| +import org.chromium.webview_ui_test.WebViewUiTestActivity; |
| +import org.chromium.webview_ui_test.test.util.UseLayout; |
| +import org.chromium.webview_ui_test.test.util.WebViewUiTestRule; |
| + |
| + |
| +/** |
| + * Tests for WebView ActionMode. |
| + */ |
| +@RunWith(BaseJUnit4ClassRunner.class) |
| +public class DropDownListTest { |
| + @Rule |
| + public WebViewUiTestRule mWebViewActivityRule = new WebViewUiTestRule( |
| + WebViewUiTestActivity.class); |
| + |
| + private static final String HTML_NON_SCALED = "webview_nonscaled.html"; |
| + |
| + private static final String HTML_SCALED = "webview_scaled.html"; |
| + |
|
mikecase (-- gone --)
2016/11/15 00:50:49
nit: remove empty lines btw these constants.
aluo
2016/11/18 00:22:29
Done.
|
| + private static final String HTML_SCROLL = "webview_scroll.html"; |
| + |
| + @Before |
| + public void setUp() { |
| + mWebViewActivityRule.launchActivity(); |
| + onWebView().forceJavascriptEnabled(); |
| + } |
| + |
| + /** |
| + * Test Drop Down List works in ViewPort Scale Factor = 1 |
| + */ |
| + @Test |
| + @SmallTest |
| + @UseLayout("edittext_webview") |
| + public void testDropDownNonScaledViewPort() { |
| + mWebViewActivityRule.loadFileSync(HTML_NON_SCALED, false); |
| + changeAllSelectValues(); |
| + } |
| + |
| + /** |
| + * Test Drop Down List works in ViewPort Scale Factor > 1 |
| + */ |
| + @Test |
| + @SmallTest |
| + @UseLayout("edittext_webview") |
| + public void testDropDownScaledViewPort() { |
| + mWebViewActivityRule.loadFileSync(HTML_SCALED, false); |
| + changeAllSelectValues(); |
| + } |
| + |
| + /** |
| + * Test Drop Down List works in ViewPort Scale Factor > 1 in wideViewPortMode |
| + */ |
| + @Test |
| + @SmallTest |
| + @UseLayout("edittext_webview") |
| + public void testDropDownScaledViewPortUseWideViewPort() { |
| + onView(withId(R.id.webview)).perform(new UseWideViewPortAction()); |
|
the real yoland
2016/11/15 01:45:44
we should follow the Espresso standard of using a
aluo
2016/11/18 00:22:29
Done.
|
| + mWebViewActivityRule.loadFileSync(HTML_SCALED, false); |
| + WebView webView = (WebView) mWebViewActivityRule.getActivity() |
| + .findViewById(R.id.webview); |
| + int w = webView.getWidth(); |
| + int h = webView.getHeight(); |
| + changeSelectValue("select1"); |
| + onView(withId(R.id.webview)).perform(new ScrollByAction(w, 0)); |
|
the real yoland
2016/11/15 01:45:44
Same as above, create scrollHorizontal() and scrol
aluo
2016/11/18 00:22:29
Done.
|
| + changeSelectValue("select2"); |
| + onView(withId(R.id.webview)).perform(new ScrollByAction(0, h)); |
| + changeSelectValue("select3"); |
| + onView(withId(R.id.webview)).perform(new ScrollByAction(-w, 0)); |
| + changeSelectValue("select4"); |
| + } |
| + |
| + /** |
| + * Test that WebView does not scroll when a drop down menu is selected |
| + */ |
| + @Test |
| + @SmallTest |
| + @UseLayout("edittext_webview") |
| + public void testSelectNoScroll() { |
| + mWebViewActivityRule.loadFileSync(HTML_SCROLL, false); |
| + WebView webView = (WebView) mWebViewActivityRule.getActivity() |
| + .findViewById(R.id.webview); |
| + int w = webView.getWidth(); |
| + int h = webView.getHeight(); |
| + onView(withId(R.id.webview)).perform(new ScrollByAction(w, h)); |
| + Point beforeSelectScroll = getScroll((WebView) mWebViewActivityRule |
| + .getActivity().findViewById(R.id.webview)); |
| + changeSelectValue("select"); |
| + Point afterSelectScroll = getScroll((WebView) mWebViewActivityRule |
| + .getActivity().findViewById(R.id.webview)); |
| + assertEquals("Scroll should not move after clicking select element", |
| + beforeSelectScroll, afterSelectScroll); |
| + } |
| + |
| + /** |
| + * get the scroll position of the view |
|
mikecase (-- gone --)
2016/11/15 00:50:49
Nit: Capitalize get
aluo
2016/11/18 00:22:29
Done.
|
| + */ |
| + private Point getScroll(View v) { |
| + int x, y; |
| + x = v.getScrollX(); |
| + y = v.getScrollY(); |
| + return new Point(x, y); |
| + } |
| + |
| + /** |
| + * Change all select box values |
| + */ |
| + private void changeAllSelectValues() { |
| + changeSelectValue("select1"); |
| + changeSelectValue("select2"); |
| + changeSelectValue("select3"); |
| + changeSelectValue("select4"); |
| + } |
| + |
| + /** |
| + * Change select box value from Value1 to Value2 |
| + */ |
| + private void changeSelectValue(String id) { |
| + Web.WebInteraction<Void> selectElement = |
|
the real yoland
2016/11/15 01:45:44
maybe something like this:
```
onWebView()
aluo
2016/11/18 00:22:29
Not sure what the suggestion here?
The line "onV
|
| + onWebView().withElement(findElement(Locator.ID, id)); |
| + selectElement.check(webMatches(DropDownListUtils.getCurrentSelection(), |
| + is("Value1"))); |
| + selectElement.perform(DropDownListUtils.selectAction()); |
|
the real yoland
2016/11/15 01:45:44
I assume this is because webClick() doesn't work h
aluo
2016/11/18 00:22:30
correct
|
| + DropDownListUtils.getSelectItem("Value2").perform(click()); |
|
the real yoland
2016/11/15 01:45:44
Value2 shouldn't be hardcoded here, maybe make the
aluo
2016/11/18 00:22:30
Done.
|
| + selectElement.check(webMatches(DropDownListUtils.getCurrentSelection(), |
| + is("Value2"))); |
| + } |
| +} |