1/*
2 * Copyright (C) 2016 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 android.support.design.widget;
18
19import static org.junit.Assert.assertEquals;
20import static org.junit.Assert.assertNotNull;
21
22import android.support.design.test.R;
23import android.support.design.testutils.SnackbarUtils;
24import android.support.test.filters.SdkSuppress;
25import android.support.v4.view.WindowInsetsCompat;
26import android.test.suitebuilder.annotation.MediumTest;
27import android.view.View;
28
29import org.junit.Before;
30import org.junit.Test;
31
32@SdkSuppress(minSdkVersion = 21)
33public class SnackbarTestWithTranslucentNavBar
34        extends BaseInstrumentationTestCase<SnackbarActivityWithTranslucentNavBar> {
35
36    private static final String MESSAGE_TEXT = "Test Message";
37
38    private CoordinatorLayout mCoordinatorLayout;
39
40    public SnackbarTestWithTranslucentNavBar() {
41        super(SnackbarActivityWithTranslucentNavBar.class);
42    }
43
44    @Before
45    public void setup() {
46        mCoordinatorLayout =
47                (CoordinatorLayout) mActivityTestRule.getActivity().findViewById(R.id.col);
48    }
49
50    @Test
51    @MediumTest
52    public void testDrawsAboveNavigationBar() {
53        // Show a simple Snackbar and wait for it to be shown
54        final Snackbar snackbar = Snackbar.make(mCoordinatorLayout, MESSAGE_TEXT,
55                Snackbar.LENGTH_SHORT);
56        SnackbarUtils.showSnackbarAndWaitUntilFullyShown(snackbar);
57
58        final WindowInsetsCompat colLastInsets = mCoordinatorLayout.getLastWindowInsets();
59        assertNotNull(colLastInsets);
60
61        // Check that the Snackbar view has padding set to display above the nav bar
62        final View view = snackbar.getView();
63        assertNotNull(view);
64        assertEquals(colLastInsets.getSystemWindowInsetBottom(), view.getPaddingBottom());
65    }
66}
67