summaryrefslogtreecommitdiff
path: root/tests/PhotoPicker/src/android/photopicker/cts/PhotoPickerSettingsTest.java
blob: 70e050212db67fe96c6135cde8f5d089c09625d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.photopicker.cts;

import static android.photopicker.cts.PhotoPickerCloudUtils.disableCloudMediaAndClearAllowedCloudProviders;
import static android.photopicker.cts.PhotoPickerCloudUtils.enableCloudMediaAndSetAllowedCloudProviders;
import static android.photopicker.cts.PhotoPickerCloudUtils.getAllowedProvidersDeviceConfig;
import static android.photopicker.cts.PhotoPickerCloudUtils.isCloudMediaEnabled;
import static android.photopicker.cts.util.PhotoPickerUiUtils.isPhotoPickerVisible;
import static android.photopicker.cts.util.PhotoPickerUiUtils.verifySettingsActionBarIsVisible;
import static android.photopicker.cts.util.PhotoPickerUiUtils.verifySettingsActivityIsVisible;
import static android.photopicker.cts.util.PhotoPickerUiUtils.verifySettingsDescriptionIsVisible;
import static android.photopicker.cts.util.PhotoPickerUiUtils.verifySettingsFragmentContainerExists;
import static android.photopicker.cts.util.PhotoPickerUiUtils.verifySettingsTitleIsVisible;

import android.content.Intent;
import android.os.Build;
import android.photopicker.cts.util.PhotoPickerUiUtils;
import android.provider.MediaStore;

import androidx.test.filters.SdkSuppress;
import androidx.test.uiautomator.UiObject;

import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * Photo Picker tests for settings page launched from the overflow menu in PhotoPickerActivity or
 * the Settings app.
 */
// TODO(b/195009187): Enabling settings page requires setting allowed_cloud_providers device config.
//  We currently can't do this in R.
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
public class PhotoPickerSettingsTest extends PhotoPickerBaseTest {

    private static boolean sCloudMediaPreviouslyEnabled;
    private static String sPreviouslyAllowedCloudProviders;

    @BeforeClass
    public static void setUpBeforeClass() {
        // Store the current CMP configs, so that we can reset them at the end of the test.
        sCloudMediaPreviouslyEnabled = isCloudMediaEnabled();
        if (sCloudMediaPreviouslyEnabled) {
            sPreviouslyAllowedCloudProviders = getAllowedProvidersDeviceConfig();
        }

        // Enable Settings menu item in PhotoPickerActivity's overflow menu.
        PhotoPickerCloudUtils.enableCloudMediaAndSetAllowedCloudProviders(
                /* allowedCloudProviders */ "not_empty");
    }

    @AfterClass
    public static void tearDownClass() {
        // Reset CloudMedia configs.
        if (sCloudMediaPreviouslyEnabled) {
            enableCloudMediaAndSetAllowedCloudProviders(sPreviouslyAllowedCloudProviders);
        } else {
            disableCloudMediaAndClearAllowedCloudProviders();
        }
    }

    @Test
    public void testSettingsLaunchFromOverflowMenu() throws Exception {
        // Launch PhotoPickerActivity.
        final Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
        mActivity.startActivityForResult(intent, REQUEST_CODE);
        sDevice.waitForIdle();
        Assume.assumeTrue("Assume photo picker activity is visible", isPhotoPickerVisible());

        // Click on the Settings menu item in the overflow menu.
        final UiObject settingsMenuItem = PhotoPickerUiUtils.findSettingsOverflowMenuItem(sDevice);
        PhotoPickerUiUtils.clickAndWait(sDevice, settingsMenuItem);

        // Verify PhotoPickerSettingsActivity is launched and visible.
        verifySettingsActivityIsVisible();
        verifySettingsActionBarIsVisible();
        verifySettingsTitleIsVisible();
        verifySettingsDescriptionIsVisible();
        verifySettingsFragmentContainerExists();
    }
}