1 // Copyright 2020 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.chrome.browser.customtabs; 6 7 import static org.junit.Assert.assertTrue; 8 9 import android.content.Intent; 10 import android.support.test.InstrumentationRegistry; 11 import android.view.View; 12 13 import androidx.test.filters.MediumTest; 14 15 import org.junit.Before; 16 import org.junit.Rule; 17 import org.junit.Test; 18 import org.junit.runner.RunWith; 19 20 import org.chromium.base.test.params.ParameterAnnotations; 21 import org.chromium.base.test.params.ParameterSet; 22 import org.chromium.base.test.params.ParameterizedRunner; 23 import org.chromium.base.test.util.CommandLineFlags; 24 import org.chromium.base.test.util.Feature; 25 import org.chromium.chrome.R; 26 import org.chromium.chrome.browser.flags.ChromeFeatureList; 27 import org.chromium.chrome.browser.flags.ChromeSwitches; 28 import org.chromium.chrome.browser.incognito.IncognitoDataTestUtils; 29 import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; 30 import org.chromium.chrome.test.util.browser.Features; 31 import org.chromium.net.test.EmbeddedTestServerRule; 32 import org.chromium.ui.test.util.RenderTestRule; 33 34 import java.io.IOException; 35 import java.util.Arrays; 36 import java.util.List; 37 import java.util.concurrent.TimeoutException; 38 39 /** 40 * Instrumentation Render tests for default {@link CustomTabActivity} UI. 41 */ 42 @RunWith(ParameterizedRunner.class) 43 @ParameterAnnotations.UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class) 44 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) 45 @Features.EnableFeatures({ChromeFeatureList.CCT_INCOGNITO}) 46 public class IncognitoCustomTabActivityRenderTest { 47 @ParameterAnnotations.ClassParameter 48 private static final List<ParameterSet> sClassParameter = 49 Arrays.asList(new ParameterSet().name("HTTPS").value(true), 50 new ParameterSet().name("HTTP").value(false)); 51 52 private static final String TEST_PAGE = "/chrome/test/data/android/google.html"; 53 private static final int PORT_NO = 31415; 54 55 private final boolean mRunWithHttps; 56 private Intent mIntent; 57 58 @Rule 59 public final CustomTabActivityTestRule mCustomTabActivityTestRule = 60 new CustomTabActivityTestRule(); 61 62 @Rule 63 public final EmbeddedTestServerRule mEmbeddedTestServerRule = new EmbeddedTestServerRule(); 64 65 @Rule 66 public final RenderTestRule mRenderTestRule = RenderTestRule.Builder.withPublicCorpus().build(); 67 68 @Before setUp()69 public void setUp() throws TimeoutException { 70 mEmbeddedTestServerRule.setServerUsesHttps(mRunWithHttps); 71 mEmbeddedTestServerRule.setServerPort(PORT_NO); 72 prepareCCTIntent(); 73 74 // Ensuring native is initialized before we access the CCT_INCOGNITO feature flag. 75 IncognitoDataTestUtils.fireAndWaitForCctWarmup(); 76 assertTrue(ChromeFeatureList.isEnabled(ChromeFeatureList.CCT_INCOGNITO)); 77 } 78 IncognitoCustomTabActivityRenderTest(boolean runWithHttps)79 public IncognitoCustomTabActivityRenderTest(boolean runWithHttps) { 80 mRunWithHttps = runWithHttps; 81 } 82 prepareCCTIntent()83 private void prepareCCTIntent() { 84 String url = mEmbeddedTestServerRule.getServer().getURL(TEST_PAGE); 85 mIntent = CustomTabsTestUtils.createMinimalIncognitoCustomTabIntent( 86 InstrumentationRegistry.getContext(), url); 87 } 88 startActivity(String renderTestId)89 private void startActivity(String renderTestId) throws IOException { 90 mCustomTabActivityTestRule.startCustomTabActivityWithIntent(mIntent); 91 View toolbarView = mCustomTabActivityTestRule.getActivity().findViewById(R.id.toolbar); 92 mRenderTestRule.render(toolbarView, renderTestId); 93 } 94 95 @Test 96 @MediumTest 97 @Feature("RenderTest") testCCTToolbar()98 public void testCCTToolbar() throws IOException { 99 startActivity("default_incognito_cct_toolbar_with_https_" + mRunWithHttps); 100 } 101 }