• 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 
17 package com.android.settings.slices;
18 
19 import static com.android.settings.search.DeviceIndexFeatureProvider.createDeepLink;
20 
21 import android.content.Context;
22 import android.content.Intent;
23 import android.net.Uri;
24 import android.platform.test.annotations.Presubmit;
25 import android.support.test.InstrumentationRegistry;
26 import android.support.test.filters.MediumTest;
27 import android.support.test.runner.AndroidJUnit4;
28 
29 import com.android.settings.bluetooth.BluetoothSliceBuilder;
30 import com.android.settings.location.LocationSliceBuilder;
31 import com.android.settings.notification.ZenModeSliceBuilder;
32 import com.android.settings.wifi.WifiSliceBuilder;
33 
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 
38 @RunWith(AndroidJUnit4.class)
39 @MediumTest
40 public class SliceDeepLinkSpringBoardTest {
41     private Context mContext;
42 
43     @Before
setUp()44     public void setUp() {
45         mContext = InstrumentationRegistry.getTargetContext();
46     }
47 
48     @Test
49     @Presubmit
launchesDeepLinkIntent_shouldNotCrash()50     public void launchesDeepLinkIntent_shouldNotCrash() {
51         final Intent deepLinkIntent = getSpringboardIntent(
52                 "content://com.android.settings.slices/action/test_slice");
53 
54         mContext.startActivity(deepLinkIntent);
55     }
56 
57     @Test
58     @Presubmit
launchesDeepLinkIntent_wifiSlice_shouldNotCrash()59     public void launchesDeepLinkIntent_wifiSlice_shouldNotCrash() {
60         final Intent deepLinkIntent = getSpringboardIntent(WifiSliceBuilder.WIFI_URI.toString());
61 
62         mContext.startActivity(deepLinkIntent);
63     }
64 
65     @Test
66     @Presubmit
launchesDeepLinkIntent_bluetoothSlice_shouldNotCrash()67     public void launchesDeepLinkIntent_bluetoothSlice_shouldNotCrash() {
68         final Intent deepLinkIntent = getSpringboardIntent(
69                 BluetoothSliceBuilder.BLUETOOTH_URI.toString());
70 
71         mContext.startActivity(deepLinkIntent);
72     }
73 
74     @Test
75     @Presubmit
launchesDeepLinkIntent_dndSlice_shouldNotCrash()76     public void launchesDeepLinkIntent_dndSlice_shouldNotCrash() {
77         final Intent deepLinkIntent = getSpringboardIntent(
78                 ZenModeSliceBuilder.ZEN_MODE_URI.toString());
79 
80         mContext.startActivity(deepLinkIntent);
81     }
82 
83     @Test
84     @Presubmit
launchesDeepLinkIntent_locationSlice_shouldNotCrash()85     public void launchesDeepLinkIntent_locationSlice_shouldNotCrash() {
86         final Intent deepLinkIntent = getSpringboardIntent(
87                 LocationSliceBuilder.LOCATION_URI.toString());
88 
89         mContext.startActivity(deepLinkIntent);
90     }
91 
getSpringboardIntent(String uriString)92     private Intent getSpringboardIntent(String uriString) {
93         final Uri uri = createDeepLink(new Intent(SliceDeepLinkSpringBoard.ACTION_VIEW_SLICE)
94                 .setPackage(mContext.getPackageName())
95                 .putExtra(SliceDeepLinkSpringBoard.EXTRA_SLICE, uriString)
96                 .toUri(Intent.URI_ANDROID_APP_SCHEME));
97 
98         return new Intent(Intent.ACTION_VIEW)
99                 .setData(uri)
100                 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
101     }
102 }
103