• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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.dirlist;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.content.Context;
22 import android.view.View;
23 import android.widget.Button;
24 
25 import androidx.test.filters.SmallTest;
26 import androidx.test.platform.app.InstrumentationRegistry;
27 
28 import com.android.documentsui.CrossProfileQuietModeException;
29 import com.android.documentsui.Model;
30 import com.android.documentsui.R;
31 import com.android.documentsui.base.State;
32 import com.android.documentsui.testing.TestActionHandler;
33 import com.android.documentsui.testing.TestEnv;
34 import com.android.documentsui.testing.TestProvidersAccess;
35 
36 import org.junit.Before;
37 import org.junit.Test;
38 
39 @SmallTest
40 public final class InflateMessageDocumentHolderTest {
41 
42     private Context mContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
43     private Runnable mDefaultCallback = () -> {
44     };
45     private Message mInflateMessage;
46     private TestActionHandler mTestActionHandler = new TestActionHandler();
47     private InflateMessageDocumentHolder mHolder;
48 
49     @Before
setUp()50     public void setUp() {
51         DocumentsAdapter.Environment env =
52                 new TestEnvironment(mContext, TestEnv.create(), mTestActionHandler);
53         env.getDisplayState().action = State.ACTION_GET_CONTENT;
54         env.getDisplayState().canShareAcrossProfile = true;
55         env.getDisplayState().supportsCrossProfile = true;
56         mInflateMessage = new Message.InflateMessage(env, mDefaultCallback);
57         mContext.setTheme(R.style.DocumentsTheme);
58         mContext.getTheme().applyStyle(R.style.DocumentsDefaultTheme,  /* force= */false);
59 
60         mHolder = new InflateMessageDocumentHolder(mContext, /* parent= */null);
61     }
62 
63     @Test
testClickingButtonShouldShowProgressBar()64     public void testClickingButtonShouldShowProgressBar() {
65         Model.Update error = new Model.Update(
66                 new CrossProfileQuietModeException(TestProvidersAccess.OtherUser.USER_ID),
67                 /* remoteActionsEnabled= */ true);
68         mInflateMessage.update(error);
69 
70         mHolder.bind(mInflateMessage);
71 
72         View content = mHolder.itemView.findViewById(R.id.content);
73         View crossProfile = mHolder.itemView.findViewById(R.id.cross_profile);
74         View crossProfileContent = mHolder.itemView.findViewById(R.id.cross_profile_content);
75         View progress = mHolder.itemView.findViewById(R.id.cross_profile_progress);
76         Button button = mHolder.itemView.findViewById(R.id.button);
77 
78         assertThat(content.getVisibility()).isEqualTo(View.GONE);
79         assertThat(crossProfile.getVisibility()).isEqualTo(View.VISIBLE);
80         assertThat(crossProfileContent.getVisibility()).isEqualTo(View.VISIBLE);
81         assertThat(progress.getVisibility()).isEqualTo(View.GONE);
82 
83         if (button.getVisibility() == View.VISIBLE) {
84             // The button is visible when docsUI has the permission to modify quiet mode.
85             assertThat(button.callOnClick()).isTrue();
86             assertThat(crossProfile.getVisibility()).isEqualTo(View.VISIBLE);
87             assertThat(crossProfileContent.getVisibility()).isEqualTo(View.GONE);
88             assertThat(progress.getVisibility()).isEqualTo(View.VISIBLE);
89         }
90     }
91 }
92