• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.tv.ui;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import static org.robolectric.Shadows.shadowOf;
21 
22 import android.app.Activity;
23 import android.content.Context;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.widget.ImageView;
27 
28 import com.android.tv.R;
29 import com.android.tv.common.flags.impl.DefaultLegacyFlags;
30 import com.android.tv.common.singletons.HasSingletons;
31 import com.android.tv.data.api.Channel;
32 import com.android.tv.data.api.Program;
33 import com.android.tv.dvr.DvrManager;
34 import com.android.tv.testing.TvRobolectricTestRunner;
35 import com.android.tv.testing.constants.ConfigConstants;
36 import com.android.tv.ui.ChannelBannerView.MySingletons;
37 import com.android.tv.util.TvInputManagerHelper;
38 
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.robolectric.Robolectric;
43 import org.robolectric.annotation.Config;
44 
45 import javax.inject.Provider;
46 
47 /** Tests for {@link ChannelBannerView}. */
48 @RunWith(TvRobolectricTestRunner.class)
49 @Config(sdk = ConfigConstants.SDK)
50 public class ChannelBannerViewTest {
51 
52     private TestActivity testActivity;
53     private ChannelBannerView mChannelBannerView;
54     private ImageView mChannelSignalStrengthView;
55 
56     @Before
setUp()57     public void setUp() {
58         testActivity = Robolectric.buildActivity(TestActivity.class).create().get();
59         mChannelBannerView =
60                 (ChannelBannerView)
61                         LayoutInflater.from(testActivity).inflate(R.layout.channel_banner, null);
62         mChannelSignalStrengthView = mChannelBannerView.findViewById(R.id.channel_signal_strength);
63     }
64 
65     @Test
updateChannelSignalStrengthView_valueIsNotValid()66     public void updateChannelSignalStrengthView_valueIsNotValid() {
67         mChannelBannerView.updateChannelSignalStrengthView(-1);
68         assertThat(mChannelSignalStrengthView.getVisibility()).isEqualTo(View.GONE);
69         mChannelBannerView.updateChannelSignalStrengthView(101);
70         assertThat(mChannelSignalStrengthView.getVisibility()).isEqualTo(View.GONE);
71     }
72 
73     @Test
updateChannelSignalStrengthView_20()74     public void updateChannelSignalStrengthView_20() {
75         mChannelBannerView.updateChannelSignalStrengthView(20);
76         assertThat(mChannelSignalStrengthView.getVisibility()).isEqualTo(View.VISIBLE);
77         assertThat(shadowOf(mChannelSignalStrengthView.getDrawable()).getCreatedFromResId())
78                 .isEqualTo(R.drawable.quantum_ic_signal_cellular_0_bar_white_24);
79     }
80 
81     @Test
updateChannelSignalStrengthView_40()82     public void updateChannelSignalStrengthView_40() {
83         mChannelBannerView.updateChannelSignalStrengthView(40);
84         assertThat(mChannelSignalStrengthView.getVisibility()).isEqualTo(View.VISIBLE);
85         assertThat(shadowOf(mChannelSignalStrengthView.getDrawable()).getCreatedFromResId())
86                 .isEqualTo(R.drawable.quantum_ic_signal_cellular_1_bar_white_24);
87     }
88 
89     @Test
updateChannelSignalStrengthView_60()90     public void updateChannelSignalStrengthView_60() {
91         mChannelBannerView.updateChannelSignalStrengthView(60);
92         assertThat(mChannelSignalStrengthView.getVisibility()).isEqualTo(View.VISIBLE);
93         assertThat(shadowOf(mChannelSignalStrengthView.getDrawable()).getCreatedFromResId())
94                 .isEqualTo(R.drawable.quantum_ic_signal_cellular_2_bar_white_24);
95     }
96 
97     @Test
updateChannelSignalStrengthView_80()98     public void updateChannelSignalStrengthView_80() {
99         mChannelBannerView.updateChannelSignalStrengthView(80);
100         assertThat(mChannelSignalStrengthView.getVisibility()).isEqualTo(View.VISIBLE);
101         assertThat(shadowOf(mChannelSignalStrengthView.getDrawable()).getCreatedFromResId())
102                 .isEqualTo(R.drawable.quantum_ic_signal_cellular_3_bar_white_24);
103     }
104 
105     @Test
updateChannelSignalStrengthView_100()106     public void updateChannelSignalStrengthView_100() {
107         mChannelBannerView.updateChannelSignalStrengthView(100);
108         assertThat(mChannelSignalStrengthView.getVisibility()).isEqualTo(View.VISIBLE);
109         assertThat(shadowOf(mChannelSignalStrengthView.getDrawable()).getCreatedFromResId())
110                 .isEqualTo(R.drawable.quantum_ic_signal_cellular_4_bar_white_24);
111     }
112 
113     /** An activity for {@link ChannelBannerViewTest}. */
114     public static class TestActivity extends Activity implements HasSingletons<MySingletons> {
115 
116         MySingletonsImpl mSingletons = new MySingletonsImpl();
117         Context mContext = this;
118 
119         @Override
singletons()120         public ChannelBannerView.MySingletons singletons() {
121             return mSingletons;
122         }
123 
124         /** MySingletons implementation needed for this class. */
125         public class MySingletonsImpl implements ChannelBannerView.MySingletons {
126 
127             @Override
getCurrentChannelProvider()128             public Provider<Channel> getCurrentChannelProvider() {
129                 return null;
130             }
131 
132             @Override
getCurrentProgramProvider()133             public Provider<Program> getCurrentProgramProvider() {
134                 return null;
135             }
136 
137             @Override
getOverlayManagerProvider()138             public Provider<TvOverlayManager> getOverlayManagerProvider() {
139                 return null;
140             }
141 
142             @Override
getTvInputManagerHelperSingleton()143             public TvInputManagerHelper getTvInputManagerHelperSingleton() {
144                 return new TvInputManagerHelper(mContext, DefaultLegacyFlags.DEFAULT);
145             }
146 
147             @Override
getCurrentPlayingPositionProvider()148             public Provider<Long> getCurrentPlayingPositionProvider() {
149                 return null;
150             }
151 
152             @Override
getDvrManagerSingleton()153             public DvrManager getDvrManagerSingleton() {
154                 return null;
155             }
156         }
157     }
158 }
159