OLD | NEW |
(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.util; |
| 6 |
| 7 import android.view.View; |
| 8 |
| 9 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 10 import org.chromium.chrome.browser.compositor.layouts.components.CompositorButto
n; |
| 11 import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutHelper; |
| 12 import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutHelperMa
nager; |
| 13 import org.chromium.chrome.browser.compositor.overlays.strip.StripLayoutTab; |
| 14 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
| 15 import org.chromium.content.browser.test.util.Criteria; |
| 16 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 17 import org.chromium.content.browser.test.util.TestTouchUtils; |
| 18 |
| 19 /** |
| 20 * A utility class that contains methods generic to all TabStrip test classes. |
| 21 */ |
| 22 public class TabStripUtils { |
| 23 |
| 24 /** |
| 25 * @param activity The main activity that contains the TabStrips. |
| 26 * @param incognito Whether or not the TabStrip should be from the incognito
or normal model. |
| 27 * @return The TabStrip for the specified model. |
| 28 */ |
| 29 public static StripLayoutHelper getStripLayoutHelper(ChromeTabbedActivity ac
tivity, |
| 30 boolean incognito) { |
| 31 StripLayoutHelperManager manager = getStripLayoutHelperManager(activity)
; |
| 32 if (manager != null) { |
| 33 return manager.getStripLayoutHelper(incognito); |
| 34 } |
| 35 return null; |
| 36 } |
| 37 |
| 38 /** |
| 39 * @param activity The main activity that contains the TabStrips. |
| 40 * @return The TabStrip for the specified model. |
| 41 */ |
| 42 public static StripLayoutHelper getActiveStripLayoutHelper(ChromeTabbedActiv
ity activity) { |
| 43 StripLayoutHelperManager manager = getStripLayoutHelperManager(activity)
; |
| 44 if (manager != null) { |
| 45 return manager.getActiveStripLayoutHelper(); |
| 46 } |
| 47 return null; |
| 48 } |
| 49 |
| 50 /** |
| 51 * @param activity The main activity that contains the TabStrips. |
| 52 * @return The TabStrip for the specified model. |
| 53 */ |
| 54 public static StripLayoutHelperManager getStripLayoutHelperManager( |
| 55 ChromeTabbedActivity activity) { |
| 56 StripLayoutHelperManager manager = |
| 57 activity.getLayoutManager().getStripLayoutHelperManager(); |
| 58 return manager; |
| 59 } |
| 60 |
| 61 /** |
| 62 * Finds a TabView from a TabStrip based on a Tab id. |
| 63 * @param activity The main activity that contains the TabStrips. |
| 64 * @param incognito Whether or not to use the incognito strip or the nromal
strip. |
| 65 * @param id The Tab id to look for. |
| 66 * @return The TabView that represents the Tab identified by the id. Null i
f not found. |
| 67 */ |
| 68 public static StripLayoutTab findStripLayoutTab(ChromeTabbedActivity activit
y, |
| 69 boolean incognito, int id) { |
| 70 StripLayoutHelper strip = getStripLayoutHelper(activity, incognito); |
| 71 return strip.findTabById(id); |
| 72 } |
| 73 |
| 74 /** |
| 75 * Click a compositor tab strip tab; |
| 76 * @param tab The tab to click. |
| 77 * @param base The ChromeTabbedActivityTestBase where we're calling this fro
m. |
| 78 */ |
| 79 public static void clickTab(StripLayoutTab tab, ChromeTabbedActivityTestBase
base) { |
| 80 View view = base.getActivity().getTabsView(); |
| 81 final float x = tab.getDrawX() + tab.getWidth() / 2; |
| 82 final float y = tab.getDrawY() + tab.getHeight() / 2; |
| 83 TestTouchUtils.singleClickView(base.getInstrumentation(), view, (int) x,
(int) y); |
| 84 } |
| 85 |
| 86 /** |
| 87 * Click a compositor button; |
| 88 * @param button The button to click. |
| 89 * @param base The ChromeTabbedActivityTestBase where we're calling this fro
m. |
| 90 */ |
| 91 public static void clickCompositorButton(CompositorButton button, |
| 92 ChromeTabbedActivityTestBase base) { |
| 93 final StripLayoutHelperManager manager = getStripLayoutHelperManager(bas
e.getActivity()); |
| 94 final float x = button.getX() + button.getWidth() / 2; |
| 95 final float y = button.getY() + button.getHeight() / 2; |
| 96 base.getInstrumentation().runOnMainSync(new Runnable() { |
| 97 @Override |
| 98 public void run() { |
| 99 manager.click(0, x, y); |
| 100 } |
| 101 }); |
| 102 } |
| 103 |
| 104 /** |
| 105 * Long press a compositor button. |
| 106 * @param button The button to long press. |
| 107 * @param base The ChromeTabbedActivityTestBase where we're calling this fro
m. |
| 108 */ |
| 109 public static void longPressCompositorButton(CompositorButton button, |
| 110 ChromeTabbedActivityTestBase base) { |
| 111 final StripLayoutHelperManager manager = getStripLayoutHelperManager(bas
e.getActivity()); |
| 112 final float x = button.getX() + button.getWidth() / 2; |
| 113 final float y = button.getY() + button.getHeight() / 2; |
| 114 base.getInstrumentation().runOnMainSync(new Runnable() { |
| 115 @Override |
| 116 public void run() { |
| 117 manager.onLongPress(0, x, y); |
| 118 } |
| 119 }); |
| 120 } |
| 121 |
| 122 /** |
| 123 * @param tabStrip The tab strip to wait for. |
| 124 */ |
| 125 public static void settleDownCompositor(final StripLayoutHelper tabStrip) th
rows |
| 126 InterruptedException { |
| 127 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 128 @Override |
| 129 public boolean isSatisfied() { |
| 130 return !tabStrip.isAnimating(); |
| 131 } |
| 132 }); |
| 133 } |
| 134 } |
OLD | NEW |