Commit fdb2d73d authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Add InstrumentationActivity

WebLayerShellActivity currently serves two purposes.
* As a demo app for weblayer where user can type in a url and expect it
  behave somewhat like a browser.
* As the target activity for instrumentation tests.

Keeping both purposes in the same activity is a maintenance burden and
makes the more complicated than it needs to be. This CL creates a new
InstrumentationActivity (copied from WebLayerShellActivity) and removes
code from both Activity that's needed for their purpose.

Also rename WebLayerShellActivityTestRule to
InstrumentationActivityTestRule.

Change-Id: I306fecb57ed15ee7a59487ced40262094ef7c438
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1888451
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710848}
parent 627c85bd
...@@ -28,8 +28,10 @@ android_library("weblayer_shell_java") { ...@@ -28,8 +28,10 @@ android_library("weblayer_shell_java") {
"//third_party/android_deps:android_support_v4_java", "//third_party/android_deps:android_support_v4_java",
"//weblayer/public/java", "//weblayer/public/java",
] ]
java_files = java_files = [
[ "shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java" ] "shell_apk/src/org/chromium/weblayer/shell/InstrumentationActivity.java",
"shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java",
]
} }
template("weblayer_shell_apk_helper") { template("weblayer_shell_apk_helper") {
...@@ -210,20 +212,19 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") { ...@@ -210,20 +212,19 @@ instrumentation_test_apk("weblayer_instrumentation_test_apk") {
] ]
java_files = [ java_files = [
"javatests/src/org/chromium/weblayer/test/BrowserObserverTest.java", "javatests/src/org/chromium/weblayer/test/BrowserObserverTest.java",
"javatests/src/org/chromium/weblayer/test/DataClearingTest.java",
"javatests/src/org/chromium/weblayer/test/DownloadDelegateTest.java", "javatests/src/org/chromium/weblayer/test/DownloadDelegateTest.java",
"javatests/src/org/chromium/weblayer/test/EventUtils.java", "javatests/src/org/chromium/weblayer/test/EventUtils.java",
"javatests/src/org/chromium/weblayer/test/FullscreenDelegateTest.java",
"javatests/src/org/chromium/weblayer/test/NavigationTest.java",
"javatests/src/org/chromium/weblayer/test/DataClearingTest.java",
"javatests/src/org/chromium/weblayer/test/SmokeTest.java",
"javatests/src/org/chromium/weblayer/test/EventUtils.java", "javatests/src/org/chromium/weblayer/test/EventUtils.java",
"javatests/src/org/chromium/weblayer/test/ExecuteScriptTest.java", "javatests/src/org/chromium/weblayer/test/ExecuteScriptTest.java",
"javatests/src/org/chromium/weblayer/test/RenderingTest.java",
"javatests/src/org/chromium/weblayer/test/TopControlsTest.java",
"javatests/src/org/chromium/weblayer/test/WebLayerShellActivityTestRule.java",
"javatests/src/org/chromium/weblayer/test/FragmentRestoreTest.java", "javatests/src/org/chromium/weblayer/test/FragmentRestoreTest.java",
"javatests/src/org/chromium/weblayer/test/FullscreenDelegateTest.java",
"javatests/src/org/chromium/weblayer/test/InputTypesTest.java", "javatests/src/org/chromium/weblayer/test/InputTypesTest.java",
"shell_apk/src/org/chromium/weblayer/shell/WebLayerShellActivity.java", "javatests/src/org/chromium/weblayer/test/InstrumentationActivityTestRule.java",
"javatests/src/org/chromium/weblayer/test/NavigationTest.java",
"javatests/src/org/chromium/weblayer/test/RenderingTest.java",
"javatests/src/org/chromium/weblayer/test/SmokeTest.java",
"javatests/src/org/chromium/weblayer/test/TopControlsTest.java",
] ]
additional_apks = [ additional_apks = [
"//weblayer/shell/android:weblayer_support_apk", "//weblayer/shell/android:weblayer_support_apk",
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<uses-library android:name="android.test.runner" /> <uses-library android:name="android.test.runner" />
<activity android:name="org.chromium.test.broker.OnDeviceInstrumentationBroker" <activity android:name="org.chromium.test.broker.OnDeviceInstrumentationBroker"
android:exported="true"/> android:exported="true"/>
<activity android:name="org.chromium.weblayer.shell.WebLayerShellActivity"> <activity android:name="org.chromium.weblayer.shell.InstrumentationActivity">
<!-- Add these intent filters so tests can resolve these intents. --> <!-- Add these intent filters so tests can resolve these intents. -->
<intent-filter> <intent-filter>
<action android:name="android.provider.MediaStore.RECORD_SOUND" /> <action android:name="android.provider.MediaStore.RECORD_SOUND" />
......
...@@ -16,7 +16,7 @@ import org.chromium.content_public.browser.test.util.Criteria; ...@@ -16,7 +16,7 @@ import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.BrowserObserver; import org.chromium.weblayer.BrowserObserver;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -28,7 +28,8 @@ import java.util.List; ...@@ -28,7 +28,8 @@ import java.util.List;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class BrowserObserverTest { public class BrowserObserverTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private static class Observer extends BrowserObserver { private static class Observer extends BrowserObserver {
public static class BrowserObserverValueRecorder { public static class BrowserObserverValueRecorder {
...@@ -69,7 +70,7 @@ public class BrowserObserverTest { ...@@ -69,7 +70,7 @@ public class BrowserObserverTest {
@SmallTest @SmallTest
public void testLoadEvents() { public void testLoadEvents() {
String startupUrl = "about:blank"; String startupUrl = "about:blank";
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(startupUrl); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(startupUrl);
Observer observer = new Observer(); Observer observer = new Observer();
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
......
...@@ -20,7 +20,7 @@ import org.junit.runner.RunWith; ...@@ -20,7 +20,7 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.weblayer.Profile; import org.chromium.weblayer.Profile;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -31,7 +31,8 @@ import java.util.concurrent.TimeUnit; ...@@ -31,7 +31,8 @@ import java.util.concurrent.TimeUnit;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class DataClearingTest { public class DataClearingTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
@Test @Test
@SmallTest @SmallTest
...@@ -68,7 +69,7 @@ public class DataClearingTest { ...@@ -68,7 +69,7 @@ public class DataClearingTest {
@Test @Test
@SmallTest @SmallTest
public void twoSuccesiveRequestsTriggerCallbacks() throws InterruptedException { public void twoSuccesiveRequestsTriggerCallbacks() throws InterruptedException {
WebLayerShellActivity activity = launchWithProfile("profile"); InstrumentationActivity activity = launchWithProfile("profile");
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
runOnUiThreadBlocking(() -> { runOnUiThreadBlocking(() -> {
...@@ -84,7 +85,7 @@ public class DataClearingTest { ...@@ -84,7 +85,7 @@ public class DataClearingTest {
@Test @Test
@SmallTest @SmallTest
public void clearingAgainAfterClearFinished_TriggersCallback() throws InterruptedException { public void clearingAgainAfterClearFinished_TriggersCallback() throws InterruptedException {
WebLayerShellActivity activity = launchWithProfile("profile"); InstrumentationActivity activity = launchWithProfile("profile");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
runOnUiThreadBlocking(() -> { runOnUiThreadBlocking(() -> {
...@@ -100,7 +101,7 @@ public class DataClearingTest { ...@@ -100,7 +101,7 @@ public class DataClearingTest {
@Test @Test
@SmallTest @SmallTest
public void destroyingProfileDuringDataClear_DoesntCrash() throws InterruptedException { public void destroyingProfileDuringDataClear_DoesntCrash() throws InterruptedException {
WebLayerShellActivity activity = launchWithProfile("profile"); InstrumentationActivity activity = launchWithProfile("profile");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
runOnUiThreadBlocking(() -> { runOnUiThreadBlocking(() -> {
...@@ -119,19 +120,18 @@ public class DataClearingTest { ...@@ -119,19 +120,18 @@ public class DataClearingTest {
private void checkTriggersCallbackOnClearData(int[] dataTypes, String profileName) private void checkTriggersCallbackOnClearData(int[] dataTypes, String profileName)
throws InterruptedException { throws InterruptedException {
WebLayerShellActivity activity = launchWithProfile(profileName); InstrumentationActivity activity = launchWithProfile(profileName);
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
runOnUiThreadBlocking(() -> activity.getBrowserFragmentController().getProfile() runOnUiThreadBlocking(() -> activity.getBrowserFragmentController().getProfile()
.clearBrowsingData(dataTypes).addCallback((ignored) -> latch.countDown())); .clearBrowsingData(dataTypes).addCallback((ignored) -> latch.countDown()));
assertTrue(latch.await(3, TimeUnit.SECONDS)); assertTrue(latch.await(3, TimeUnit.SECONDS));
} }
private WebLayerShellActivity launchWithProfile(String profileName) { private InstrumentationActivity launchWithProfile(String profileName) {
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(WebLayerShellActivity.EXTRA_PROFILE_NAME, profileName); extras.putString(InstrumentationActivity.EXTRA_PROFILE_NAME, profileName);
String url = "data:text,foo"; String url = "data:text,foo";
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(url, extras); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(url, extras);
return activity; return activity;
} }
} }
...@@ -22,7 +22,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -22,7 +22,7 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.net.test.util.TestWebServer; import org.chromium.net.test.util.TestWebServer;
import org.chromium.weblayer.DownloadDelegate; import org.chromium.weblayer.DownloadDelegate;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -33,9 +33,10 @@ import java.util.List; ...@@ -33,9 +33,10 @@ import java.util.List;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class DownloadDelegateTest { public class DownloadDelegateTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private WebLayerShellActivity mActivity; private InstrumentationActivity mActivity;
private Delegate mDelegate; private Delegate mDelegate;
private static class Delegate extends DownloadDelegate { private static class Delegate extends DownloadDelegate {
......
...@@ -16,7 +16,7 @@ import org.chromium.base.test.BaseJUnit4ClassRunner; ...@@ -16,7 +16,7 @@ import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.BrowserController; import org.chromium.weblayer.BrowserController;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
/** /**
* Tests that script execution works as expected. * Tests that script execution works as expected.
...@@ -24,7 +24,8 @@ import org.chromium.weblayer.shell.WebLayerShellActivity; ...@@ -24,7 +24,8 @@ import org.chromium.weblayer.shell.WebLayerShellActivity;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class ExecuteScriptTest { public class ExecuteScriptTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private static final String DATA_URL = UrlUtils.encodeHtmlDataUri( private static final String DATA_URL = UrlUtils.encodeHtmlDataUri(
"<html><head><script>var bar = 10;</script></head><body>foo</body></html>"); "<html><head><script>var bar = 10;</script></head><body>foo</body></html>");
...@@ -32,7 +33,7 @@ public class ExecuteScriptTest { ...@@ -32,7 +33,7 @@ public class ExecuteScriptTest {
@Test @Test
@SmallTest @SmallTest
public void testBasicScript() throws Exception { public void testBasicScript() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL);
JSONObject result = mActivityTestRule.executeScriptSync("document.body.innerHTML"); JSONObject result = mActivityTestRule.executeScriptSync("document.body.innerHTML");
Assert.assertEquals(result.getString(BrowserController.SCRIPT_RESULT_KEY), "foo"); Assert.assertEquals(result.getString(BrowserController.SCRIPT_RESULT_KEY), "foo");
} }
...@@ -40,7 +41,7 @@ public class ExecuteScriptTest { ...@@ -40,7 +41,7 @@ public class ExecuteScriptTest {
@Test @Test
@SmallTest @SmallTest
public void testScriptIsolatedFromPage() throws Exception { public void testScriptIsolatedFromPage() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL);
JSONObject result = mActivityTestRule.executeScriptSync("bar"); JSONObject result = mActivityTestRule.executeScriptSync("bar");
Assert.assertTrue(result.isNull(BrowserController.SCRIPT_RESULT_KEY)); Assert.assertTrue(result.isNull(BrowserController.SCRIPT_RESULT_KEY));
} }
...@@ -48,7 +49,7 @@ public class ExecuteScriptTest { ...@@ -48,7 +49,7 @@ public class ExecuteScriptTest {
@Test @Test
@SmallTest @SmallTest
public void testScriptNotIsolatedFromOtherScript() throws Exception { public void testScriptNotIsolatedFromOtherScript() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL);
mActivityTestRule.executeScriptSync("var foo = 20;"); mActivityTestRule.executeScriptSync("var foo = 20;");
JSONObject result = mActivityTestRule.executeScriptSync("foo"); JSONObject result = mActivityTestRule.executeScriptSync("foo");
Assert.assertEquals(result.getInt(BrowserController.SCRIPT_RESULT_KEY), 20); Assert.assertEquals(result.getInt(BrowserController.SCRIPT_RESULT_KEY), 20);
...@@ -57,7 +58,7 @@ public class ExecuteScriptTest { ...@@ -57,7 +58,7 @@ public class ExecuteScriptTest {
@Test @Test
@SmallTest @SmallTest
public void testClearedOnNavigate() throws Exception { public void testClearedOnNavigate() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL);
mActivityTestRule.executeScriptSync("var foo = 20;"); mActivityTestRule.executeScriptSync("var foo = 20;");
String newUrl = UrlUtils.encodeHtmlDataUri("<html></html>"); String newUrl = UrlUtils.encodeHtmlDataUri("<html></html>");
...@@ -69,7 +70,7 @@ public class ExecuteScriptTest { ...@@ -69,7 +70,7 @@ public class ExecuteScriptTest {
@Test @Test
@SmallTest @SmallTest
public void testNullCallback() throws Exception { public void testNullCallback() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(DATA_URL);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
// Null callback should not crash. // Null callback should not crash.
activity.getBrowserController().executeScript("null", null); activity.getBrowserController().executeScript("null", null);
......
...@@ -15,7 +15,8 @@ import org.chromium.base.test.BaseJUnit4ClassRunner; ...@@ -15,7 +15,8 @@ import org.chromium.base.test.BaseJUnit4ClassRunner;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class FragmentRestoreTest { public class FragmentRestoreTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
@Test @Test
@SmallTest @SmallTest
......
...@@ -20,7 +20,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper; ...@@ -20,7 +20,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.weblayer.FullscreenDelegate; import org.chromium.weblayer.FullscreenDelegate;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
/** /**
* Tests that FullscreenDelegate methods are invoked as expected. * Tests that FullscreenDelegate methods are invoked as expected.
...@@ -28,10 +28,11 @@ import org.chromium.weblayer.shell.WebLayerShellActivity; ...@@ -28,10 +28,11 @@ import org.chromium.weblayer.shell.WebLayerShellActivity;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class FullscreenDelegateTest { public class FullscreenDelegateTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
private WebLayerShellActivity mActivity; private InstrumentationActivity mActivity;
private Delegate mDelegate; private Delegate mDelegate;
private static class Delegate extends FullscreenDelegate { private static class Delegate extends FullscreenDelegate {
......
...@@ -26,7 +26,7 @@ import org.chromium.base.test.BaseJUnit4ClassRunner; ...@@ -26,7 +26,7 @@ import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.io.File; import java.io.File;
...@@ -36,12 +36,13 @@ import java.io.File; ...@@ -36,12 +36,13 @@ import java.io.File;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class InputTypesTest { public class InputTypesTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private EmbeddedTestServer mTestServer; private EmbeddedTestServer mTestServer;
private File mTempFile; private File mTempFile;
private class FileIntentInterceptor implements WebLayerShellActivity.IntentInterceptor { private class FileIntentInterceptor implements InstrumentationActivity.IntentInterceptor {
public Intent mLastIntent; public Intent mLastIntent;
private Intent mResponseIntent; private Intent mResponseIntent;
...@@ -82,7 +83,7 @@ public class InputTypesTest { ...@@ -82,7 +83,7 @@ public class InputTypesTest {
mTestServer.addDefaultHandlers("weblayer/test/data"); mTestServer.addDefaultHandlers("weblayer/test/data");
Assert.assertTrue(mTestServer.start(0)); Assert.assertTrue(mTestServer.start(0));
WebLayerShellActivity activity = InstrumentationActivity activity =
mActivityTestRule.launchShellWithUrl(mTestServer.getURL("/input_types.html")); mActivityTestRule.launchShellWithUrl(mTestServer.getURL("/input_types.html"));
mTempFile = File.createTempFile("file", null); mTempFile = File.createTempFile("file", null);
activity.setIntentInterceptor(mIntentInterceptor); activity.setIntentInterceptor(mIntentInterceptor);
......
...@@ -23,17 +23,17 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils; ...@@ -23,17 +23,17 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.BrowserController; import org.chromium.weblayer.BrowserController;
import org.chromium.weblayer.Navigation; import org.chromium.weblayer.Navigation;
import org.chromium.weblayer.NavigationObserver; import org.chromium.weblayer.NavigationObserver;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
/** /**
* ActivityTestRule for WebLayerShellActivity. * ActivityTestRule for InstrumentationActivity.
* *
* Test can use this ActivityTestRule to launch or get WebLayerShellActivity. * Test can use this ActivityTestRule to launch or get InstrumentationActivity.
*/ */
public class WebLayerShellActivityTestRule extends ActivityTestRule<WebLayerShellActivity> { public class InstrumentationActivityTestRule extends ActivityTestRule<InstrumentationActivity> {
private static final class NavigationWaiter { private static final class NavigationWaiter {
private String mUrl; private String mUrl;
private BrowserController mController; private BrowserController mController;
...@@ -97,25 +97,23 @@ public class WebLayerShellActivityTestRule extends ActivityTestRule<WebLayerShel ...@@ -97,25 +97,23 @@ public class WebLayerShellActivityTestRule extends ActivityTestRule<WebLayerShel
} }
} }
public WebLayerShellActivityTestRule() { public InstrumentationActivityTestRule() {
super(WebLayerShellActivity.class, false, false); super(InstrumentationActivity.class, false, false);
} }
/** /**
* Starts the WebLayer activity with the given extras Bundle and completely loads the given URL * Starts the WebLayer activity with the given extras Bundle and completely loads the given URL
* (this calls navigateAndWait()). * (this calls navigateAndWait()).
*/ */
public WebLayerShellActivity launchShellWithUrl(String url, Bundle extras) { public InstrumentationActivity launchShellWithUrl(String url, Bundle extras) {
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.putExtras(extras); intent.putExtras(extras);
intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Prevent URL from being loaded on start.
intent.putExtra(WebLayerShellActivity.EXTRA_NO_LOAD, true);
intent.setComponent( intent.setComponent(
new ComponentName(InstrumentationRegistry.getInstrumentation().getTargetContext(), new ComponentName(InstrumentationRegistry.getInstrumentation().getTargetContext(),
WebLayerShellActivity.class)); InstrumentationActivity.class));
WebLayerShellActivity activity = launchActivity(intent); InstrumentationActivity activity = launchActivity(intent);
Assert.assertNotNull(activity); Assert.assertNotNull(activity);
if (url != null) navigateAndWait(url); if (url != null) navigateAndWait(url);
return activity; return activity;
...@@ -125,7 +123,7 @@ public class WebLayerShellActivityTestRule extends ActivityTestRule<WebLayerShel ...@@ -125,7 +123,7 @@ public class WebLayerShellActivityTestRule extends ActivityTestRule<WebLayerShel
* Starts the WebLayer activity and completely loads the given URL (this calls * Starts the WebLayer activity and completely loads the given URL (this calls
* navigateAndWait()). * navigateAndWait()).
*/ */
public WebLayerShellActivity launchShellWithUrl(String url) { public InstrumentationActivity launchShellWithUrl(String url) {
return launchShellWithUrl(url, new Bundle()); return launchShellWithUrl(url, new Bundle());
} }
...@@ -144,15 +142,14 @@ public class WebLayerShellActivityTestRule extends ActivityTestRule<WebLayerShel ...@@ -144,15 +142,14 @@ public class WebLayerShellActivityTestRule extends ActivityTestRule<WebLayerShel
public void recreateActivity() { public void recreateActivity() {
Activity activity = getActivity(); Activity activity = getActivity();
ActivityMonitor monitor = new ActivityMonitor(WebLayerShellActivity.class.getName(), ActivityMonitor monitor =
null, false); new ActivityMonitor(InstrumentationActivity.class.getName(), null, false);
InstrumentationRegistry.getInstrumentation().addMonitor(monitor); InstrumentationRegistry.getInstrumentation().addMonitor(monitor);
TestThreadUtils.runOnUiThreadBlocking(activity::recreate); TestThreadUtils.runOnUiThreadBlocking(activity::recreate);
CriteriaHelper.pollUiThread(() -> CriteriaHelper.pollUiThread(
monitor.getLastActivity() != null && monitor.getLastActivity() != activity () -> monitor.getLastActivity() != null && monitor.getLastActivity() != activity);
);
InstrumentationRegistry.getInstrumentation().removeMonitor(monitor); InstrumentationRegistry.getInstrumentation().removeMonitor(monitor);
// There is no way to rotate the activity using ActivityTestRule or even notify it. // There is no way to rotate the activity using ActivityTestRule or even notify it.
......
...@@ -25,7 +25,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper; ...@@ -25,7 +25,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.weblayer.Navigation; import org.chromium.weblayer.Navigation;
import org.chromium.weblayer.NavigationController; import org.chromium.weblayer.NavigationController;
import org.chromium.weblayer.NavigationObserver; import org.chromium.weblayer.NavigationObserver;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
...@@ -38,7 +38,8 @@ import java.util.concurrent.TimeoutException; ...@@ -38,7 +38,8 @@ import java.util.concurrent.TimeoutException;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class NavigationTest { public class NavigationTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
// URLs used for base tests. // URLs used for base tests.
private static final String URL1 = "data:text,foo"; private static final String URL1 = "data:text,foo";
...@@ -146,7 +147,7 @@ public class NavigationTest { ...@@ -146,7 +147,7 @@ public class NavigationTest {
@Test @Test
@SmallTest @SmallTest
public void testNavigationEvents() throws Exception { public void testNavigationEvents() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(URL1); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(URL1);
setNavigationObserver(activity); setNavigationObserver(activity);
int curStartedCount = mObserver.onStartedCallback.getCallCount(); int curStartedCount = mObserver.onStartedCallback.getCallCount();
...@@ -166,7 +167,7 @@ public class NavigationTest { ...@@ -166,7 +167,7 @@ public class NavigationTest {
@Test @Test
@SmallTest @SmallTest
public void testLoadStateUpdates() throws Exception { public void testLoadStateUpdates() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(null); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(null);
setNavigationObserver(activity); setNavigationObserver(activity);
mActivityTestRule.navigateAndWait(URL1); mActivityTestRule.navigateAndWait(URL1);
...@@ -199,7 +200,7 @@ public class NavigationTest { ...@@ -199,7 +200,7 @@ public class NavigationTest {
@Test @Test
@SmallTest @SmallTest
public void testGoBackAndForward() throws Exception { public void testGoBackAndForward() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(URL1); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(URL1);
setNavigationObserver(activity); setNavigationObserver(activity);
mActivityTestRule.navigateAndWait(URL2); mActivityTestRule.navigateAndWait(URL2);
...@@ -237,7 +238,7 @@ public class NavigationTest { ...@@ -237,7 +238,7 @@ public class NavigationTest {
@Test @Test
@SmallTest @SmallTest
public void testSameDocument() throws Exception { public void testSameDocument() throws Exception {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(URL1); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(URL1);
setNavigationObserver(activity); setNavigationObserver(activity);
int curCompletedCount = mObserver.onCompletedCallback.getCallCount(); int curCompletedCount = mObserver.onCompletedCallback.getCallCount();
...@@ -248,7 +249,7 @@ public class NavigationTest { ...@@ -248,7 +249,7 @@ public class NavigationTest {
curCompletedCount, "data:text,foo#bar", true); curCompletedCount, "data:text,foo#bar", true);
} }
private void setNavigationObserver(WebLayerShellActivity activity) { private void setNavigationObserver(InstrumentationActivity activity) {
runOnUiThreadBlocking(() -> runOnUiThreadBlocking(() ->
activity.getBrowserController().getNavigationController().addObserver(mObserver) activity.getBrowserController().getNavigationController().addObserver(mObserver)
); );
......
...@@ -13,19 +13,20 @@ import org.junit.runner.RunWith; ...@@ -13,19 +13,20 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class RenderingTest { public class RenderingTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
@Test @Test
@SmallTest @SmallTest
public void testSetSupportEmbeddingFromCallback() { public void testSetSupportEmbeddingFromCallback() {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl("about:blank"); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank");
CountDownLatch latch = new CountDownLatch(1); CountDownLatch latch = new CountDownLatch(1);
String url = "data:text,foo"; String url = "data:text,foo";
...@@ -53,7 +54,7 @@ public class RenderingTest { ...@@ -53,7 +54,7 @@ public class RenderingTest {
@Test @Test
@SmallTest @SmallTest
public void testRepeatSetSupportEmbeddingGeneratesCallback() { public void testRepeatSetSupportEmbeddingGeneratesCallback() {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl("about:blank"); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank");
CountDownLatch latch = new CountDownLatch(2); CountDownLatch latch = new CountDownLatch(2);
String url = "data:text,foo"; String url = "data:text,foo";
......
...@@ -13,19 +13,20 @@ import org.junit.runner.RunWith; ...@@ -13,19 +13,20 @@ import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class SmokeTest { public class SmokeTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
@Test @Test
@SmallTest @SmallTest
public void testSetSupportEmbedding() { public void testSetSupportEmbedding() {
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl("about:blank"); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank");
TestThreadUtils.runOnUiThreadBlocking( TestThreadUtils.runOnUiThreadBlocking(
() -> { activity.getBrowserFragmentController().setSupportsEmbedding(true); }); () -> { activity.getBrowserFragmentController().setSupportsEmbedding(true); });
......
...@@ -19,7 +19,7 @@ import org.chromium.content_public.browser.test.util.Criteria; ...@@ -19,7 +19,7 @@ import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.BrowserController; import org.chromium.weblayer.BrowserController;
import org.chromium.weblayer.shell.WebLayerShellActivity; import org.chromium.weblayer.shell.InstrumentationActivity;
/** /**
* Test for top-controls. * Test for top-controls.
...@@ -27,7 +27,8 @@ import org.chromium.weblayer.shell.WebLayerShellActivity; ...@@ -27,7 +27,8 @@ import org.chromium.weblayer.shell.WebLayerShellActivity;
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(BaseJUnit4ClassRunner.class)
public class TopControlsTest { public class TopControlsTest {
@Rule @Rule
public WebLayerShellActivityTestRule mActivityTestRule = new WebLayerShellActivityTestRule(); public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private int mTopControlsHeight; private int mTopControlsHeight;
private int mInitialVisiblePageHeight; private int mInitialVisiblePageHeight;
...@@ -49,7 +50,7 @@ public class TopControlsTest { ...@@ -49,7 +50,7 @@ public class TopControlsTest {
@SmallTest @SmallTest
public void testBasic() throws Exception { public void testBasic() throws Exception {
final String url = UrlUtils.encodeHtmlDataUri("<body><p style='height:5000px'>"); final String url = UrlUtils.encodeHtmlDataUri("<body><p style='height:5000px'>");
WebLayerShellActivity activity = mActivityTestRule.launchShellWithUrl(url); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(url);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
mTopControlsHeight = activity.getTopContentsContainer().getHeight(); mTopControlsHeight = activity.getTopContentsContainer().getHeight();
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<activity android:name="InstrumentationActivity">
</activity>
<meta-data android:name="org.chromium.weblayer.WebLayerPackage" <meta-data android:name="org.chromium.weblayer.WebLayerPackage"
android:value="{{ weblayer_package }}"/> android:value="{{ weblayer_package }}"/>
</application> </application>
......
// Copyright 2019 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.weblayer.shell;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.InputType;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import org.chromium.weblayer.BrowserController;
import org.chromium.weblayer.BrowserFragment;
import org.chromium.weblayer.BrowserFragmentController;
import org.chromium.weblayer.BrowserObserver;
import org.chromium.weblayer.Profile;
import org.chromium.weblayer.UnsupportedVersionException;
import org.chromium.weblayer.WebLayer;
import java.io.File;
import java.util.List;
/**
* Activity for running instrumentation tests.
*/
public class InstrumentationActivity extends FragmentActivity {
private static final String TAG = "WLInstrumentation";
public static final String EXTRA_PROFILE_NAME = "EXTRA_PROFILE_NAME";
private Profile mProfile;
private BrowserFragmentController mBrowserFragmentController;
private BrowserController mBrowserController;
private EditText mUrlView;
private View mMainView;
private int mMainViewId;
private ViewGroup mTopContentsContainer;
private BrowserFragment mFragment;
private IntentInterceptor mIntentInterceptor;
public BrowserController getBrowserController() {
return mBrowserController;
}
public BrowserFragmentController getBrowserFragmentController() {
return mBrowserFragmentController;
}
/** Interface used to intercept intents for testing. */
public static interface IntentInterceptor {
void interceptIntent(Fragment fragment, Intent intent, int requestCode, Bundle options);
}
public void setIntentInterceptor(IntentInterceptor interceptor) {
mIntentInterceptor = interceptor;
}
@Override
public void startActivityFromFragment(
Fragment fragment, Intent intent, int requestCode, Bundle options) {
if (mIntentInterceptor != null) {
mIntentInterceptor.interceptIntent(fragment, intent, requestCode, options);
return;
}
super.startActivityFromFragment(fragment, intent, requestCode, options);
}
public View getTopContentsContainer() {
return mTopContentsContainer;
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout mainView = new LinearLayout(this);
mMainViewId = View.generateViewId();
mainView.setId(mMainViewId);
mMainView = mainView;
setContentView(mainView);
mUrlView = new EditText(this);
mUrlView.setId(View.generateViewId());
mUrlView.setSelectAllOnFocus(true);
mUrlView.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
mUrlView.setImeOptions(EditorInfo.IME_ACTION_GO);
// The background of the top-view must be opaque, otherwise it bleeds through to the
// cc::Layer that mirrors the contents of the top-view.
mUrlView.setBackgroundColor(0xFFa9a9a9);
// The progress bar sits above the URL bar in Z order and at its bottom in Y.
mTopContentsContainer = new RelativeLayout(this);
mTopContentsContainer.addView(mUrlView,
new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
try {
// This ensures asynchronous initialization of WebLayer on first start of activity.
// If activity is re-created during process restart, FragmentManager attaches
// BrowserFragment immediately, resulting in synchronous init. By the time this line
// executes, the synchronous init has already happened.
WebLayer.create(getApplication())
.addCallback(webLayer -> onWebLayerReady(savedInstanceState));
} catch (UnsupportedVersionException e) {
throw new RuntimeException("Failed to initialize WebLayer", e);
}
}
private void onWebLayerReady(Bundle savedInstanceState) {
if (isFinishing() || isDestroyed()) return;
mFragment = getOrCreateBrowserFragment(savedInstanceState);
mBrowserFragmentController = mFragment.getController();
mProfile = mBrowserFragmentController.getProfile();
mBrowserFragmentController.setTopView(mTopContentsContainer);
mBrowserController = mBrowserFragmentController.getBrowserController();
mBrowserController.addObserver(new BrowserObserver() {
@Override
public void visibleUrlChanged(Uri uri) {
mUrlView.setText(uri.toString());
}
});
}
private BrowserFragment getOrCreateBrowserFragment(Bundle savedInstanceState) {
FragmentManager fragmentManager = getSupportFragmentManager();
if (savedInstanceState != null) {
// FragmentManager could have re-created the fragment.
List<Fragment> fragments = fragmentManager.getFragments();
if (fragments.size() > 1) {
throw new IllegalStateException("More than one fragment added, shouldn't happen");
}
if (fragments.size() == 1) {
return (BrowserFragment) fragments.get(0);
}
}
String profileName = getIntent().hasExtra(EXTRA_PROFILE_NAME)
? getIntent().getStringExtra(EXTRA_PROFILE_NAME)
: "DefaultProfile";
String profilePath = null;
if (!TextUtils.isEmpty(profileName)) {
profilePath = new File(getFilesDir(), profileName).getPath();
} // else create an in-memory Profile.
BrowserFragment fragment = WebLayer.createBrowserFragment(profilePath);
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(mMainViewId, fragment);
// Note the commitNow() instead of commit(). We want the fragment to get attached to
// activity synchronously, so we can use all the functionality immediately. Otherwise we'd
// have to wait until the commit is executed.
transaction.commitNow();
return fragment;
}
public void loadUrl(String url) {
mBrowserController.getNavigationController().navigate(Uri.parse(url));
mUrlView.clearFocus();
}
private static String getUrlFromIntent(Intent intent) {
return intent != null ? intent.getDataString() : null;
}
}
...@@ -46,13 +46,9 @@ import java.util.List; ...@@ -46,13 +46,9 @@ import java.util.List;
* Activity for managing the Demo Shell. * Activity for managing the Demo Shell.
*/ */
public class WebLayerShellActivity extends FragmentActivity { public class WebLayerShellActivity extends FragmentActivity {
public static final String EXTRA_NO_LOAD = "extra_no_load";
private static final String TAG = "WebLayerShell"; private static final String TAG = "WebLayerShell";
private static final String KEY_MAIN_VIEW_ID = "mainViewId"; private static final String KEY_MAIN_VIEW_ID = "mainViewId";
public static final String EXTRA_PROFILE_NAME = "EXTRA_PROFILE_NAME";
private Profile mProfile; private Profile mProfile;
private BrowserFragmentController mBrowserFragmentController; private BrowserFragmentController mBrowserFragmentController;
private BrowserController mBrowserController; private BrowserController mBrowserController;
...@@ -62,38 +58,6 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -62,38 +58,6 @@ public class WebLayerShellActivity extends FragmentActivity {
private int mMainViewId; private int mMainViewId;
private ViewGroup mTopContentsContainer; private ViewGroup mTopContentsContainer;
private BrowserFragment mFragment; private BrowserFragment mFragment;
private IntentInterceptor mIntentInterceptor;
public BrowserController getBrowserController() {
return mBrowserController;
}
public BrowserFragmentController getBrowserFragmentController() {
return mBrowserFragmentController;
}
/** Interface used to intercept intents for testing. */
public static interface IntentInterceptor {
void interceptIntent(Fragment fragment, Intent intent, int requestCode, Bundle options);
}
public void setIntentInterceptor(IntentInterceptor interceptor) {
mIntentInterceptor = interceptor;
}
@Override
public void startActivityFromFragment(
Fragment fragment, Intent intent, int requestCode, Bundle options) {
if (mIntentInterceptor != null) {
mIntentInterceptor.interceptIntent(fragment, intent, requestCode, options);
return;
}
super.startActivityFromFragment(fragment, intent, requestCode, options);
}
public View getTopContentsContainer() {
return mTopContentsContainer;
}
@Override @Override
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
...@@ -205,15 +169,11 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -205,15 +169,11 @@ public class WebLayerShellActivity extends FragmentActivity {
mBrowserFragmentController.setTopView(mTopContentsContainer); mBrowserFragmentController.setTopView(mTopContentsContainer);
mBrowserController = mBrowserFragmentController.getBrowserController(); mBrowserController = mBrowserFragmentController.getBrowserController();
boolean blockFirstLoad = getIntent().getExtras() != null String startupUrl = getUrlFromIntent(getIntent());
&& getIntent().getExtras().getBoolean(EXTRA_NO_LOAD, false); if (TextUtils.isEmpty(startupUrl)) {
if (!blockFirstLoad) { startupUrl = "http://google.com";
String startupUrl = getUrlFromIntent(getIntent());
if (TextUtils.isEmpty(startupUrl)) {
startupUrl = "http://google.com";
}
loadUrl(startupUrl);
} }
loadUrl(startupUrl);
mBrowserController.addObserver(new BrowserObserver() { mBrowserController.addObserver(new BrowserObserver() {
@Override @Override
public void visibleUrlChanged(Uri uri) { public void visibleUrlChanged(Uri uri) {
...@@ -257,8 +217,7 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -257,8 +217,7 @@ public class WebLayerShellActivity extends FragmentActivity {
} }
} }
String profileName = getIntent().hasExtra(EXTRA_PROFILE_NAME) String profileName = "DefaultProfile";
? getIntent().getStringExtra(EXTRA_PROFILE_NAME) : "DefaultProfile";
String profilePath = null; String profilePath = null;
if (!TextUtils.isEmpty(profileName)) { if (!TextUtils.isEmpty(profileName)) {
profilePath = new File(getFilesDir(), profileName).getPath(); profilePath = new File(getFilesDir(), profileName).getPath();
...@@ -275,11 +234,6 @@ public class WebLayerShellActivity extends FragmentActivity { ...@@ -275,11 +234,6 @@ public class WebLayerShellActivity extends FragmentActivity {
return fragment; return fragment;
} }
@Override
protected void onStart() {
super.onStart();
}
public void loadUrl(String url) { public void loadUrl(String url) {
mBrowserController.getNavigationController().navigate(Uri.parse(sanitizeUrl(url))); mBrowserController.getNavigationController().navigate(Uri.parse(sanitizeUrl(url)));
mUrlView.clearFocus(); mUrlView.clearFocus();
......
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