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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/FocusedEditableTextFieldZoomTest.java

Issue 2858933002: Reland: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: Patch takes out flaky tests 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 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser; 5 package org.chromium.chrome.browser;
6 6
7 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL ING_INTERVAL; 7 import static org.chromium.content.browser.test.util.CriteriaHelper.DEFAULT_POLL ING_INTERVAL;
8 8
9 import android.support.test.InstrumentationRegistry;
9 import android.view.KeyEvent; 10 import android.view.KeyEvent;
10 11
12 import org.junit.After;
13 import org.junit.Before;
14 import org.junit.Rule;
15 import org.junit.Test;
16 import org.junit.runner.RunWith;
17
18 import org.chromium.base.test.util.CommandLineFlags;
11 import org.chromium.base.test.util.DisabledTest; 19 import org.chromium.base.test.util.DisabledTest;
12 import org.chromium.base.test.util.Feature; 20 import org.chromium.base.test.util.Feature;
13 import org.chromium.chrome.browser.tab.Tab; 21 import org.chromium.chrome.browser.tab.Tab;
14 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 22 import org.chromium.chrome.test.ChromeActivityTestRule;
23 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
15 import org.chromium.content.browser.ContentViewCore; 24 import org.chromium.content.browser.ContentViewCore;
16 import org.chromium.content.browser.test.util.Criteria; 25 import org.chromium.content.browser.test.util.Criteria;
17 import org.chromium.content.browser.test.util.CriteriaHelper; 26 import org.chromium.content.browser.test.util.CriteriaHelper;
18 import org.chromium.content.browser.test.util.DOMUtils; 27 import org.chromium.content.browser.test.util.DOMUtils;
19 import org.chromium.content.browser.test.util.KeyUtils; 28 import org.chromium.content.browser.test.util.KeyUtils;
20 import org.chromium.net.test.EmbeddedTestServer; 29 import org.chromium.net.test.EmbeddedTestServer;
21 30
22 /** 31 /**
23 * Tests for zooming into & out of a selected & deselected editable text field. 32 * Tests for zooming into & out of a selected & deselected editable text field.
24 */ 33 */
25 public class FocusedEditableTextFieldZoomTest extends ChromeActivityTestCaseBase <ChromeActivity> { 34 @RunWith(ChromeJUnit4ClassRunner.class)
35 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
36 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
37 public class FocusedEditableTextFieldZoomTest {
38 @Rule
39 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
40 new ChromeActivityTestRule<>(ChromeActivity.class);
41
26 private static final int TEST_TIMEOUT = 5000; 42 private static final int TEST_TIMEOUT = 5000;
27 private static final String TEXTFIELD_DOM_ID = "textfield"; 43 private static final String TEXTFIELD_DOM_ID = "textfield";
28 private static final float FLOAT_DELTA = 0.01f; 44 private static final float FLOAT_DELTA = 0.01f;
29 private static final float INITIAL_SCALE = 0.5f; 45 private static final float INITIAL_SCALE = 0.5f;
30 46
31 private EmbeddedTestServer mTestServer; 47 private EmbeddedTestServer mTestServer;
32 48
33 public FocusedEditableTextFieldZoomTest() { 49 @Before
34 super(ChromeActivity.class); 50 public void setUp() throws Exception {
51 mTestServer = EmbeddedTestServer.createAndStartServer(
52 InstrumentationRegistry.getInstrumentation().getContext());
53 mActivityTestRule.startMainActivityWithURL(
54 mTestServer.getURL("/chrome/test/data/android/focused_editable_z oom.html"));
55 waitForInitialZoom();
35 } 56 }
36 57
37 @Override 58 @After
38 protected void setUp() throws Exception { 59 public void tearDown() throws Exception {
39 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext());
40 super.setUp();
41 }
42
43 @Override
44 protected void tearDown() throws Exception {
45 mTestServer.stopAndDestroyServer(); 60 mTestServer.stopAndDestroyServer();
46 super.tearDown();
47 } 61 }
48 62
49 void waitForInitialZoom() { 63 void waitForInitialZoom() {
50 // The zoom level sometimes changes immediately after the page loads whi ch makes grabbing 64 // The zoom level sometimes changes immediately after the page loads whi ch makes grabbing
51 // the initial value problematic. We solve this by explicitly specifying the initial zoom 65 // the initial value problematic. We solve this by explicitly specifying the initial zoom
52 // level via the viewport tag and waiting for the zoom level to reach th at value before we 66 // level via the viewport tag and waiting for the zoom level to reach th at value before we
53 // proceed with the rest of the test. 67 // proceed with the rest of the test.
54 final ContentViewCore contentViewCore = getActivity().getActivityTab().g etContentViewCore(); 68 final ContentViewCore contentViewCore =
69 mActivityTestRule.getActivity().getActivityTab().getContentViewC ore();
55 CriteriaHelper.pollInstrumentationThread(new Criteria() { 70 CriteriaHelper.pollInstrumentationThread(new Criteria() {
56 @Override 71 @Override
57 public boolean isSatisfied() { 72 public boolean isSatisfied() {
58 return contentViewCore.getScale() - INITIAL_SCALE < FLOAT_DELTA; 73 return contentViewCore.getScale() - INITIAL_SCALE < FLOAT_DELTA;
59 } 74 }
60 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL); 75 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL);
61 } 76 }
62 77
63 private void waitForZoomIn(final ContentViewCore contentViewCore, 78 private void waitForZoomIn(final ContentViewCore contentViewCore,
64 final float initialZoomLevel) { 79 final float initialZoomLevel) {
65 CriteriaHelper.pollInstrumentationThread(new Criteria() { 80 CriteriaHelper.pollInstrumentationThread(new Criteria() {
66 @Override 81 @Override
67 public boolean isSatisfied() { 82 public boolean isSatisfied() {
68 return contentViewCore.getScale() > initialZoomLevel; 83 return contentViewCore.getScale() > initialZoomLevel;
69 } 84 }
70 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL); 85 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL);
71 } 86 }
72 87
73 /* 88 /*
74 * @LargeTest 89 * @LargeTest
75 */ 90 */
91 @Test
76 @DisabledTest(message = "Broken by subpixel precision changes crbug.com/3711 19") 92 @DisabledTest(message = "Broken by subpixel precision changes crbug.com/3711 19")
77 @Feature({"TabContents"}) 93 @Feature({"TabContents"})
78 public void testZoomInToSelected() throws Throwable { 94 public void testZoomInToSelected() throws Throwable {
79 // This should focus the text field and initiate a zoom in. 95 // This should focus the text field and initiate a zoom in.
80 Tab tab = getActivity().getActivityTab(); 96 Tab tab = mActivityTestRule.getActivity().getActivityTab();
81 final ContentViewCore contentViewCore = tab.getContentViewCore(); 97 final ContentViewCore contentViewCore = tab.getContentViewCore();
82 float initialZoomLevel = contentViewCore.getScale(); 98 float initialZoomLevel = contentViewCore.getScale();
83 99
84 DOMUtils.clickNode(contentViewCore, TEXTFIELD_DOM_ID); 100 DOMUtils.clickNode(contentViewCore, TEXTFIELD_DOM_ID);
85 101
86 // Wait for the zoom in to complete. 102 // Wait for the zoom in to complete.
87 waitForZoomIn(contentViewCore, initialZoomLevel); 103 waitForZoomIn(contentViewCore, initialZoomLevel);
88 } 104 }
89 105
90 /* 106 /*
91 * @LargeTest 107 * @LargeTest
92 */ 108 */
109 @Test
93 @DisabledTest(message = "Broken by subpixel precision changes crbug.com/3711 19") 110 @DisabledTest(message = "Broken by subpixel precision changes crbug.com/3711 19")
94 @Feature({"TabContents"}) 111 @Feature({"TabContents"})
95 public void testZoomOutOfSelectedIfOnlyBackPressed() throws Throwable { 112 public void testZoomOutOfSelectedIfOnlyBackPressed() throws Throwable {
96 final Tab tab = getActivity().getActivityTab(); 113 final Tab tab = mActivityTestRule.getActivity().getActivityTab();
97 final ContentViewCore contentViewCore = tab.getContentViewCore(); 114 final ContentViewCore contentViewCore = tab.getContentViewCore();
98 final float initialZoomLevel = contentViewCore.getScale(); 115 final float initialZoomLevel = contentViewCore.getScale();
99 116
100 // This should focus the text field and initiate a zoom in. 117 // This should focus the text field and initiate a zoom in.
101 DOMUtils.clickNode(contentViewCore, TEXTFIELD_DOM_ID); 118 DOMUtils.clickNode(contentViewCore, TEXTFIELD_DOM_ID);
102 119
103 // Wait for the zoom in to complete. 120 // Wait for the zoom in to complete.
104 waitForZoomIn(contentViewCore, initialZoomLevel); 121 waitForZoomIn(contentViewCore, initialZoomLevel);
105 122
106 KeyUtils.singleKeyEventView(getInstrumentation(), tab.getView(), KeyEven t.KEYCODE_BACK); 123 KeyUtils.singleKeyEventView(
124 InstrumentationRegistry.getInstrumentation(), tab.getView(), Key Event.KEYCODE_BACK);
107 125
108 // We should zoom out to the previous zoom level. 126 // We should zoom out to the previous zoom level.
109 CriteriaHelper.pollInstrumentationThread(new Criteria() { 127 CriteriaHelper.pollInstrumentationThread(new Criteria() {
110 @Override 128 @Override
111 public boolean isSatisfied() { 129 public boolean isSatisfied() {
112 return (contentViewCore.getScale() - initialZoomLevel) < FLOAT_D ELTA; 130 return (contentViewCore.getScale() - initialZoomLevel) < FLOAT_D ELTA;
113 } 131 }
114 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL); 132 }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL);
115 } 133 }
116
117 @Override
118 public void startMainActivity() throws InterruptedException {
119 startMainActivityWithURL(mTestServer.getURL(
120 "/chrome/test/data/android/focused_editable_zoom.html"));
121 waitForInitialZoom();
122 }
123 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698