/* * Copyright 2022 Google LLC * * 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 com.google.android.libraries.mobiledatadownload; import static com.google.android.libraries.mobiledatadownload.TestFileGroupPopulator.FILE_CHECKSUM; import static com.google.android.libraries.mobiledatadownload.TestFileGroupPopulator.FILE_ID; import static com.google.android.libraries.mobiledatadownload.TestFileGroupPopulator.FILE_SIZE; import static com.google.android.libraries.mobiledatadownload.TestFileGroupPopulator.FILE_URL; import static com.google.android.libraries.mobiledatadownload.testing.MddTestDependencies.ExecutorType; import static com.google.common.truth.Truth.assertThat; import static java.util.concurrent.TimeUnit.SECONDS; import android.accounts.Account; import android.content.Context; import androidx.test.core.app.ApplicationProvider; import com.google.android.libraries.mobiledatadownload.account.AccountUtil; import com.google.android.libraries.mobiledatadownload.file.SynchronousFileStorage; import com.google.android.libraries.mobiledatadownload.file.backends.AndroidFileBackend; import com.google.android.libraries.mobiledatadownload.file.backends.JavaFileBackend; import com.google.android.libraries.mobiledatadownload.monitor.NetworkUsageMonitor; import com.google.android.libraries.mobiledatadownload.testing.FakeTimeSource; import com.google.android.libraries.mobiledatadownload.testing.MddTestDependencies; import com.google.android.libraries.mobiledatadownload.testing.TestFileDownloader; import com.google.android.libraries.mobiledatadownload.testing.TestFlags; import com.google.common.base.Optional; import com.google.common.collect.ImmutableList; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.ListeningScheduledExecutorService; import com.google.common.util.concurrent.MoreExecutors; import com.google.mobiledatadownload.ClientConfigProto.ClientFileGroup; import com.google.mobiledatadownload.DownloadConfigProto.DataFile; import com.google.mobiledatadownload.DownloadConfigProto.DataFileGroup; import com.google.mobiledatadownload.DownloadConfigProto.DownloadConditions; import com.google.mobiledatadownload.DownloadConfigProto.DownloadConditions.DeviceNetworkPolicy; import com.google.testing.junit.testparameterinjector.TestParameter; import com.google.testing.junit.testparameterinjector.TestParameterInjector; import java.util.concurrent.Executors; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnit; import org.mockito.junit.MockitoRule; /** * Integration Tests that relate to interactions with MDD's Isolated Structures feature * *
Tests should be included here if they test MDD's behavior regarding reading/writing isolated
* structure groups.
*/
@RunWith(TestParameterInjector.class)
public class MobileDataDownloadIsolatedStructuresIntegrationTest {
private static final String TAG = "MDDIsolatedStructuresIntegrationTest";
private static final int MAX_MDD_API_WAIT_TIME_SECS = 5;
private static final String GROUP_NAME_1 = "test-group-1";
private static final String GROUP_NAME_2 = "test-group-2";
private static final String VARIANT_1 = "test-variant-1";
private static final String VARIANT_2 = "test-variant-2";
private static final Account ACCOUNT_1 = AccountUtil.create("account-name-1", "account-type");
private static final Account ACCOUNT_2 = AccountUtil.create("account-name-2", "account-type");
private static final String TEST_DATA_RELATIVE_PATH =
"third_party/java_src/android_libs/mobiledatadownload/javatests/com/google/android/libraries/mobiledatadownload/testdata/";
private static final ListeningScheduledExecutorService DOWNLOAD_EXECUTOR =
MoreExecutors.listeningDecorator(Executors.newScheduledThreadPool(2));
private static final Context context = ApplicationProvider.getApplicationContext();
private final NetworkUsageMonitor networkUsageMonitor =
new NetworkUsageMonitor(context, new FakeTimeSource());
private final SynchronousFileStorage fileStorage =
new SynchronousFileStorage(
ImmutableList.of(AndroidFileBackend.builder(context).build(), new JavaFileBackend()),
ImmutableList.of(),
ImmutableList.of(networkUsageMonitor));
private final TestFlags flags = new TestFlags();
private ListeningExecutorService controlExecutor;
@Mock private Logger mockLogger;
@Mock private TaskScheduler mockTaskScheduler;
@Rule(order = 1)
public final MockitoRule mocks = MockitoJUnit.rule();
@TestParameter ExecutorType controlExecutorType;
@Before
public void setUp() throws Exception {
controlExecutor = controlExecutorType.executor();
}
@Test
public void addFileGroup_whenImmediatelyComplete_createsCorrectIsolatedRoot(
@TestParameter boolean sameGroupName,
@TestParameter boolean sameAccount,
@TestParameter boolean sameVariantId)
throws Exception {
Optional