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

Side by Side Diff: chrome/test/android/javatests/src/org/chromium/chrome/test/BottomSheetTestCaseBase.java

Issue 2698613006: [Home] Add lifecycle events and some tests (Closed)
Patch Set: fix previous patch Created 3 years, 10 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
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/widget/BottomSheetObserverTest.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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.test; 5 package org.chromium.chrome.test;
6 6
7 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_P HONE; 7 import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_P HONE;
8 8
9 import org.chromium.base.ThreadUtils; 9 import org.chromium.base.ThreadUtils;
10 import org.chromium.base.test.util.CommandLineFlags; 10 import org.chromium.base.test.util.CommandLineFlags;
11 import org.chromium.base.test.util.Restriction; 11 import org.chromium.base.test.util.Restriction;
12 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; 12 import org.chromium.chrome.browser.preferences.ChromePreferenceManager;
13 import org.chromium.chrome.browser.widget.BottomSheet; 13 import org.chromium.chrome.browser.widget.BottomSheet;
14 import org.chromium.chrome.browser.widget.BottomSheet.BottomSheetContent; 14 import org.chromium.chrome.browser.widget.BottomSheet.BottomSheetContent;
15 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; 15 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils;
16 16
17 /** 17 /**
18 * Base class for instrumentation tests using the bottom sheet. 18 * Base class for instrumentation tests using the bottom sheet.
19 */ 19 */
20 @CommandLineFlags.Add({"enable-features=ChromeHome"}) 20 @CommandLineFlags.Add({"enable-features=ChromeHome"})
21 @Restriction(RESTRICTION_TYPE_PHONE) // ChromeHome is only enabled on phones 21 @Restriction(RESTRICTION_TYPE_PHONE) // ChromeHome is only enabled on phones
22 public abstract class BottomSheetTestCaseBase extends ChromeTabbedActivityTestBa se { 22 public abstract class BottomSheetTestCaseBase extends ChromeTabbedActivityTestBa se {
23 /** A handle to the bottom sheet. */
24 protected BottomSheet mBottomSheet;
25
23 private boolean mOldChromeHomeFlagValue; 26 private boolean mOldChromeHomeFlagValue;
24 @Override 27 @Override
25 protected void setUp() throws Exception { 28 protected void setUp() throws Exception {
26 // TODO(dgn,mdjones): Chrome restarts when the ChromeHome feature flag v alue changes. That 29 // TODO(dgn,mdjones): Chrome restarts when the ChromeHome feature flag v alue changes. That
27 // crashes the test so we need to manually set the preference to match t he flag before 30 // crashes the test so we need to manually set the preference to match t he flag before
28 // Chrome initialises via super.setUp() 31 // Chrome initialises via super.setUp()
29 ChromePreferenceManager prefManager = ChromePreferenceManager.getInstanc e(); 32 ChromePreferenceManager prefManager = ChromePreferenceManager.getInstanc e();
30 mOldChromeHomeFlagValue = prefManager.isChromeHomeEnabled(); 33 mOldChromeHomeFlagValue = prefManager.isChromeHomeEnabled();
31 prefManager.setChromeHomeEnabled(true); 34 prefManager.setChromeHomeEnabled(true);
32 35
33 super.setUp(); 36 super.setUp();
34 37
35 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 38 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
36 @Override 39 @Override
37 public void run() { 40 public void run() {
38 getActivity().getBottomSheet().setSheetState( 41 getActivity().getBottomSheet().setSheetState(
39 BottomSheet.SHEET_STATE_FULL, /* animate = */ false); 42 BottomSheet.SHEET_STATE_FULL, /* animate = */ false);
40 } 43 }
41 }); 44 });
42 RecyclerViewTestUtils.waitForStableRecyclerView( 45 RecyclerViewTestUtils.waitForStableRecyclerView(
43 getBottomSheetContent().getScrollingContentView()); 46 getBottomSheetContent().getScrollingContentView());
47
48 mBottomSheet = getActivity().getBottomSheet();
44 } 49 }
45 50
46 @Override 51 @Override
47 public void startMainActivity() throws InterruptedException { 52 public void startMainActivity() throws InterruptedException {
48 startMainActivityOnBlankPage(); 53 startMainActivityOnBlankPage();
49 } 54 }
50 55
51 @Override 56 @Override
52 protected void tearDown() throws Exception { 57 protected void tearDown() throws Exception {
53 super.tearDown(); 58 super.tearDown();
54 ChromePreferenceManager.getInstance().setChromeHomeEnabled(mOldChromeHom eFlagValue); 59 ChromePreferenceManager.getInstance().setChromeHomeEnabled(mOldChromeHom eFlagValue);
55 } 60 }
56 61
62 /**
63 * Set the bottom sheet's state on the UI thread.
64 * @param state The state to set the sheet to.
65 * @param animate If the sheet should animate to the provided state.
66 */
67 protected void setSheetState(final int state, final boolean animate) {
68 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
69 @Override
70 public void run() {
71 mBottomSheet.setSheetState(state, animate);
72 }
73 });
74 }
75
76 /**
77 * Set the bottom sheet's offset from the bottom of the screen on the UI thr ead.
78 * @param offset The offset from the bottom that the sheet should be.
79 */
80 protected void setSheetOffsetFromBottom(final float offset) {
81 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
82 @Override
83 public void run() {
84 mBottomSheet.setSheetOffsetFromBottomForTesting(offset);
85 }
86 });
87 }
88
57 protected BottomSheetContent getBottomSheetContent() { 89 protected BottomSheetContent getBottomSheetContent() {
58 return getActivity().getBottomSheet().getCurrentSheetContent(); 90 return getActivity().getBottomSheet().getCurrentSheetContent();
59 } 91 }
60 } 92 }
OLDNEW
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/widget/BottomSheetObserverTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698