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

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

Issue 2831823003: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: fix findbug issues Created 3 years, 8 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.input; 5 package org.chromium.chrome.browser.input;
6 6
7 import android.support.test.InstrumentationRegistry;
7 import android.support.test.filters.LargeTest; 8 import android.support.test.filters.LargeTest;
8 9
10 import org.junit.Assert;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14
9 import org.chromium.base.ThreadUtils; 15 import org.chromium.base.ThreadUtils;
16 import org.chromium.base.test.util.CommandLineFlags;
10 import org.chromium.base.test.util.Feature; 17 import org.chromium.base.test.util.Feature;
11 import org.chromium.base.test.util.RetryOnFailure; 18 import org.chromium.base.test.util.RetryOnFailure;
12 import org.chromium.base.test.util.UrlUtils; 19 import org.chromium.base.test.util.UrlUtils;
13 import org.chromium.chrome.browser.ChromeActivity; 20 import org.chromium.chrome.browser.ChromeActivity;
21 import org.chromium.chrome.browser.ChromeSwitches;
14 import org.chromium.chrome.browser.WebContentsFactory; 22 import org.chromium.chrome.browser.WebContentsFactory;
15 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 23 import org.chromium.chrome.test.ChromeActivityTestRule;
24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
16 import org.chromium.content.browser.ContentView; 25 import org.chromium.content.browser.ContentView;
17 import org.chromium.content.browser.ContentViewCore; 26 import org.chromium.content.browser.ContentViewCore;
18 import org.chromium.content.browser.test.util.Criteria; 27 import org.chromium.content.browser.test.util.Criteria;
19 import org.chromium.content.browser.test.util.CriteriaHelper; 28 import org.chromium.content.browser.test.util.CriteriaHelper;
20 import org.chromium.content.browser.test.util.DOMUtils; 29 import org.chromium.content.browser.test.util.DOMUtils;
21 import org.chromium.content_public.browser.WebContents; 30 import org.chromium.content_public.browser.WebContents;
22 import org.chromium.ui.base.ActivityWindowAndroid; 31 import org.chromium.ui.base.ActivityWindowAndroid;
23 import org.chromium.ui.base.ViewAndroidDelegate; 32 import org.chromium.ui.base.ViewAndroidDelegate;
24 import org.chromium.ui.base.WindowAndroid; 33 import org.chromium.ui.base.WindowAndroid;
25 34
26 /** 35 /**
27 * Test the select popup and how it interacts with another ContentViewCore. 36 * Test the select popup and how it interacts with another ContentViewCore.
28 */ 37 */
29 public class SelectPopupOtherContentViewTest extends ChromeActivityTestCaseBase< ChromeActivity> { 38 @RunWith(ChromeJUnit4ClassRunner.class)
39 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
40 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
41 public class SelectPopupOtherContentViewTest {
42 @Rule
43 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
44 new ChromeActivityTestRule<>(ChromeActivity.class);
45
30 private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri( 46 private static final String SELECT_URL = UrlUtils.encodeHtmlDataUri(
31 "<html><body>" 47 "<html><body>"
32 + "Which animal is the strongest:<br/>" 48 + "Which animal is the strongest:<br/>"
33 + "<select id=\"select\">" 49 + "<select id=\"select\">"
34 + "<option>Black bear</option>" 50 + "<option>Black bear</option>"
35 + "<option>Polar bear</option>" 51 + "<option>Polar bear</option>"
36 + "<option>Grizzly</option>" 52 + "<option>Grizzly</option>"
37 + "<option>Tiger</option>" 53 + "<option>Tiger</option>"
38 + "<option>Lion</option>" 54 + "<option>Lion</option>"
39 + "<option>Gorilla</option>" 55 + "<option>Gorilla</option>"
40 + "<option>Chipmunk</option>" 56 + "<option>Chipmunk</option>"
41 + "</select>" 57 + "</select>"
42 + "</body></html>"); 58 + "</body></html>");
43 59
44 private class PopupShowingCriteria extends Criteria { 60 private class PopupShowingCriteria extends Criteria {
45 public PopupShowingCriteria() { 61 public PopupShowingCriteria() {
46 super("The select popup did not show up on click."); 62 super("The select popup did not show up on click.");
47 } 63 }
48 64
49 @Override 65 @Override
50 public boolean isSatisfied() { 66 public boolean isSatisfied() {
51 ContentViewCore contentViewCore = getActivity().getCurrentContentVie wCore(); 67 ContentViewCore contentViewCore =
68 mActivityTestRule.getActivity().getCurrentContentViewCore();
52 return contentViewCore.getSelectPopupForTest() != null; 69 return contentViewCore.getSelectPopupForTest() != null;
53 } 70 }
54 } 71 }
55 72
56 public SelectPopupOtherContentViewTest() {
57 super(ChromeActivity.class);
58 }
59
60 @Override
61 public void startMainActivity() throws InterruptedException {
62 // Don't launch activity automatically.
63 }
64
65 /** 73 /**
66 * Tests that the showing select popup does not get closed because an unrela ted ContentView 74 * Tests that the showing select popup does not get closed because an unrela ted ContentView
67 * gets destroyed. 75 * gets destroyed.
68 * 76 *
69 */ 77 */
78 @Test
70 @LargeTest 79 @LargeTest
71 @Feature({"Browser"}) 80 @Feature({"Browser"})
72 @RetryOnFailure 81 @RetryOnFailure
73 public void testPopupNotClosedByOtherContentView() 82 public void testPopupNotClosedByOtherContentView()
74 throws InterruptedException, Exception, Throwable { 83 throws InterruptedException, Exception, Throwable {
75 // Load the test page. 84 // Load the test page.
76 startMainActivityWithURL(SELECT_URL); 85 mActivityTestRule.startMainActivityWithURL(SELECT_URL);
77 86
78 final ContentViewCore viewCore = getActivity().getCurrentContentViewCore (); 87 final ContentViewCore viewCore =
88 mActivityTestRule.getActivity().getCurrentContentViewCore();
79 89
80 // Once clicked, the popup should show up. 90 // Once clicked, the popup should show up.
81 DOMUtils.clickNode(viewCore, "select"); 91 DOMUtils.clickNode(viewCore, "select");
82 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria()); 92 CriteriaHelper.pollInstrumentationThread(new PopupShowingCriteria());
83 93
84 // Now create and destroy a different ContentView. 94 // Now create and destroy a different ContentView.
85 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 95 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
86 @Override 96 @Override
87 public void run() { 97 public void run() {
88 WebContents webContents = WebContentsFactory.createWebContents(f alse, false); 98 WebContents webContents = WebContentsFactory.createWebContents(f alse, false);
89 WindowAndroid windowAndroid = new ActivityWindowAndroid(getActiv ity()); 99 WindowAndroid windowAndroid =
100 new ActivityWindowAndroid(mActivityTestRule.getActivity( ));
90 101
91 ContentViewCore contentViewCore = new ContentViewCore(getActivit y(), ""); 102 ContentViewCore contentViewCore =
92 ContentView cv = ContentView.createContentView(getActivity(), co ntentViewCore); 103 new ContentViewCore(mActivityTestRule.getActivity(), "") ;
104 ContentView cv = ContentView.createContentView(
105 mActivityTestRule.getActivity(), contentViewCore);
93 contentViewCore.initialize(ViewAndroidDelegate.createBasicDelega te(cv), cv, 106 contentViewCore.initialize(ViewAndroidDelegate.createBasicDelega te(cv), cv,
94 webContents, windowAndroid); 107 webContents, windowAndroid);
95 contentViewCore.destroy(); 108 contentViewCore.destroy();
96 } 109 }
97 }); 110 });
98 111
99 // Process some more events to give a chance to the dialog to hide if it were to. 112 // Process some more events to give a chance to the dialog to hide if it were to.
100 getInstrumentation().waitForIdleSync(); 113 InstrumentationRegistry.getInstrumentation().waitForIdleSync();
101 114
102 // The popup should still be shown. 115 // The popup should still be shown.
103 assertNotNull("The select popup got hidden by destroying of unrelated Co ntentViewCore.", 116 Assert.assertNotNull(
117 "The select popup got hidden by destroying of unrelated ContentV iewCore.",
104 viewCore.getSelectPopupForTest()); 118 viewCore.getSelectPopupForTest());
105 } 119 }
106 } 120 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698