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

Unified Diff: chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/TabStripUtils.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/PrerenderTestHelper.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/TabStripUtils.java
diff --git a/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/TabStripUtils.java b/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/TabStripUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..8f8f96fcbb3651bd383e269bc2954b1aa885efda
--- /dev/null
+++ b/chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/TabStripUtils.java
@@ -0,0 +1,134 @@
+// Copyright 2015 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.chrome.test.util;
+
+import android.view.View;
+
+import org.chromium.chrome.browser.ChromeTabbedActivity;
+import org.chromium.chrome.browser.compositor.layouts.components.CompositorButton;
+import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutHelper;
+import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutHelperManager;
+import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutTab;
+import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+import org.chromium.content.browser.test.util.TestTouchUtils;
+
+/**
+ * A utility class that contains methods generic to all TabStrip test classes.
+ */
+public class TabStripUtils {
+
+ /**
+ * @param activity The main activity that contains the TabStrips.
+ * @param incognito Whether or not the TabStrip should be from the incognito or normal model.
+ * @return The TabStrip for the specified model.
+ */
+ public static StripLayoutHelper getStripLayoutHelper(ChromeTabbedActivity activity,
+ boolean incognito) {
+ StripLayoutHelperManager manager = getStripLayoutHelperManager(activity);
+ if (manager != null) {
+ return manager.getStripLayoutHelper(incognito);
+ }
+ return null;
+ }
+
+ /**
+ * @param activity The main activity that contains the TabStrips.
+ * @return The TabStrip for the specified model.
+ */
+ public static StripLayoutHelper getActiveStripLayoutHelper(ChromeTabbedActivity activity) {
+ StripLayoutHelperManager manager = getStripLayoutHelperManager(activity);
+ if (manager != null) {
+ return manager.getActiveStripLayoutHelper();
+ }
+ return null;
+ }
+
+ /**
+ * @param activity The main activity that contains the TabStrips.
+ * @return The TabStrip for the specified model.
+ */
+ public static StripLayoutHelperManager getStripLayoutHelperManager(
+ ChromeTabbedActivity activity) {
+ StripLayoutHelperManager manager =
+ activity.getLayoutManager().getStripLayoutHelperManager();
+ return manager;
+ }
+
+ /**
+ * Finds a TabView from a TabStrip based on a Tab id.
+ * @param activity The main activity that contains the TabStrips.
+ * @param incognito Whether or not to use the incognito strip or the nromal strip.
+ * @param id The Tab id to look for.
+ * @return The TabView that represents the Tab identified by the id. Null if not found.
+ */
+ public static StripLayoutTab findStripLayoutTab(ChromeTabbedActivity activity,
+ boolean incognito, int id) {
+ StripLayoutHelper strip = getStripLayoutHelper(activity, incognito);
+ return strip.findTabById(id);
+ }
+
+ /**
+ * Click a compositor tab strip tab;
+ * @param tab The tab to click.
+ * @param base The ChromeTabbedActivityTestBase where we're calling this from.
+ */
+ public static void clickTab(StripLayoutTab tab, ChromeTabbedActivityTestBase base) {
+ View view = base.getActivity().getTabsView();
+ final float x = tab.getDrawX() + tab.getWidth() / 2;
+ final float y = tab.getDrawY() + tab.getHeight() / 2;
+ TestTouchUtils.singleClickView(base.getInstrumentation(), view, (int) x, (int) y);
+ }
+
+ /**
+ * Click a compositor button;
+ * @param button The button to click.
+ * @param base The ChromeTabbedActivityTestBase where we're calling this from.
+ */
+ public static void clickCompositorButton(CompositorButton button,
+ ChromeTabbedActivityTestBase base) {
+ final StripLayoutHelperManager manager = getStripLayoutHelperManager(base.getActivity());
+ final float x = button.getX() + button.getWidth() / 2;
+ final float y = button.getY() + button.getHeight() / 2;
+ base.getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ manager.click(0, x, y);
+ }
+ });
+ }
+
+ /**
+ * Long press a compositor button.
+ * @param button The button to long press.
+ * @param base The ChromeTabbedActivityTestBase where we're calling this from.
+ */
+ public static void longPressCompositorButton(CompositorButton button,
+ ChromeTabbedActivityTestBase base) {
+ final StripLayoutHelperManager manager = getStripLayoutHelperManager(base.getActivity());
+ final float x = button.getX() + button.getWidth() / 2;
+ final float y = button.getY() + button.getHeight() / 2;
+ base.getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ manager.onLongPress(0, x, y);
+ }
+ });
+ }
+
+ /**
+ * @param tabStrip The tab strip to wait for.
+ */
+ public static void settleDownCompositor(final StripLayoutHelper tabStrip) throws
+ InterruptedException {
+ CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return !tabStrip.isAnimating();
+ }
+ });
+ }
+}
« no previous file with comments | « chrome/test/android/javatests_staging/src/org/chromium/chrome/test/util/PrerenderTestHelper.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698