OLD | NEW |
---|---|
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 android.support.v7.widget.RecyclerView; | 9 import android.support.v7.widget.RecyclerView; |
10 | 10 |
11 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
12 import org.chromium.base.test.util.CommandLineFlags; | 12 import org.chromium.base.test.util.CommandLineFlags; |
13 import org.chromium.base.test.util.Restriction; | 13 import org.chromium.base.test.util.Restriction; |
14 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 14 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
15 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; | 15 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet; |
16 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetCon tent; | 16 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheet.BottomSheetCon tent; |
17 import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContentControll er; | |
17 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; | 18 import org.chromium.chrome.test.util.browser.RecyclerViewTestUtils; |
18 | 19 |
19 /** | 20 /** |
20 * Base class for instrumentation tests using the bottom sheet. | 21 * Base class for instrumentation tests using the bottom sheet. |
21 */ | 22 */ |
22 @CommandLineFlags.Add({"enable-features=ChromeHome"}) | 23 @CommandLineFlags.Add({"enable-features=ChromeHome"}) |
23 @Restriction(RESTRICTION_TYPE_PHONE) // ChromeHome is only enabled on phones | 24 @Restriction(RESTRICTION_TYPE_PHONE) // ChromeHome is only enabled on phones |
24 public abstract class BottomSheetTestCaseBase extends ChromeTabbedActivityTestBa se { | 25 public abstract class BottomSheetTestCaseBase extends ChromeTabbedActivityTestBa se { |
25 /** A handle to the bottom sheet. */ | 26 /** A handle to the bottom sheet. */ |
26 protected BottomSheet mBottomSheet; | 27 protected BottomSheet mBottomSheet; |
27 | 28 |
29 /** A handle to the bottom seet content controller. */ | |
gone
2017/03/21 17:46:51
sheet, or use the real class name
Theresa
2017/03/21 22:29:25
Done.
| |
30 protected BottomSheetContentController mBottomSheetContentController; | |
31 | |
28 private boolean mOldChromeHomeFlagValue; | 32 private boolean mOldChromeHomeFlagValue; |
29 @Override | 33 @Override |
30 protected void setUp() throws Exception { | 34 protected void setUp() throws Exception { |
31 // TODO(dgn,mdjones): Chrome restarts when the ChromeHome feature flag v alue changes. That | 35 // TODO(dgn,mdjones): Chrome restarts when the ChromeHome feature flag v alue changes. That |
32 // crashes the test so we need to manually set the preference to match t he flag before | 36 // crashes the test so we need to manually set the preference to match t he flag before |
33 // Chrome initialises via super.setUp() | 37 // Chrome initialises via super.setUp() |
34 ChromePreferenceManager prefManager = ChromePreferenceManager.getInstanc e(); | 38 ChromePreferenceManager prefManager = ChromePreferenceManager.getInstanc e(); |
35 mOldChromeHomeFlagValue = prefManager.isChromeHomeEnabled(); | 39 mOldChromeHomeFlagValue = prefManager.isChromeHomeEnabled(); |
36 prefManager.setChromeHomeEnabled(true); | 40 prefManager.setChromeHomeEnabled(true); |
37 | 41 |
38 super.setUp(); | 42 super.setUp(); |
39 | 43 |
40 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 44 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
41 @Override | 45 @Override |
42 public void run() { | 46 public void run() { |
43 getActivity().getBottomSheet().setSheetState( | 47 getActivity().getBottomSheet().setSheetState( |
44 BottomSheet.SHEET_STATE_FULL, /* animate = */ false); | 48 BottomSheet.SHEET_STATE_FULL, /* animate = */ false); |
45 } | 49 } |
46 }); | 50 }); |
47 // The default BottomSheetContent is SuggestionsBottomSheetContent, whos e content view is a | 51 // The default BottomSheetContent is SuggestionsBottomSheetContent, whos e content view is a |
48 // RecyclerView. | 52 // RecyclerView. |
49 RecyclerViewTestUtils.waitForStableRecyclerView( | 53 RecyclerViewTestUtils.waitForStableRecyclerView( |
50 ((RecyclerView) getBottomSheetContent().getContentView())); | 54 ((RecyclerView) getBottomSheetContent().getContentView())); |
51 | 55 |
52 mBottomSheet = getActivity().getBottomSheet(); | 56 mBottomSheet = getActivity().getBottomSheet(); |
57 mBottomSheetContentController = getActivity().getBottomSheetContentContr oller(); | |
53 } | 58 } |
54 | 59 |
55 @Override | 60 @Override |
56 public void startMainActivity() throws InterruptedException { | 61 public void startMainActivity() throws InterruptedException { |
57 startMainActivityOnBlankPage(); | 62 startMainActivityOnBlankPage(); |
58 } | 63 } |
59 | 64 |
60 @Override | 65 @Override |
61 protected void tearDown() throws Exception { | 66 protected void tearDown() throws Exception { |
62 super.tearDown(); | 67 super.tearDown(); |
(...skipping 23 matching lines...) Expand all Loading... | |
86 @Override | 91 @Override |
87 public void run() { | 92 public void run() { |
88 mBottomSheet.setSheetOffsetFromBottomForTesting(offset); | 93 mBottomSheet.setSheetOffsetFromBottomForTesting(offset); |
89 } | 94 } |
90 }); | 95 }); |
91 } | 96 } |
92 | 97 |
93 protected BottomSheetContent getBottomSheetContent() { | 98 protected BottomSheetContent getBottomSheetContent() { |
94 return getActivity().getBottomSheet().getCurrentSheetContent(); | 99 return getActivity().getBottomSheet().getCurrentSheetContent(); |
95 } | 100 } |
101 | |
102 /** | |
103 * @param itemId The id of the MenuItem corresponding to the {@link BottomSh eetContent} to | |
104 * select. | |
105 */ | |
106 protected void selectBottomSheetContent(final int itemId) { | |
107 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
108 @Override | |
109 public void run() { | |
110 mBottomSheetContentController.selectItem(itemId); | |
111 } | |
112 }); | |
113 } | |
96 } | 114 } |
OLD | NEW |