1/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
6 *
7 *      http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
13 */
14
15package com.android.systemui.qs;
16
17import static org.mockito.ArgumentMatchers.any;
18import static org.mockito.ArgumentMatchers.anyBoolean;
19import static org.mockito.Mockito.never;
20import static org.mockito.Mockito.verify;
21import static org.mockito.Mockito.when;
22
23import android.support.test.filters.SmallTest;
24import android.testing.AndroidTestingRunner;
25import android.testing.TestableLooper;
26import android.testing.TestableLooper.RunWithLooper;
27import android.view.LayoutInflater;
28import android.view.View;
29
30import com.android.systemui.R;
31import com.android.systemui.R.id;
32import com.android.systemui.plugins.ActivityStarter;
33import com.android.systemui.statusbar.policy.DeviceProvisionedController;
34import com.android.systemui.utils.leaks.LeakCheckedTest;
35
36import org.junit.Before;
37import org.junit.Ignore;
38import org.junit.Test;
39import org.junit.runner.RunWith;
40
41@RunWith(AndroidTestingRunner.class)
42@RunWithLooper
43@SmallTest
44public class QSFooterTest extends LeakCheckedTest {
45
46    private QSFooter mFooter;
47    private ActivityStarter mActivityStarter;
48    private DeviceProvisionedController mDeviceProvisionedController;
49
50    @Before
51    public void setup() throws Exception {
52        injectLeakCheckedDependencies(ALL_SUPPORTED_CLASSES);
53        mActivityStarter = mDependency.injectMockDependency(ActivityStarter.class);
54        mDeviceProvisionedController = mDependency.injectMockDependency(
55                DeviceProvisionedController.class);
56        TestableLooper.get(this).runWithLooper(() -> {
57            mFooter = (QSFooter) LayoutInflater.from(mContext).inflate(R.layout.qs_footer, null);
58        });
59    }
60
61    @Test
62    public void testSettings_UserNotSetup() {
63        View settingsButton = mFooter.findViewById(id.settings_button);
64        when(mDeviceProvisionedController.isCurrentUserSetup()).thenReturn(false);
65
66        mFooter.onClick(settingsButton);
67        // Verify Settings wasn't launched.
68        verify(mActivityStarter, never()).startActivity(any(), anyBoolean());
69    }
70}
71