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

Side by Side Diff: chrome/test/android/javatests_staging/src/org/chromium/chrome/test/ChromeTabbedActivityTestBase.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.test;
6
7 import android.app.Activity;
8 import android.app.Instrumentation;
9 import android.content.Intent;
10 import android.text.TextUtils;
11 import android.util.Log;
12 import android.view.View;
13
14 import org.chromium.base.test.util.CommandLineFlags;
15 import org.chromium.chrome.browser.ChromeSwitches;
16 import org.chromium.chrome.browser.ChromeTabbedActivity;
17 import org.chromium.chrome.browser.EmptyTabObserver;
18 import org.chromium.chrome.browser.Tab;
19 import org.chromium.chrome.browser.tab.ChromeTab;
20 import org.chromium.chrome.browser.tabmodel.EmptyTabModelObserver;
21 import org.chromium.chrome.browser.tabmodel.TabModel;
22 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
23 import org.chromium.chrome.browser.tabmodel.TabModelUtils;
24 import org.chromium.content.browser.test.util.CallbackHelper;
25 import org.chromium.content.browser.test.util.TestTouchUtils;
26
27 import java.util.concurrent.TimeoutException;
28
29 /**
30 * The base class of the ChromeTabbedActivity specific tests. It provides the co mmon methods
31 * to access the ChromeTabbedActivity UI.
32 */
33 @CommandLineFlags.Add(ChromeSwitches.DISABLE_DOCUMENT_MODE)
34 public abstract class ChromeTabbedActivityTestBase extends
35 ChromeActivityTestCaseBase<ChromeTabbedActivity> {
36 private static final String TAG = "ChromeTabbedActivityTestBase";
37
38 public ChromeTabbedActivityTestBase() {
39 super(ChromeTabbedActivity.class);
40 }
41
42 /**
43 * Load a url in multiple new tabs in parallel. Each {@link ChromeTab} will pretend to be
44 * created from a link.
45 *
46 * @param url The url of the page to load.
47 * @param numTabs The number of tabs to open.
48 */
49 public void loadUrlInManyNewTabs(final String url, final int numTabs)
50 throws InterruptedException {
51 final CallbackHelper[] pageLoadedCallbacks = new CallbackHelper[numTabs] ;
52 final int[] tabIds = new int[numTabs];
53 for (int i = 0; i < numTabs; ++i) {
54 final int index = i;
55 getInstrumentation().runOnMainSync(new Runnable() {
56 @Override
57 public void run() {
58 Tab currentTab = getActivity().getCurrentTabCreator().launch Url(
59 url, TabLaunchType.FROM_LINK);
60 final CallbackHelper pageLoadCallback = new CallbackHelper() ;
61 pageLoadedCallbacks[index] = pageLoadCallback;
62 currentTab.addObserver(new EmptyTabObserver() {
63 @Override
64 public void onPageLoadFinished(Tab tab) {
65 pageLoadCallback.notifyCalled();
66 tab.removeObserver(this);
67 }
68 });
69 tabIds[index] = currentTab.getId();
70 }
71 });
72 }
73 // When opening many tabs some may be frozen due to memory pressure and won't send
74 // PAGE_LOAD_FINISHED events. Iterate over the newly opened tabs and wa it for each to load.
75 for (int i = 0; i < numTabs; ++i) {
76 final TabModel tabModel = getActivity().getCurrentTabModel();
77 final Tab tab = TabModelUtils.getTabById(tabModel, tabIds[i]);
78 getInstrumentation().runOnMainSync(new Runnable() {
79 @Override
80 public void run() {
81 TabModelUtils.setIndex(tabModel, tabModel.indexOf(tab));
82 }
83 });
84 try {
85 pageLoadedCallbacks[i].waitForCallback(0);
86 } catch (TimeoutException e) {
87 fail(String.format("PAGE_LOAD_FINISHED was not received for tabI d=%d", tabIds[i]));
88 }
89 }
90 }
91
92 @Override
93 protected void startActivityCompletely(Intent intent) {
94 Instrumentation.ActivityMonitor monitor = getInstrumentation().addMonito r(
95 ChromeTabbedActivity.class.getName(), null, false);
96 Activity activity = getInstrumentation().startActivitySync(intent);
97 assertNotNull("Main activity did not start", activity);
98 ChromeTabbedActivity tabbedActivity = (ChromeTabbedActivity)
99 monitor.waitForActivityWithTimeout(ACTIVITY_START_TIMEOUT_MS);
100 assertNotNull("ChromeTabbedActivity did not start", tabbedActivity);
101 setActivity(tabbedActivity);
102 Log.d(TAG, "startActivityCompletely <<");
103 }
104
105 /**
106 * Long presses the view, selects an item from the context menu, and
107 * asserts that a new tab is opened and is incognito iff expectIncognito is true.
108 * @param view The View to long press.
109 * @param contextMenuItemId The context menu item to select on the view.
110 * @param expectIncognito Whether the opened tab is expected to be incognito .
111 * @param expectedUrl The expected url for the new tab.
112 */
113 protected void invokeContextMenuAndOpenInANewTab(View view, int contextMenuI temId,
114 boolean expectIncognito, final String expectedUrl) throws Interrupte dException {
115 final CallbackHelper createdCallback = new CallbackHelper();
116 final TabModel tabModel = getActivity().getTabModelSelector().getModel(e xpectIncognito);
117 tabModel.addObserver(new EmptyTabModelObserver() {
118 @Override
119 public void didAddTab(Tab tab, TabLaunchType type) {
120 if (TextUtils.equals(expectedUrl, tab.getUrl())) {
121 createdCallback.notifyCalled();
122 tabModel.removeObserver(this);
123 }
124 }
125 });
126
127 TestTouchUtils.longClickView(getInstrumentation(), view);
128 assertTrue(getInstrumentation().invokeContextMenuAction(getActivity(),
129 contextMenuItemId, 0));
130
131 try {
132 createdCallback.waitForCallback(0);
133 } catch (TimeoutException e) {
134 fail("Never received tab creation event");
135 }
136 }
137 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698