Commit d19a57db authored by jbudorick's avatar jbudorick Committed by Commit bot

[Android] Add support for command-line flags via annotation.

BUG=433539

Review URL: https://codereview.chromium.org/879993002

Cr-Commit-Position: refs/heads/master@{#314247}
parent 31bc0e86
...@@ -6,6 +6,7 @@ package org.chromium.base; ...@@ -6,6 +6,7 @@ package org.chromium.base;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.Window; import android.view.Window;
...@@ -96,4 +97,16 @@ public class BaseChromiumApplication extends Application { ...@@ -96,4 +97,16 @@ public class BaseChromiumApplication extends Application {
public void unregisterWindowFocusChangedListener(WindowFocusChangedListener listener) { public void unregisterWindowFocusChangedListener(WindowFocusChangedListener listener) {
mWindowFocusListeners.removeObserver(listener); mWindowFocusListeners.removeObserver(listener);
} }
/** Initializes the {@link CommandLine}. */
public void initCommandLine() {}
/**
* This must only be called for contexts whose application is a subclass of
* {@link BaseChromiumApplication}.
*/
@VisibleForTesting
public static void initCommandLine(Context context) {
((BaseChromiumApplication) context.getApplicationContext()).initCommandLine();
};
} }
...@@ -31,6 +31,7 @@ public abstract class CommandLine { ...@@ -31,6 +31,7 @@ public abstract class CommandLine {
* Returns true if this command line contains the given switch. * Returns true if this command line contains the given switch.
* (Switch names ARE case-sensitive). * (Switch names ARE case-sensitive).
*/ */
@VisibleForTesting
public abstract boolean hasSwitch(String switchString); public abstract boolean hasSwitch(String switchString);
/** /**
...@@ -57,6 +58,7 @@ public abstract class CommandLine { ...@@ -57,6 +58,7 @@ public abstract class CommandLine {
* this action happens before the switch is needed. * this action happens before the switch is needed.
* @param switchString the switch to add. It should NOT start with '--' ! * @param switchString the switch to add. It should NOT start with '--' !
*/ */
@VisibleForTesting
public abstract void appendSwitch(String switchString); public abstract void appendSwitch(String switchString);
/** /**
...@@ -96,6 +98,7 @@ public abstract class CommandLine { ...@@ -96,6 +98,7 @@ public abstract class CommandLine {
} }
// Equivalent to CommandLine::ForCurrentProcess in C++. // Equivalent to CommandLine::ForCurrentProcess in C++.
@VisibleForTesting
public static CommandLine getInstance() { public static CommandLine getInstance() {
CommandLine commandLine = sCommandLine.get(); CommandLine commandLine = sCommandLine.get();
assert commandLine != null; assert commandLine != null;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.base.test;
import android.app.Activity;
import android.content.Context;
import android.os.SystemClock;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import org.chromium.base.BaseChromiumApplication;
import org.chromium.base.CommandLine;
import org.chromium.base.test.util.CommandLineFlags;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Base class for all Activity-based Instrumentation tests.
*
* @param <T> The Activity type.
*/
public class BaseActivityInstrumentationTestCase<T extends Activity>
extends ActivityInstrumentationTestCase2<T> {
private static final String TAG = "BaseActivityInstrumentationTestCase";
private static final int SLEEP_INTERVAL = 50; // milliseconds
private static final int WAIT_DURATION = 5000; // milliseconds
/**
* Creates a instance for running tests against an Activity of the given class.
*
* @param activityClass The type of activity that will be tested.
*/
public BaseActivityInstrumentationTestCase(Class<T> activityClass) {
super(activityClass);
}
/**
* Sets up the CommandLine with the appropriate flags.
*
* This will add the difference of the sets of flags specified by {@link CommandLineFlags.Add}
* and {@link CommandLineFlags.Remove} to the {@link org.chromium.base.CommandLine}. Note that
* trying to remove a flag set externally, i.e. by the command-line flags file, will not work.
*/
@Override
protected void setUp() throws Exception {
super.setUp();
CommandLine.reset();
Context targetContext = getTargetContext();
assertNotNull("Unable to get a non-null target context.", targetContext);
BaseChromiumApplication.initCommandLine(targetContext);
Set<String> flags = getFlags(getClass().getMethod(getName()));
for (String flag : flags) {
CommandLine.getInstance().appendSwitch(flag);
}
}
/**
* Gets the target context.
*
* On older versions of Android, getTargetContext() may initially return null, so we have to
* wait for it to become available.
*
* @return The target {@link android.content.Context} if available; null otherwise.
*/
private Context getTargetContext() {
Context targetContext = getInstrumentation().getTargetContext();
try {
long startTime = SystemClock.uptimeMillis();
// TODO(jbudorick): Convert this to CriteriaHelper once that moves to base/.
while (targetContext == null
&& SystemClock.uptimeMillis() - startTime < WAIT_DURATION) {
Thread.sleep(SLEEP_INTERVAL);
targetContext = getInstrumentation().getTargetContext();
}
} catch (InterruptedException e) {
Log.e(TAG, "Interrupted while attempting to initialize the command line.");
}
return targetContext;
}
private static Set<String> getFlags(AnnotatedElement element) {
AnnotatedElement parent = (element instanceof Method)
? ((Method) element).getDeclaringClass()
: ((Class) element).getSuperclass();
Set<String> flags = (parent == null) ? new HashSet<String>() : getFlags(parent);
if (element.isAnnotationPresent(CommandLineFlags.Add.class)) {
flags.addAll(
Arrays.asList(element.getAnnotation(CommandLineFlags.Add.class).value()));
}
if (element.isAnnotationPresent(CommandLineFlags.Remove.class)) {
List<String> flagsToRemove =
Arrays.asList(element.getAnnotation(CommandLineFlags.Remove.class).value());
for (String flagToRemove : flagsToRemove) {
// If your test fails here, you have tried to remove a command-line flag via
// CommandLineFlags.Remove that was loaded into CommandLine via something other
// than CommandLineFlags.Add (probably the command-line flag file).
assertFalse("Unable to remove command-line flag \"" + flagToRemove + "\".",
CommandLine.getInstance().hasSwitch(flagToRemove));
}
flags.removeAll(flagsToRemove);
}
return flags;
}
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.base.test.util;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Provides annotations related to command-line flag handling.
*
* Uses of these annotations on a derived class will take precedence over uses on its base classes,
* so a derived class can add a command-line flag that a base class has removed (or vice versa).
* Similarly, uses of these annotations on a test method will take precedence over uses on the
* containing class.
*
* Note that this class should never be instantiated.
*/
public final class CommandLineFlags {
/**
* Adds command-line flags to the {@link org.chromium.base.CommandLine} for this test.
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Add {
String[] value();
}
/**
* Removes command-line flags from the {@link org.chromium.base.CommandLine} from this test.
*
* Note that this can only remove flags added via {@link Add} above.
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface Remove {
String[] value();
}
private CommandLineFlags() {}
}
...@@ -211,7 +211,7 @@ class InstrumentationTestInstance(test_instance.TestInstance): ...@@ -211,7 +211,7 @@ class InstrumentationTestInstance(test_instance.TestInstance):
if self._test_package == package_info.test_package: if self._test_package == package_info.test_package:
self._package_info = package_info self._package_info = package_info
if not self._package_info: if not self._package_info:
error_func('Unable to find package info for %s' % self._test_package) logging.warning('Unable to find package info for %s', self._test_package)
def __initializeDataDependencyAttributes(self, args, isolate_delegate): def __initializeDataDependencyAttributes(self, args, isolate_delegate):
self._data_deps = [] self._data_deps = []
......
...@@ -61,7 +61,7 @@ class LocalDeviceTestRun(test_run.TestRun): ...@@ -61,7 +61,7 @@ class LocalDeviceTestRun(test_run.TestRun):
tests = [t for t in tests if self._GetTestName(t) not in results_names] tests = [t for t in tests if self._GetTestName(t) not in results_names]
tries += 1 tries += 1
all_unknown_test_names = set(tests) all_unknown_test_names = set(self._GetTestName(t) for f in tests)
all_failed_test_names = set(all_fail_results.iterkeys()) all_failed_test_names = set(all_fail_results.iterkeys())
unknown_tests = all_unknown_test_names.difference(all_failed_test_names) unknown_tests = all_unknown_test_names.difference(all_failed_test_names)
......
...@@ -28,11 +28,10 @@ public class AddToHomescreenDialogTest extends ChromeShellTestBase { ...@@ -28,11 +28,10 @@ public class AddToHomescreenDialogTest extends ChromeShellTestBase {
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp();
mActivity = launchChromeShellWithBlankPage(); mActivity = launchChromeShellWithBlankPage();
ChromeShellApplication application = ChromeShellApplication application =
(ChromeShellApplication) mActivity.getApplication(); (ChromeShellApplication) mActivity.getApplication();
super.setUp();
} }
@SmallTest @SmallTest
......
...@@ -10,17 +10,19 @@ import android.content.ComponentName; ...@@ -10,17 +10,19 @@ import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.ProcessInitException; import org.chromium.base.library_loader.ProcessInitException;
import org.chromium.base.test.BaseActivityInstrumentationTestCase;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.chrome.test.util.ApplicationData; import org.chromium.chrome.test.util.ApplicationData;
import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.BrowserStartupController;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.common.ContentSwitches;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
...@@ -28,7 +30,8 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -28,7 +30,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
/** /**
* Base test class for all ChromeShell based tests. * Base test class for all ChromeShell based tests.
*/ */
public class ChromeShellTestBase extends ActivityInstrumentationTestCase2<ChromeShellActivity> { @CommandLineFlags.Add(ContentSwitches.ENABLE_TEST_INTENTS)
public class ChromeShellTestBase extends BaseActivityInstrumentationTestCase<ChromeShellActivity> {
/** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */ /** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */
private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeout(10000); private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeout(10000);
private static final String TAG = "ChromeShellTestBase"; private static final String TAG = "ChromeShellTestBase";
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
package org.chromium.content.app; package org.chromium.content.app;
import android.content.Context;
import android.os.Looper; import android.os.Looper;
import android.os.MessageQueue; import android.os.MessageQueue;
...@@ -85,11 +84,4 @@ public abstract class ContentApplication extends BaseChromiumApplication { ...@@ -85,11 +84,4 @@ public abstract class ContentApplication extends BaseChromiumApplication {
super.onTerminate(); super.onTerminate();
} }
public abstract void initCommandLine();
/// This must only be called for contexts whose application is a subclass of ContentApplication.
public static void initCommandLine(Context context) {
((ContentApplication) context.getApplicationContext()).initCommandLine();
};
} }
...@@ -11,10 +11,10 @@ import android.test.suitebuilder.annotation.SmallTest; ...@@ -11,10 +11,10 @@ import android.test.suitebuilder.annotation.SmallTest;
import junit.framework.Assert; import junit.framework.Assert;
import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer; import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_shell_apk.ContentShellActivity;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
...@@ -98,13 +98,6 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase { ...@@ -98,13 +98,6 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
setUpContentView(mTestController, "testController"); setUpContentView(mTestController, "testController");
} }
@Override
protected ContentShellActivity launchContentShellWithUrl(String url) {
// Expose a global function "gc()" into pages.
return launchContentShellWithUrlAndCommandLineArgs(
url, new String[]{ "--js-flags=--expose-gc" });
}
// Note that this requires that we can pass a JavaScript string to Java. // Note that this requires that we can pass a JavaScript string to Java.
protected String executeJavaScriptAndGetStringResult(String script) throws Throwable { protected String executeJavaScriptAndGetStringResult(String script) throws Throwable {
executeJavaScript("testController.setStringValue(" + script + ");"); executeJavaScript("testController.setStringValue(" + script + ");");
...@@ -471,6 +464,7 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase { ...@@ -471,6 +464,7 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
// leak. // leak.
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@CommandLineFlags.Add("js-flags=--expose-gc")
public void testReturnedObjectIsGarbageCollected() throws Throwable { public void testReturnedObjectIsGarbageCollected() throws Throwable {
// Make sure V8 exposes "gc" property on the global object (enabled with --expose-gc flag) // Make sure V8 exposes "gc" property on the global object (enabled with --expose-gc flag)
assertEquals("function", executeJavaScriptAndGetStringResult("typeof gc")); assertEquals("function", executeJavaScriptAndGetStringResult("typeof gc"));
......
...@@ -6,6 +6,7 @@ package org.chromium.content.browser; ...@@ -6,6 +6,7 @@ package org.chromium.content.browser;
import android.test.FlakyTest; import android.test.FlakyTest;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.content.common.ContentSwitches; import org.chromium.content.common.ContentSwitches;
...@@ -22,20 +23,6 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase { ...@@ -22,20 +23,6 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase {
return intentUrl.equals(expectedUrl); return intentUrl.equals(expectedUrl);
} }
/**
* Starts the content shell activity with the provided test URL and setting the local country
* to the one provided by its 2-letter ISO code.
* @param testUrl Test url to load.
* @param countryIso 2-letter ISO country code. If set to null only international numbers
* can be assumed to be supported.
*/
private void startActivityWithTestUrlAndCountryIso(String testUrl, String countryIso)
throws Throwable {
final String[] cmdlineArgs = countryIso == null ? null : new String[] {
"--" + ContentSwitches.NETWORK_COUNTRY_ISO + "=" + countryIso };
startActivityWithTestUrlAndCommandLineArgs(testUrl, cmdlineArgs);
}
/* @LargeTest */ /* @LargeTest */
@FlakyTest @FlakyTest
@Feature({"ContentDetection", "TabContents"}) @Feature({"ContentDetection", "TabContents"})
...@@ -155,8 +142,9 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase { ...@@ -155,8 +142,9 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase {
/* @MediumTest */ /* @MediumTest */
@FlakyTest @FlakyTest
@Feature({"ContentDetection", "TabContents"}) @Feature({"ContentDetection", "TabContents"})
@CommandLineFlags.Add(ContentSwitches.NETWORK_COUNTRY_ISO + "=US")
public void testLocalUSNumbers() throws Throwable { public void testLocalUSNumbers() throws Throwable {
startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "US"); startActivityWithTestUrl("content/content_detection/phone_local.html");
assertWaitForPageScaleFactorMatch(1.0f); assertWaitForPageScaleFactorMatch(1.0f);
// US_1: 1-888-433-5788. // US_1: 1-888-433-5788.
...@@ -179,8 +167,9 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase { ...@@ -179,8 +167,9 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase {
/* @MediumTest */ /* @MediumTest */
@FlakyTest @FlakyTest
@Feature({"ContentDetection", "TabContents"}) @Feature({"ContentDetection", "TabContents"})
@CommandLineFlags.Add(ContentSwitches.NETWORK_COUNTRY_ISO + "=GB")
public void testLocalUKNumbers() throws Throwable { public void testLocalUKNumbers() throws Throwable {
startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "GB"); startActivityWithTestUrl("content/content_detection/phone_local.html");
assertWaitForPageScaleFactorMatch(1.0f); assertWaitForPageScaleFactorMatch(1.0f);
// GB_1: (0) 20 7323 8299. // GB_1: (0) 20 7323 8299.
...@@ -203,8 +192,9 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase { ...@@ -203,8 +192,9 @@ public class PhoneNumberDetectionTest extends ContentDetectionTestBase {
/* @MediumTest */ /* @MediumTest */
@FlakyTest @FlakyTest
@Feature({"ContentDetection", "TabContents"}) @Feature({"ContentDetection", "TabContents"})
@CommandLineFlags.Add(ContentSwitches.NETWORK_COUNTRY_ISO + "=FR")
public void testLocalFRNumbers() throws Throwable { public void testLocalFRNumbers() throws Throwable {
startActivityWithTestUrlAndCountryIso("content/content_detection/phone_local.html", "FR"); startActivityWithTestUrl("content/content_detection/phone_local.html");
assertWaitForPageScaleFactorMatch(1.0f); assertWaitForPageScaleFactorMatch(1.0f);
// FR_1: 01 40 20 50 50. // FR_1: 01 40 20 50 50.
......
...@@ -9,11 +9,12 @@ import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; ...@@ -9,11 +9,12 @@ import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.test.ActivityInstrumentationTestCase2;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.BaseActivityInstrumentationTestCase;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.ContentView; import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.ContentViewCore; import org.chromium.content.browser.ContentViewCore;
...@@ -21,6 +22,7 @@ import org.chromium.content.browser.test.util.CallbackHelper; ...@@ -21,6 +22,7 @@ import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer; import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content.common.ContentSwitches;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.NavigationController; import org.chromium.content_public.browser.NavigationController;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -37,8 +39,9 @@ import java.util.concurrent.atomic.AtomicBoolean; ...@@ -37,8 +39,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
/** /**
* Base test class for all ContentShell based tests. * Base test class for all ContentShell based tests.
*/ */
public class ContentShellTestBase extends ActivityInstrumentationTestCase2<ContentShellActivity> { @CommandLineFlags.Add(ContentSwitches.ENABLE_TEST_INTENTS)
public class ContentShellTestBase
extends BaseActivityInstrumentationTestCase<ContentShellActivity> {
/** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */ /** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */
private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeout(10000); private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeout(10000);
...@@ -53,25 +56,12 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte ...@@ -53,25 +56,12 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
* The URL can be null, in which case will default to ContentShellActivity.DEFAULT_SHELL_URL. * The URL can be null, in which case will default to ContentShellActivity.DEFAULT_SHELL_URL.
*/ */
protected ContentShellActivity launchContentShellWithUrl(String url) { protected ContentShellActivity launchContentShellWithUrl(String url) {
return launchContentShellWithUrlAndCommandLineArgs(url, null);
}
/**
* Starts the ContentShell activity appending the provided command line arguments
* and loads the given URL. The URL can be null, in which case will default to
* ContentShellActivity.DEFAULT_SHELL_URL.
*/
protected ContentShellActivity launchContentShellWithUrlAndCommandLineArgs(String url,
String[] commandLineArgs) {
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (url != null) intent.setData(Uri.parse(url)); if (url != null) intent.setData(Uri.parse(url));
intent.setComponent(new ComponentName(getInstrumentation().getTargetContext(), intent.setComponent(new ComponentName(getInstrumentation().getTargetContext(),
ContentShellActivity.class)); ContentShellActivity.class));
if (commandLineArgs != null) {
intent.putExtra(ContentShellActivity.COMMAND_LINE_ARGS_KEY, commandLineArgs);
}
setActivityIntent(intent); setActivityIntent(intent);
return getActivity(); return getActivity();
} }
...@@ -91,21 +81,6 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte ...@@ -91,21 +81,6 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
assertEquals(UrlUtils.getTestFileUrl(url), getContentViewCore().getWebContents().getUrl()); assertEquals(UrlUtils.getTestFileUrl(url), getContentViewCore().getWebContents().getUrl());
} }
/**
* Starts the content shell activity with the provided test url and optional command line
* arguments to append.
* The url is synchronously loaded.
* @param url Test url to load.
* @param commandLineArgs Optional command line args to append when launching the activity.
*/
protected void startActivityWithTestUrlAndCommandLineArgs(
String url, String[] commandLineArgs) throws Throwable {
launchContentShellWithUrlAndCommandLineArgs(
UrlUtils.getTestFileUrl(url), commandLineArgs);
assertNotNull(getActivity());
assertTrue(waitForActiveShellToBeDoneLoading());
}
/** /**
* Returns the current ContentViewCore or null if there is no ContentView. * Returns the current ContentViewCore or null if there is no ContentView.
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment