blob: 5d99f95091d98eb96512f07a6aa4c2b8a7c727af [file] [log] [blame]
Cole Faustd4e193b2019-10-03 09:49:26 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.ui.toolbar;
18
19import static com.google.common.truth.Truth.assertThat;
20
Ram Parameswaran05fec072019-10-17 13:24:27 -070021import static org.mockito.Mockito.spy;
22import static org.mockito.Mockito.when;
23
Cole Faustd4e193b2019-10-03 09:49:26 -070024import android.content.Context;
Ram Parameswaran05fec072019-10-17 13:24:27 -070025import android.content.res.Resources;
Cole Faustd4e193b2019-10-03 09:49:26 -070026import android.view.View;
27import android.view.ViewGroup;
28
Cole Faustd4e193b2019-10-03 09:49:26 -070029import com.android.car.ui.R;
30
31import org.junit.Before;
32import org.junit.Test;
33import org.junit.runner.RunWith;
34import org.robolectric.Robolectric;
Ram Parameswaran39020e42020-01-23 17:50:54 -080035import org.robolectric.RobolectricTestRunner;
Cole Faustd4e193b2019-10-03 09:49:26 -070036import org.robolectric.RuntimeEnvironment;
37import org.robolectric.android.controller.ActivityController;
38import org.robolectric.annotation.Config;
39
40import java.util.Arrays;
41import java.util.Collections;
42import java.util.List;
43
Ram Parameswaran39020e42020-01-23 17:50:54 -080044@RunWith(RobolectricTestRunner.class)
Cole Faustd75f2342020-01-29 10:33:36 -080045@Config(shadows = {ExtendedShadowTypeface.class, ShadowAsyncLayoutInflater.class},
46 qualifiers = "land")
Cole Faustd4e193b2019-10-03 09:49:26 -070047public class ToolbarTest {
48
49 private Context mContext;
Ram Parameswaran05fec072019-10-17 13:24:27 -070050 private Resources mResources;
Cole Faustd4e193b2019-10-03 09:49:26 -070051 private ActivityController<TestActivity> mActivityController;
52 private TestActivity mActivity;
53 private Toolbar mToolbar;
54
55 @Before
56 public void setUp() {
57 mContext = RuntimeEnvironment.application;
Ram Parameswaran05fec072019-10-17 13:24:27 -070058 mResources = mContext.getResources();
Cole Faustd4e193b2019-10-03 09:49:26 -070059 mActivityController = Robolectric.buildActivity(TestActivity.class);
60 mActivityController.setup();
Cole Faustd4e193b2019-10-03 09:49:26 -070061 mActivity = mActivityController.get();
62 mToolbar = mActivity.findViewById(R.id.toolbar);
63 }
64
65 @Test
66 public void getters_nochanges_shouldReturnDefaults() {
67 assertThat(mToolbar.getBackgroundShown()).isEqualTo(true);
68 assertThat(mToolbar.getShowMenuItemsWhileSearching()).isEqualTo(false);
69 assertThat(mToolbar.getState()).isEquivalentAccordingToCompareTo(Toolbar.State.HOME);
70 assertThat(mToolbar.getNavButtonMode()).isEquivalentAccordingToCompareTo(
71 Toolbar.NavButtonMode.BACK);
72 }
73
74 @Test
75 public void setState_subpage_shouldCauseGetStateToReturnSubpage() {
76 mToolbar.setState(Toolbar.State.SUBPAGE);
77
78 assertThat(mToolbar.getState()).isEquivalentAccordingToCompareTo(Toolbar.State.SUBPAGE);
79 }
80
81 @Test
Cole Faustcffd5ba2020-01-02 15:25:55 -080082 public void setters_and_getters_test() {
Cole Faustd4e193b2019-10-03 09:49:26 -070083 mToolbar.setTitle("Foo");
84 mToolbar.setSearchHint("Foo2");
85 mToolbar.setBackgroundShown(false);
86 mToolbar.setShowMenuItemsWhileSearching(true);
87 mToolbar.setState(Toolbar.State.SUBPAGE);
88 mToolbar.setNavButtonMode(Toolbar.NavButtonMode.CLOSE);
89
Cole Faustd4e193b2019-10-03 09:49:26 -070090 assertThat(mToolbar.getTitle().toString()).isEqualTo("Foo");
91 assertThat(mToolbar.getSearchHint().toString()).isEqualTo("Foo2");
92 assertThat(mToolbar.getBackgroundShown()).isEqualTo(false);
93 assertThat(mToolbar.getShowMenuItemsWhileSearching()).isEqualTo(true);
94 assertThat(mToolbar.getState()).isEquivalentAccordingToCompareTo(Toolbar.State.SUBPAGE);
95 assertThat(mToolbar.getNavButtonMode()).isEquivalentAccordingToCompareTo(
96 Toolbar.NavButtonMode.CLOSE);
97 }
98
99 @Test
Cole Faustd4e193b2019-10-03 09:49:26 -0700100 public void showLogo_whenSet_andStateIsHome() {
101 mToolbar.setState(Toolbar.State.HOME);
102 mToolbar.setLogo(R.drawable.test_ic_launcher);
103
Cole Faustdb6866c2019-10-09 15:56:07 -0700104 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isTrue();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700105 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700106 }
107
108 @Test
Roberto Pereze5d8e682019-12-12 06:39:16 -0800109 public void hideLogo_andTitleLogo_whenSet_andStateIsHome_andLogoIsDisabled() {
110 mockResources();
111 when(mResources.getBoolean(R.bool.car_ui_toolbar_show_logo)).thenReturn(false);
112
113 Toolbar toolbar = new Toolbar(mContext);
114 toolbar.setState(Toolbar.State.HOME);
115 toolbar.setLogo(R.drawable.test_ic_launcher);
116
117 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
118 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
119 }
120
121 @Test
Roberto Perez90c45bb2019-10-21 17:30:48 -0700122 public void showTitleLogo_whenSet_andStateIsNotHome() {
Cole Faustd4e193b2019-10-03 09:49:26 -0700123 mToolbar.setState(Toolbar.State.SUBPAGE);
124 mToolbar.setLogo(R.drawable.test_ic_launcher);
125
Cole Faustdb6866c2019-10-09 15:56:07 -0700126 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700127 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700128 }
129
130 @Test
Roberto Perez90c45bb2019-10-21 17:30:48 -0700131 public void hideLogo_andTitleLogo_whenNotSet_andStateIsHome() {
Cole Faustd4e193b2019-10-03 09:49:26 -0700132 mToolbar.setState(Toolbar.State.HOME);
133 mToolbar.setLogo(0);
134
Cole Faustdb6866c2019-10-09 15:56:07 -0700135 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700136 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700137 }
138
139 @Test
Roberto Perez90c45bb2019-10-21 17:30:48 -0700140 public void hideLogo_andTitleLogo_whenNotSet_andStateIsNotHome() {
Cole Faustd4e193b2019-10-03 09:49:26 -0700141 mToolbar.setState(Toolbar.State.SUBPAGE);
142 mToolbar.setLogo(0);
143
Cole Faustdb6866c2019-10-09 15:56:07 -0700144 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700145 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700146 }
147
148 @Test
149 public void registerOnBackListener_whenBackIsPressed_shouldCallListener() {
150 mToolbar.setState(Toolbar.State.SUBPAGE);
151 Mutable<Integer> timesBackPressed = new Mutable<>(0);
152 Toolbar.OnBackListener listener = () -> {
153 timesBackPressed.value++;
154 return false;
155 };
156
157 mToolbar.registerOnBackListener(listener);
158 pressBack();
159
160 assertThat(timesBackPressed.value).isEqualTo(1);
161 assertThat(mActivity.getTimesBackPressed()).isEqualTo(1);
162 }
163
164 @Test
165 public void registerOnBackListener_whenAListenerReturnsTrue_shouldSuppressBack() {
166 mToolbar.setState(Toolbar.State.SUBPAGE);
167
168 mToolbar.registerOnBackListener(() -> true);
169 pressBack();
170 mToolbar.registerOnBackListener(() -> false);
171 pressBack();
172
173 assertThat(mActivity.getTimesBackPressed()).isEqualTo(0);
174 }
175
176 @Test
Ram Parameswaran05fec072019-10-17 13:24:27 -0700177 public void testState_twoRow_withTitle_withTabs() {
178 mockResources();
179 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(true);
180
181 Toolbar toolbar = new Toolbar(mContext);
182 assertThat(toolbar.isTabsInSecondRow()).isTrue();
183
184 // Set title and tabs for toolbar.
185 toolbar.setTitle("Test title");
186 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
187 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
188
189 // Toolbar should display two rows, showing both title and tabs.
190 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
191 View.VISIBLE);
192 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
193 View.VISIBLE);
194 }
195
196 @Test
197 public void testState_twoRow_withTitle() {
198 mockResources();
199 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(true);
200
201 Toolbar toolbar = new Toolbar(mContext);
202 assertThat(toolbar.isTabsInSecondRow()).isTrue();
203
204 toolbar.setTitle("Test title");
205
206 // Toolbar should display two rows, but no tabs are set so they should not be visible.
207 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
208 View.VISIBLE);
209 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isNotEqualTo(
210 View.VISIBLE);
211 }
212
213 @Test
214 public void testState_twoRow_withTabs() {
215 mockResources();
216 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(true);
217
218 Toolbar toolbar = new Toolbar(mContext);
219 assertThat(toolbar.isTabsInSecondRow()).isTrue();
220 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
221 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
222
223 // Toolbar should display two rows with an empty title and tabs.
224 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
225 View.VISIBLE);
226 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
227 View.VISIBLE);
228 }
229
230 @Test
231 public void testState_oneRow_withTitle_withTabs() {
232 mockResources();
233 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(false);
234
235 Toolbar toolbar = new Toolbar(mContext);
236 assertThat(toolbar.isTabsInSecondRow()).isFalse();
237
238 // Set title and tabs for toolbar.
239 toolbar.setTitle("Test title");
240 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
241 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
242
243 // With only one row available, toolbar will only show tabs and not the title.
244 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
245 View.VISIBLE);
246 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isNotEqualTo(
247 View.VISIBLE);
248 }
249
250 @Test
251 public void testState_oneRow_withTitle() {
252 mockResources();
253 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(false);
254
255
256 Toolbar toolbar = new Toolbar(mContext);
257 assertThat(toolbar.isTabsInSecondRow()).isFalse();
258
259 toolbar.setTitle("Test title");
260
261 // Toolbar should display one row with the title and no tabs.
262 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isNotEqualTo(
263 View.VISIBLE);
264 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
265 View.VISIBLE);
266 }
267
268 @Test
269 public void testState_oneRow_withTabs() {
270 mockResources();
271 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(false);
272
273
274 Toolbar toolbar = new Toolbar(mContext);
275 assertThat(toolbar.isTabsInSecondRow()).isFalse();
276
277 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
278 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
279
280 // Toolbar should display one row with only tabs.
281 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
282 View.VISIBLE);
283 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isNotEqualTo(
284 View.VISIBLE);
285 }
286
287 @Test
Cole Faustd4e193b2019-10-03 09:49:26 -0700288 public void registerOnBackListener_whenListenerRegisteredTwice_shouldntCallListenerTwice() {
289 mToolbar.setState(Toolbar.State.SUBPAGE);
290 Mutable<Integer> timesBackPressed = new Mutable<>(0);
291 Toolbar.OnBackListener listener = () -> {
292 timesBackPressed.value++;
293 return false;
294 };
295
296 // Registering a second time shouldn't do anything
297 mToolbar.registerOnBackListener(listener);
298 mToolbar.registerOnBackListener(listener);
299 pressBack();
300
301 assertThat(timesBackPressed.value).isEqualTo(1);
302 }
303
304 @Test
305 public void unregisterOnBackListener_previouslyRegisteredListener_shouldUnregister() {
306 mToolbar.setState(Toolbar.State.SUBPAGE);
307 Mutable<Integer> timesBackPressed = new Mutable<>(0);
308 Toolbar.OnBackListener listener = () -> {
309 timesBackPressed.value++;
310 return false;
311 };
312
313 mToolbar.registerOnBackListener(listener);
314 mToolbar.unregisterOnBackListener(listener);
315 pressBack();
316
317 assertThat(timesBackPressed.value).isEqualTo(0);
318 }
319
320 @Test
Cole Faust4ad34c82019-11-19 17:55:11 -0800321 public void menuItems_builder_id() {
322 MenuItem item = MenuItem.builder(mContext)
323 .setId(5)
324 .build();
325
326 assertThat(item.getId()).isEqualTo(5);
327 }
328
329 @Test
330 public void menuItems_setId_shouldWork() {
331 MenuItem item = MenuItem.builder(mContext).build();
332
Cole Faust9ed740e2019-12-06 17:36:20 -0800333 assertThat(item.getId()).isEqualTo(View.NO_ID);
Cole Faust4ad34c82019-11-19 17:55:11 -0800334
335 item.setId(7);
336
337 assertThat(item.getId()).isEqualTo(7);
338 }
339
340 @Test
Cole Faustd4e193b2019-10-03 09:49:26 -0700341 public void menuItems_whenClicked_shouldCallListener() {
Cole Faust9de21992019-11-22 10:45:25 -0800342 assertThat(getMenuItemCount()).isEqualTo(0);
Cole Faustd4e193b2019-10-03 09:49:26 -0700343
344 Mutable<Boolean> button1Clicked = new Mutable<>(false);
345 Mutable<Boolean> button2Clicked = new Mutable<>(false);
346 mToolbar.setMenuItems(Arrays.asList(
347 createMenuItem(i -> button1Clicked.value = true),
348 createMenuItem(i -> button2Clicked.value = true)));
349
Cole Faust9de21992019-11-22 10:45:25 -0800350 assertThat(getMenuItemCount()).isEqualTo(2);
Cole Faustd4e193b2019-10-03 09:49:26 -0700351
Cole Faustdb6866c2019-10-09 15:56:07 -0700352 getMenuItemView(0).performClick();
Cole Faustd4e193b2019-10-03 09:49:26 -0700353
354 assertThat(button1Clicked.value).isTrue();
355
Cole Faustdb6866c2019-10-09 15:56:07 -0700356 getMenuItemView(1).performClick();
Cole Faustd4e193b2019-10-03 09:49:26 -0700357
358 assertThat(button2Clicked.value).isTrue();
359 }
360
361 @Test
362 public void menuItems_null_shouldRemoveExistingMenuItems() {
363 mToolbar.setMenuItems(Arrays.asList(
Ram Parameswaran05fec072019-10-17 13:24:27 -0700364 createMenuItem(i -> {
365 }),
366 createMenuItem(i -> {
367 })));
Cole Faustd4e193b2019-10-03 09:49:26 -0700368
Cole Faust9de21992019-11-22 10:45:25 -0800369 assertThat(getMenuItemCount()).isEqualTo(2);
Cole Faustd4e193b2019-10-03 09:49:26 -0700370
371 mToolbar.setMenuItems(null);
372
Cole Faust9de21992019-11-22 10:45:25 -0800373 assertThat(getMenuItemCount()).isEqualTo(0);
Cole Faustd4e193b2019-10-03 09:49:26 -0700374 }
375
376 @Test
377 public void menuItems_setVisibility_shouldDefaultToShown() {
Ram Parameswaran05fec072019-10-17 13:24:27 -0700378 MenuItem item = createMenuItem(i -> {
379 });
Cole Faustd4e193b2019-10-03 09:49:26 -0700380 mToolbar.setMenuItems(Collections.singletonList(item));
381
Cole Faustdb6866c2019-10-09 15:56:07 -0700382 assertThat(getMenuItemView(0).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700383 }
384
385 @Test
386 public void menuItems_setVisibility_shouldHide() {
Ram Parameswaran05fec072019-10-17 13:24:27 -0700387 MenuItem item = createMenuItem(i -> {
388 });
Cole Faustd4e193b2019-10-03 09:49:26 -0700389 mToolbar.setMenuItems(Collections.singletonList(item));
390
Cole Faustd4e193b2019-10-03 09:49:26 -0700391 item.setVisible(false);
Cole Faustdb6866c2019-10-09 15:56:07 -0700392 assertThat(getMenuItemView(0).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700393 }
394
395 @Test
396 public void menuItems_setVisibility_shouldReshowAfterHiding() {
Ram Parameswaran05fec072019-10-17 13:24:27 -0700397 MenuItem item = createMenuItem(i -> {
398 });
Cole Faustd4e193b2019-10-03 09:49:26 -0700399 mToolbar.setMenuItems(Collections.singletonList(item));
400
Cole Faustd4e193b2019-10-03 09:49:26 -0700401 item.setVisible(false);
402 item.setVisible(true);
Cole Faustdb6866c2019-10-09 15:56:07 -0700403 assertThat(getMenuItemView(0).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700404 }
405
406 @Test
407 public void menuItems_equalItems_shouldntRecreateViews() {
408 List<MenuItem> menuItems = Arrays.asList(
Ram Parameswaran05fec072019-10-17 13:24:27 -0700409 createMenuItem(i -> {
410 }),
411 createMenuItem(i -> {
412 }));
Cole Faustd4e193b2019-10-03 09:49:26 -0700413 mToolbar.setMenuItems(menuItems);
414
Cole Faust9de21992019-11-22 10:45:25 -0800415 assertThat(getMenuItemCount()).isEqualTo(2);
Cole Faustd4e193b2019-10-03 09:49:26 -0700416
Cole Faustdb6866c2019-10-09 15:56:07 -0700417 View firstMenuItemView = getMenuItemView(0);
Cole Faustd4e193b2019-10-03 09:49:26 -0700418
419 mToolbar.setMenuItems(menuItems);
420
Cole Faustdb6866c2019-10-09 15:56:07 -0700421 assertThat(firstMenuItemView).isSameAs(getMenuItemView(0));
Cole Faustd4e193b2019-10-03 09:49:26 -0700422 }
423
424 @Test
425 public void menuItems_searchScreen_shouldHideMenuItems() {
426 mToolbar.setMenuItems(Arrays.asList(
Cole Faust042a8a62019-11-22 14:11:58 -0800427 MenuItem.builder(mContext).setToSearch().build(),
Ram Parameswaran05fec072019-10-17 13:24:27 -0700428 createMenuItem(i -> {
429 })));
Cole Faustd4e193b2019-10-03 09:49:26 -0700430
431 mToolbar.setShowMenuItemsWhileSearching(false);
432 mToolbar.setState(Toolbar.State.SEARCH);
433
Cole Faustdb6866c2019-10-09 15:56:07 -0700434 assertThat(getMenuItemView(0).isShown()).isFalse();
435 assertThat(getMenuItemView(1).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700436 }
437
438 @Test
439 public void menuItems_showMenuItemsWhileSearching() {
440 mToolbar.setMenuItems(Arrays.asList(
Cole Faust042a8a62019-11-22 14:11:58 -0800441 MenuItem.builder(mContext).setToSearch().build(),
Ram Parameswaran05fec072019-10-17 13:24:27 -0700442 createMenuItem(i -> {
443 })));
Cole Faustd4e193b2019-10-03 09:49:26 -0700444
445 mToolbar.setShowMenuItemsWhileSearching(true);
446 mToolbar.setState(Toolbar.State.SEARCH);
447
Cole Faustdb6866c2019-10-09 15:56:07 -0700448 assertThat(getMenuItemView(0).isShown()).isFalse();
449 assertThat(getMenuItemView(1).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700450 }
451
452 private MenuItem createMenuItem(MenuItem.OnClickListener listener) {
Cole Faust042a8a62019-11-22 14:11:58 -0800453 return MenuItem.builder(mContext)
Cole Faustd4e193b2019-10-03 09:49:26 -0700454 .setTitle("Button!")
455 .setOnClickListener(listener)
456 .build();
457 }
458
Ram Parameswaran05fec072019-10-17 13:24:27 -0700459 private void mockResources() {
460 mContext = spy(RuntimeEnvironment.application);
461 mResources = spy(mContext.getResources());
462 when(mContext.getResources()).thenReturn(mResources);
463 }
464
Cole Faust9de21992019-11-22 10:45:25 -0800465 private int getMenuItemCount() {
466 return mToolbar.getMenuItems().size();
Cole Faustdb6866c2019-10-09 15:56:07 -0700467 }
468
469 private View getMenuItemView(int index) {
470 return ((ViewGroup) mToolbar
471 .findViewById(R.id.car_ui_toolbar_menu_items_container))
472 .getChildAt(index);
473 }
474
Cole Faustd4e193b2019-10-03 09:49:26 -0700475 private void pressBack() {
Cole Faustdb6866c2019-10-09 15:56:07 -0700476 mToolbar.findViewById(R.id.car_ui_toolbar_nav_icon_container).performClick();
Cole Faustd4e193b2019-10-03 09:49:26 -0700477 }
478
479 private static class Mutable<T> {
480 public T value;
481
482 Mutable(T value) {
483 this.value = value;
484 }
485 }
486
487}