summaryrefslogtreecommitdiff
path: root/library/main/tests/robotests/src/com/android/car/setupwizardlib/CarSetupWizardCompatLayoutTest.java
blob: 48d2c5291e8bc34281b5fedc78beea9da3a8af67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.car.setupwizardlib;

import static com.google.common.truth.Truth.assertThat;

import static org.robolectric.RuntimeEnvironment.application;

import android.app.Activity;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.ColorRes;
import androidx.annotation.StyleRes;

import com.android.car.setupwizardlib.partner.ExternalResources;
import com.android.car.setupwizardlib.partner.FakeOverrideContentProvider;
import com.android.car.setupwizardlib.partner.PartnerConfig;
import com.android.car.setupwizardlib.partner.ResourceEntry;
import com.android.car.setupwizardlib.robolectric.BaseRobolectricTest;
import com.android.car.setupwizardlib.robolectric.TestHelper;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowTextView;
import org.robolectric.util.ReflectionHelpers;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

/**
 * Tests for the CarSetupWizardCompatLayout
 */
@RunWith(RobolectricTestRunner.class)
public class CarSetupWizardCompatLayoutTest extends BaseRobolectricTest {
    private static final Locale LOCALE_EN_US = new Locale("en", "US");
    // Hebrew locale can be used to test RTL.
    private static final Locale LOCALE_IW_IL = new Locale("iw", "IL");

    private CarSetupWizardCompatLayout mCarSetupWizardCompatLayout;

    private static final String TEST_PACKAGE_NAME = "test.packageName";

    private static final PartnerConfig TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME =
            PartnerConfig.CONFIG_TOOLBAR_BUTTON_TEXT_SIZE;

    private static final float TOLERANCE = 0.001f;
    // A small value is picked so that it's not likely to coincide with the default font size
    private static final float EXCEPTED_TEXT_SIZE = 4;

