1 /*
2  * Copyright (C) 2018 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 
17 package com.android.documentsui.ui;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.mockito.Mockito.mock;
22 
23 import android.content.Context;
24 import android.graphics.Color;
25 import android.graphics.drawable.ColorDrawable;
26 
27 import androidx.coordinatorlayout.widget.CoordinatorLayout;
28 import androidx.test.InstrumentationRegistry;
29 
30 import com.android.documentsui.R;
31 
32 import com.google.android.material.appbar.AppBarLayout;
33 
34 import org.junit.Before;
35 import org.junit.Test;
36 
37 
38 public class SearchBarScrollingViewBehaviorTest {
39     private SearchBarScrollingViewBehavior mScrollingViewBehavior;
40     private Context mContext;
41 
42     @Before
setUp()43     public void setUp() {
44         mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
45         mScrollingViewBehavior = new SearchBarScrollingViewBehavior(mContext, null);
46     }
47 
48     @Test
shouldHeaderOverlapScrollingChild_returnTrue()49     public void shouldHeaderOverlapScrollingChild_returnTrue() {
50         assertTrue(mScrollingViewBehavior.shouldHeaderOverlapScrollingChild());
51     }
52 
53     @Test
setAppBarLayoutTransparent_defaultWhiteBackground_shouldBeTransparent()54     public void setAppBarLayoutTransparent_defaultWhiteBackground_shouldBeTransparent() {
55         mContext.setTheme(R.style.DocumentsTheme);
56         mContext.getTheme().applyStyle(R.style.DocumentsDefaultTheme, false);
57         final CoordinatorLayout coordinatorLayout = new CoordinatorLayout(mContext);
58         final AppBarLayout appBarLayout = new AppBarLayout(mContext);
59         final CoordinatorLayout.LayoutParams lp = mock(CoordinatorLayout.LayoutParams.class);
60         lp.setBehavior(mScrollingViewBehavior);
61         appBarLayout.setLayoutParams(lp);
62         appBarLayout.setBackgroundColor(Color.WHITE);
63         mScrollingViewBehavior.onDependentViewChanged(coordinatorLayout, null, appBarLayout);
64 
65         assertEquals(Color.TRANSPARENT, ((ColorDrawable) appBarLayout.getBackground()).getColor());
66     }
67 }
68