• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.sdksandbox.cts.host;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.app.sdksandbox.hosttestutils.SdkSandboxDeviceSupportedHostRule;
22 
23 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
24 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
25 
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 
32 @RunWith(DeviceJUnit4ClassRunner.class)
33 public final class CtsSdkSandboxStorageHostTest extends BaseHostJUnit4Test {
34 
35     @Rule(order = 0)
36     public final SdkSandboxDeviceSupportedHostRule deviceSupportRule =
37             new SdkSandboxDeviceSupportedHostRule(this);
38 
39     private static final String TEST_APP_PACKAGE_NAME = "com.android.sdksandbox.cts.app";
40     private static final String TEST_APP_APK_NAME = "CtsSdkSandboxHostTestApp.apk";
41 
42     /**
43      * Runs the given phase of a test by calling into the device. Throws an exception if the test
44      * phase fails.
45      *
46      * <p>For example, <code>runPhase("testExample");</code>
47      */
runPhase(String phase)48     private void runPhase(String phase) throws Exception {
49         assertThat(
50                         runDeviceTests(
51                                 TEST_APP_PACKAGE_NAME,
52                                 TEST_APP_PACKAGE_NAME + ".CtsSdkSandboxStorageTestApp",
53                                 phase))
54                 .isTrue();
55     }
56 
57     @Before
setUp()58     public void setUp() throws Exception {
59         uninstallPackage(TEST_APP_PACKAGE_NAME);
60     }
61 
62     @After
tearDown()63     public void tearDown() throws Exception {
64         uninstallPackage(TEST_APP_PACKAGE_NAME);
65     }
66 
67     @Test
testSharedPreferences_IsSyncedFromAppToSandbox()68     public void testSharedPreferences_IsSyncedFromAppToSandbox() throws Exception {
69         installPackage(TEST_APP_APK_NAME);
70         runPhase("testSharedPreferences_IsSyncedFromAppToSandbox");
71     }
72 
73     @Test
testSharedPreferences_SyncPropagatesUpdates()74     public void testSharedPreferences_SyncPropagatesUpdates() throws Exception {
75         installPackage(TEST_APP_APK_NAME);
76         runPhase("testSharedPreferences_SyncPropagatesUpdates");
77     }
78 
79     @Test
testSharedPreferences_SyncStartedBeforeLoadingSdk()80     public void testSharedPreferences_SyncStartedBeforeLoadingSdk() throws Exception {
81         installPackage(TEST_APP_APK_NAME);
82         runPhase("testSharedPreferences_SyncStartedBeforeLoadingSdk");
83     }
84 
85     @Test
testSharedPreferences_SyncRemoveKeys()86     public void testSharedPreferences_SyncRemoveKeys() throws Exception {
87         installPackage(TEST_APP_APK_NAME);
88         runPhase("testSharedPreferences_SyncRemoveKeys");
89     }
90 
91     @Test
testSharedPreferences_SyncedDataClearedOnSandboxRestart()92     public void testSharedPreferences_SyncedDataClearedOnSandboxRestart() throws Exception {
93         installPackage(TEST_APP_APK_NAME);
94         runPhase("testSharedPreferences_IsSyncedFromAppToSandbox");
95         runPhase("testSharedPreferences_SyncedDataClearedOnSandboxRestart");
96     }
97 }
98