    @Before
    public void setUp() {
        FakeOverrideContentProvider fakeOverrideDataProvider =
                FakeOverrideContentProvider.installEmptyProvider();
        List<ResourceEntry> resourceEntries = prepareFakeData();
        for (ResourceEntry entry : resourceEntries) {
            fakeOverrideDataProvider.injectResourceEntry(entry);
        }

        mCarSetupWizardCompatLayout = createCarSetupWizardCompatLayout();
        // Have to make this call first to ensure secondaryToolbar button is created from stub.
        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonVisible(true);
        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonVisible(false);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setBackButtonListener} does set the back button
     * listener.
     */
    @Test
    public void testSetBackButtonListener() {
        View.OnClickListener spyListener = TestHelper.createSpyListener();

        mCarSetupWizardCompatLayout.setBackButtonListener(spyListener);
        mCarSetupWizardCompatLayout.getBackButton().performClick();
        Mockito.verify(spyListener).onClick(mCarSetupWizardCompatLayout.getBackButton());
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setCloseButtonListener} does set the close button
     * listener.
     */
    @Test
    public void testSetCloseButtonListener() {
        View.OnClickListener spyListener = TestHelper.createSpyListener();

        mCarSetupWizardCompatLayout.setCloseButtonListener(spyListener);
        mCarSetupWizardCompatLayout.getCloseButton().performClick();
        Mockito.verify(spyListener).onClick(mCarSetupWizardCompatLayout.getCloseButton());
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setBackButtonVisible} does set the view
     * visible/not visible and calls
     * {@link CarSetupWizardDesignLayout#updateNavigationButtonTouchDelegate(View, boolean)}.
     */
    @Test
    public void testSetBackButtonVisibleTrue() {
        CarSetupWizardCompatLayout spyCarSetupWizardCompatLayout =
                Mockito.spy(mCarSetupWizardCompatLayout);

        spyCarSetupWizardCompatLayout.setBackButtonVisible(true);
        View backButton = spyCarSetupWizardCompatLayout.getBackButton();
        TestHelper.assertViewVisible(backButton);
        Mockito.verify(spyCarSetupWizardCompatLayout)
                .updateNavigationButtonTouchDelegate(backButton, true);
        View closeButton = spyCarSetupWizardCompatLayout.getCloseButton();
        TestHelper.assertViewNotVisible(closeButton);
        Mockito.verify(spyCarSetupWizardCompatLayout)
                .updateNavigationButtonTouchDelegate(closeButton, false);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setBackButtonVisible} does set the view
     * visible/not visible and calls
     * {@link CarSetupWizardDesignLayout#updateNavigationButtonTouchDelegate(View, boolean)}.
     */
    @Test
    public void testSetBackButtonVisibleFalse() {
        CarSetupWizardCompatLayout spyCarSetupWizardCompatLayout =
                Mockito.spy(mCarSetupWizardCompatLayout);

        spyCarSetupWizardCompatLayout.setBackButtonVisible(false);
        View backButton = spyCarSetupWizardCompatLayout.getBackButton();
        TestHelper.assertViewNotVisible(backButton);
        Mockito.verify(spyCarSetupWizardCompatLayout)
                .updateNavigationButtonTouchDelegate(backButton, false);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setCloseButtonVisible} does set the view
     * visible/not visible and calls
     * {@link CarSetupWizardDesignLayout#updateNavigationButtonTouchDelegate(View, boolean)}.
     */
    @Test
    public void testSetCloseButtonVisibleTrue() {
        CarSetupWizardCompatLayout spyCarSetupWizardCompatLayout =
                Mockito.spy(mCarSetupWizardCompatLayout);

        spyCarSetupWizardCompatLayout.setCloseButtonVisible(true);
        View closeButton = spyCarSetupWizardCompatLayout.getCloseButton();
        TestHelper.assertViewVisible(closeButton);
        Mockito.verify(spyCarSetupWizardCompatLayout)
                .updateNavigationButtonTouchDelegate(closeButton, true);
        View backButton = spyCarSetupWizardCompatLayout.getBackButton();
        TestHelper.assertViewNotVisible(backButton);
        Mockito.verify(spyCarSetupWizardCompatLayout)
                .updateNavigationButtonTouchDelegate(backButton, false);
    }


    /**
     * Test that {@link CarSetupWizardCompatLayout#setCloseButtonVisible} does set the view
     * visible/not visible and calls
     * {@link CarSetupWizardDesignLayout#updateNavigationButtonTouchDelegate(View, boolean)}.
     */
    @Test
    public void testSetCloseButtonVisibleFalse() {
        CarSetupWizardCompatLayout spyCarSetupWizardCompatLayout =
                Mockito.spy(mCarSetupWizardCompatLayout);

        spyCarSetupWizardCompatLayout.setCloseButtonVisible(false);
        View closeButton = spyCarSetupWizardCompatLayout.getCloseButton();
        TestHelper.assertViewNotVisible(closeButton);
        Mockito.verify(spyCarSetupWizardCompatLayout)
                .updateNavigationButtonTouchDelegate(closeButton, false);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setToolbarTitleVisible} does set the view
     * visible/not visible.
     */
    @Test
    public void testSetToolbarTitleVisibleTrue() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getToolbarTitle();

        mCarSetupWizardCompatLayout.setToolbarTitleVisible(true);
        TestHelper.assertViewVisible(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setToolbarTitleVisible} does set the view
     * visible/not visible.
     */
    @Test
    public void testSetToolbarTitleVisibleFalse() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getToolbarTitle();

        mCarSetupWizardCompatLayout.setToolbarTitleVisible(false);
        TestHelper.assertViewNotVisible(toolbarTitle);
    }

    /**
     * Tests that {@link CarSetupWizardCompatLayout#setToolbarTitleText(String)} does set the
     * toolbar title text.
     */
    @Test
    public void testSetToolbarTitleText() {
        mCarSetupWizardCompatLayout.setToolbarTitleText("test title");
        TestHelper.assertTextEqual(mCarSetupWizardCompatLayout.getToolbarTitle(), "test title");
    }

    /**
     * Test that a call to setToolbarTitleStyle sets the text appearance on the toolbar title.
     */
    @Test
    public void testSetToolbarStyle() {
        @StyleRes int newStyle = R.style.TextAppearance_Car_Body2;
        mCarSetupWizardCompatLayout.setToolbarTitleStyle(newStyle);
        ShadowTextView shadowTextView =
                Shadows.shadowOf(mCarSetupWizardCompatLayout.getToolbarTitle());
        assertThat(shadowTextView.getTextAppearanceId()).isEqualTo(newStyle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setPrimaryToolbarButtonVisible} does set the view
     * visible/not visible.
     */
    @Test
    public void testSetPrimaryToolbarButtonVisibleTrue() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();

        mCarSetupWizardCompatLayout.setPrimaryToolbarButtonVisible(true);
        TestHelper.assertViewVisible(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setPrimaryToolbarButtonVisible} does set the view
     * visible/not visible.
     */
    @Test
    public void testSetPrimaryToolbarButtonVisibleFalse() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();

        mCarSetupWizardCompatLayout.setPrimaryToolbarButtonVisible(false);
        TestHelper.assertViewNotVisible(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setPrimaryToolbarButtonEnabled} does set the view
     * enabled/not enabled.
     */
    @Test
    public void testSetPrimaryToolbarButtonEnabledTrue() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();

        mCarSetupWizardCompatLayout.setPrimaryToolbarButtonEnabled(true);
        TestHelper.assertViewEnabled(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setPrimaryToolbarButtonEnabled} does set the view
     * enabled/not enabled.
     */
    @Test
    public void testSetPrimaryToolbarButtonEnabledFalse() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();

        mCarSetupWizardCompatLayout.setPrimaryToolbarButtonEnabled(false);
        TestHelper.assertViewNotEnabled(toolbarTitle);
    }

    /**
     * Tests that {@link CarSetupWizardCompatLayout#setPrimaryToolbarButtonText(String)} does set
     * the primary toolbar button text.
     */
    @Test
    public void testSetPrimaryToolbarButtonText() {
        mCarSetupWizardCompatLayout.setPrimaryToolbarButtonText("test title");
        TestHelper.assertTextEqual(
                mCarSetupWizardCompatLayout.getPrimaryToolbarButton(), "test title");
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setPrimaryToolbarButtonListener} does set the
     * primary toolbar button listener.
     */
    @Test
    public void testSetPrimaryToolbarButtonListener() {
        View.OnClickListener spyListener = TestHelper.createSpyListener();

        mCarSetupWizardCompatLayout.setPrimaryToolbarButtonListener(spyListener);
        mCarSetupWizardCompatLayout.getPrimaryToolbarButton().performClick();
        Mockito.verify(spyListener).onClick(mCarSetupWizardCompatLayout.getPrimaryToolbarButton());
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#createPrimaryToolbarButton} creates a new button
     * but holds over the correct attributes.
     */
    @Test
    public void testCreatePrimaryButtonTrue() {
        Button currPrimaryToolbarButton = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();
        Button primaryToolbarButton = mCarSetupWizardCompatLayout.createPrimaryToolbarButton(true);

        assertThat(primaryToolbarButton.getVisibility()).isEqualTo(
                currPrimaryToolbarButton.getVisibility());
        assertThat(primaryToolbarButton.isEnabled()).isEqualTo(
                currPrimaryToolbarButton.isEnabled());
        assertThat(primaryToolbarButton.getText()).isEqualTo(currPrimaryToolbarButton.getText());
        assertThat(primaryToolbarButton.getLayoutParams()).isEqualTo(
                currPrimaryToolbarButton.getLayoutParams());
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setSecondaryToolbarButtonVisible} does set the
     * view visible/not visible.
     */
    @Test
    public void testSetSecondaryToolbarButtonVisibleTrue() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getSecondaryToolbarButton();

        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonVisible(true);
        TestHelper.assertViewVisible(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setSecondaryToolbarButtonVisible} does set the
     * view visible/not visible.
     */
    @Test
    public void testSetSecondaryToolbarButtonVisibleFalse() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getSecondaryToolbarButton();

        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonVisible(false);
        TestHelper.assertViewNotVisible(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setSecondaryToolbarButtonEnabled} does set the
     * view enabled/not enabled.
     */
    @Test
    public void testSetSecondaryToolbarButtonEnabledTrue() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getSecondaryToolbarButton();

        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonEnabled(true);
        TestHelper.assertViewEnabled(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setSecondaryToolbarButtonEnabled} does set the
     * view enabled/not enabled.
     */
    @Test
    public void testSetSecondaryToolbarButtonEnabledFalse() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getSecondaryToolbarButton();

        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonEnabled(false);
        TestHelper.assertViewNotEnabled(toolbarTitle);
    }

    /**
     * Tests that {@link CarSetupWizardCompatLayout#setSecondaryToolbarButtonText(String)} does set
     * the secondary toolbar button text.
     */
    @Test
    public void testSetSecondaryToolbarButtonText() {
        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonText("test title");
        TestHelper.assertTextEqual(
                mCarSetupWizardCompatLayout.getSecondaryToolbarButton(), "test title");
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setSecondaryToolbarButtonListener} does set the
     * secondary toolbar button listener.
     */
    @Test
    public void testSetSecondaryToolbarButtonListener() {
        View.OnClickListener spyListener = TestHelper.createSpyListener();

        mCarSetupWizardCompatLayout.setSecondaryToolbarButtonListener(spyListener);
        mCarSetupWizardCompatLayout.getSecondaryToolbarButton().performClick();
        Mockito.verify(spyListener)
                .onClick(mCarSetupWizardCompatLayout.getSecondaryToolbarButton());
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setProgressBarVisible} does set the view
     * visible/not visible.
     */
    @Test
    public void testSetProgressBarVisibleTrue() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getProgressBar();

        mCarSetupWizardCompatLayout.setProgressBarVisible(true);
        TestHelper.assertViewVisible(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setProgressBarVisible} does set the view
     * visible/not visible.
     */
    @Test
    public void testSetProgressBarVisibleFalse() {
        View toolbarTitle = mCarSetupWizardCompatLayout.getProgressBar();

        mCarSetupWizardCompatLayout.setProgressBarVisible(false);
        TestHelper.assertViewNotVisible(toolbarTitle);
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setProgressBarIndeterminate(boolean)}
     * does set the progress bar intermediate/not indeterminate.
     */
    @Test
    public void testSetProgressBarIndeterminateTrue() {
        mCarSetupWizardCompatLayout.setProgressBarIndeterminate(true);
        assertThat(mCarSetupWizardCompatLayout.getProgressBar().isIndeterminate()).isTrue();
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setProgressBarIndeterminate(boolean)}
     * does set the progress bar intermediate/not indeterminate.
     */
    @Test
    public void testSetProgressBarIndeterminateFalse() {
        mCarSetupWizardCompatLayout.setProgressBarIndeterminate(false);
        assertThat(mCarSetupWizardCompatLayout.getProgressBar().isIndeterminate()).isFalse();
    }

    /**
     * Test that {@link CarSetupWizardCompatLayout#setProgressBarProgress} does set the progress.
     */
    @Test
    public void testSetProgressBarProgress() {
        mCarSetupWizardCompatLayout.setProgressBarProgress(80);
        assertThat(mCarSetupWizardCompatLayout.getProgressBar().getProgress()).isEqualTo(80);
    }

    @Test
    public void testApplyUpdatedLocale() {
        mCarSetupWizardCompatLayout.applyLocale(LOCALE_IW_IL);
        TextView toolbarTitle = mCarSetupWizardCompatLayout.getToolbarTitle();
        Button primaryToolbarButton = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();
        Button secondaryToolbarButton = mCarSetupWizardCompatLayout.getSecondaryToolbarButton();

        assertThat(toolbarTitle.getTextLocale()).isEqualTo(LOCALE_IW_IL);
        assertThat(primaryToolbarButton.getTextLocale()).isEqualTo(LOCALE_IW_IL);
        assertThat(secondaryToolbarButton.getTextLocale()).isEqualTo(LOCALE_IW_IL);

        mCarSetupWizardCompatLayout.applyLocale(LOCALE_EN_US);
        assertThat(toolbarTitle.getTextLocale()).isEqualTo(LOCALE_EN_US);
        assertThat(primaryToolbarButton.getTextLocale()).isEqualTo(LOCALE_EN_US);
        assertThat(secondaryToolbarButton.getTextLocale()).isEqualTo(LOCALE_EN_US);
    }

    @Test
    public void testGetBackButton() {
        assertThat(mCarSetupWizardCompatLayout.getPrimaryToolbarButton()).isEqualTo(
                mCarSetupWizardCompatLayout.findViewById(R.id.primary_toolbar_button));
    }

    @Test
    public void testGetToolBarTitle() {
        assertThat(mCarSetupWizardCompatLayout.getToolbarTitle()).isEqualTo(
                mCarSetupWizardCompatLayout.findViewById(R.id.toolbar_title));
    }

    @Test
    public void testGetPrimaryToolBarButton() {
        assertThat(mCarSetupWizardCompatLayout.getPrimaryToolbarButton()).isEqualTo(
                mCarSetupWizardCompatLayout.findViewById(R.id.primary_toolbar_button));
    }

    @Test
    public void testGetSecondaryToolBarButton() {
        assertThat(mCarSetupWizardCompatLayout.getSecondaryToolbarButton()).isEqualTo(
                mCarSetupWizardCompatLayout.findViewById(R.id.secondary_toolbar_button));
    }

    @Test
    public void testGetProgressBar() {
        assertThat(mCarSetupWizardCompatLayout.getProgressBar()).isEqualTo(
                mCarSetupWizardCompatLayout.findViewById(R.id.progress_bar));
    }

    @Test
    public void testPartnerResourcesAreApplied() {
        setupFakeContentProvider();

        CarSetupWizardCompatLayout layout = createCarSetupWizardCompatLayout();

        // Verify primary button background
        Button primary = layout.getPrimaryToolbarButton();
        Drawable expected = application.getResources().getDrawable(R.drawable.button_ripple_bg);
        assertThat(getDrawbleDefaultColor(primary.getBackground()))
                .isEqualTo(getDrawbleDefaultColor(expected));

        // Verify primary button text size
        assertThat(primary.getTextSize())
                .isEqualTo(FakeOverrideContentProvider.DEFAULT_DIMENSION);

        // Verify paddings
        assertThat(primary.getPaddingStart())
                .isEqualTo(FakeOverrideContentProvider.DEFAULT_H_PADDING);

        assertThat(primary.getPaddingEnd())
                .isEqualTo(FakeOverrideContentProvider.DEFAULT_H_PADDING);

        assertThat(primary.getPaddingTop())
                .isEqualTo(FakeOverrideContentProvider.DEFAULT_V_PADDING);

        assertThat(primary.getPaddingBottom())
                .isEqualTo(FakeOverrideContentProvider.DEFAULT_V_PADDING);
    }

    @Test
    public void testShouldNotApplyLayoutBackground() {
        setupFakeContentProvider();
        CarSetupWizardCompatLayout layout = createCarSetupWizardCompatLayout();

        ColorDrawable bg = (ColorDrawable) layout.getBackground();
        assertThat(bg).isNull();
    }

    @Test
    public void testSetButtonTextColor() {
        setupFakeContentProvider();
        CarSetupWizardCompatLayout layout = createCarSetupWizardCompatLayout();
        Button primary = layout.getPrimaryToolbarButton();

        layout.setButtonTextColor(
                primary, PartnerConfig.CONFIG_LAYOUT_BG_COLOR);

        assertThat(primary.getCurrentTextColor())
                .isEqualTo(FakeOverrideContentProvider.ANDROID_COLOR_DARK_GRAY);
    }

    @Test
    public void testSetBackground() {
        setupFakeContentProvider();
        CarSetupWizardCompatLayout layout = createCarSetupWizardCompatLayout();
        layout.setSecondaryToolbarButtonVisible(true);
        Button secondary = layout.getSecondaryToolbarButton();

        layout.setBackground(
                secondary,
                PartnerConfig.CONFIG_TOOLBAR_PRIMARY_BUTTON_BG,
                PartnerConfig.CONFIG_TOOLBAR_SECONDARY_BUTTON_BG_COLOR);

        Drawable expected = application.getResources().getDrawable(R.drawable.button_ripple_bg);
        assertThat(getDrawbleDefaultColor(secondary.getBackground()))
                .isEqualTo(getDrawbleDefaultColor(expected));
    }

    @Test
    public void test_bothButtons_areStyled_inDefaultLayout() {
        Button primaryButton = mCarSetupWizardCompatLayout.getPrimaryToolbarButton();
        Button secondaryButton = mCarSetupWizardCompatLayout.getSecondaryToolbarButton();

        assertThat(primaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
        assertThat(secondaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
    }

    @Test
    public void test_bothButtons_areStyled_inAlternativeLayout() {
        Activity activity = Robolectric
                .buildActivity(CarSetupWizardLayoutAlternativeActivity.class)
                .create()
                .get();
        CarSetupWizardCompatLayout layout = activity.findViewById(R.id.car_setup_wizard_layout);

        Button primaryButton = layout.getPrimaryToolbarButton();
        Button secondaryButton = layout.getSecondaryToolbarButton();

        assertThat(primaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
        assertThat(secondaryButton.getTextSize()).isWithin(TOLERANCE).of(EXCEPTED_TEXT_SIZE);
    }

    private void setupFakeContentProvider() {
        FakeOverrideContentProvider.installDefaultProvider();
    }

    private CarSetupWizardCompatLayout createCarSetupWizardCompatLayout() {
        Activity activity = Robolectric
                .buildActivity(CarSetupWizardLayoutTestActivity.class)
                .create()
                .get();

        return activity.findViewById(R.id.car_setup_wizard_layout);
    }

    private @ColorRes int getDrawbleDefaultColor(Drawable drawable) {
        Drawable.ConstantState state = drawable.getConstantState();
        ColorStateList colorStateList = ReflectionHelpers.getField(state, "mColor");
        return colorStateList.getDefaultColor();
    }

    private List<ResourceEntry> prepareFakeData() {
        ExternalResources.Resources testResources =
                ExternalResources.injectExternalResources(TEST_PACKAGE_NAME);

        testResources.putDimension(
                TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME.getResourceName(), EXCEPTED_TEXT_SIZE);

        return Arrays.asList(
                new ResourceEntry(
                        TEST_PACKAGE_NAME,
                        TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME.getResourceName(),
                        testResources.getIdentifier(
                                TEST_TOOLBAR_BUTTON_TEXT_SIZE_RESOURCE_NAME.getResourceName(),
                                /* defType= */ "dimen",
                                TEST_PACKAGE_NAME))
        );
    }
}