Commit a9036939 authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

Revert "[WebLayer] InstrumentationShellActivity uses UrlBarController."

This reverts commit 53f0457f.

Reason for revert: Suspected cause of multiple weblayer_instrumentation_test_apk failures on Lollipop Phone Tester
https://ci.chromium.org/p/chromium/builders/ci/Lollipop%20Phone%20Tester

Original change's description:
> [WebLayer] InstrumentationShellActivity uses UrlBarController.
>
> This change gets rid of the EditText we were using in
> InstrumentationTestActivity for weblayer instrumentation tests and
> replaces it with a UrlBarView returned by UrlBarViewController.
>
> All relevant methods have been updated, and a small UrlBarControllerTest
> added to verify expected behavior.
>
> Bug: None
> Test: ./out/<build_dir>/bin/run_weblayer_instrumentation_test_apk
> Change-Id: I7b8a54cec34f4b53df2e410ebb9526c943f4edf0
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2270442
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Reviewed-by: Bo <boliu@chromium.org>
> Commit-Queue: Mugdha Lakhani <nator@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#785731}

TBR=jam@chromium.org,boliu@chromium.org,nator@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 1103342
Change-Id: I46ff0442bebc4ff50b6ae6ed8a7708ced5678568
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2288103
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786443}
parent 124cd999
......@@ -72,7 +72,6 @@ android_library("weblayer_private_java_tests") {
"src/org/chromium/weblayer/test/PopupTest.java",
"src/org/chromium/weblayer/test/ResourceLoadingTest.java",
"src/org/chromium/weblayer/test/TranslateTest.java",
"src/org/chromium/weblayer/test/UrlBarControllerTest.java",
]
deps = [
":weblayer_java_private_test_support",
......
......@@ -31,7 +31,6 @@ import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.net.test.EmbeddedTestServerRule;
import org.chromium.weblayer.CookieManager;
import org.chromium.weblayer.NavigationController;
import org.chromium.weblayer.Tab;
import org.chromium.weblayer.WebLayer;
import org.chromium.weblayer.shell.InstrumentationActivity;
......@@ -257,23 +256,7 @@ public class InstrumentationActivityTestRule
// Returns the URL that is currently being displayed to the user.
public String getCurrentDisplayUrl() {
InstrumentationActivity activity = getActivity();
return TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
NavigationController navigationController =
activity.getBrowser().getActiveTab().getNavigationController();
if (navigationController.getNavigationListSize() == 0) {
return null;
}
// TODO(crbug.com/1066382): This will not be correct in the case where the initial
// navigation in |tab| was a failed navigation and there have been no more navigations
// since then.
return navigationController
.getNavigationEntryDisplayUri(
navigationController.getNavigationListCurrentIndex())
.toString();
});
return getActivity().getCurrentDisplayUrl();
}
public void setRetainInstance(boolean retain) {
......
// Copyright 2020 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.test;
import android.os.RemoteException;
import android.view.View;
import android.widget.LinearLayout;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.weblayer.Tab;
import org.chromium.weblayer.TestWebLayer;
import org.chromium.weblayer.shell.InstrumentationActivity;
/**
* Test class to test UrlBarController logic.
*/
@RunWith(WebLayerJUnit4ClassRunner.class)
public class UrlBarControllerTest {
@Rule
public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule();
private static final String ABOUT_BLANK_URL = "about:blank";
private static final String NEW_TAB_URL = "new_browser.html";
private static final String HTTP_SCHEME = "http://";
// The test server handles "echo" with a response containing "Echo" :).
private final String mTestServerSiteUrl = mActivityTestRule.getTestServer().getURL("/echo");
private String getDisplayedUrl() {
try {
InstrumentationActivity activity = mActivityTestRule.getActivity();
TestWebLayer testWebLayer =
TestWebLayer.getTestWebLayer(activity.getApplicationContext());
View urlBarView = activity.getUrlBarView();
return testWebLayer.getDisplayedUrl(urlBarView);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
/**
* Tests that UrlBarView can be instantiated and shown.
*/
@Test
@SmallTest
public void testShowUrlBar() throws RemoteException {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(ABOUT_BLANK_URL);
Assert.assertEquals(ABOUT_BLANK_URL, mActivityTestRule.getCurrentDisplayUrl());
}
/**
* Tests that UrlBarView contains an ImageButton and a TextView with the expected text.
*/
@Test
@SmallTest
public void testUrlBarView() throws RemoteException {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(ABOUT_BLANK_URL);
View urlBarView = activity.getUrlBarView();
Assert.assertEquals(getDisplayedUrl(), ABOUT_BLANK_URL);
}
/**
* Tests that UrlBar TextView is updated when the URL navigated to changes.
*/
@Test
@SmallTest
public void testUrlBarTextViewOnNewNavigation() {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(ABOUT_BLANK_URL);
mActivityTestRule.navigateAndWait(mTestServerSiteUrl);
Assert.assertEquals(mTestServerSiteUrl, mActivityTestRule.getCurrentDisplayUrl());
View urlBarView = (LinearLayout) activity.getUrlBarView();
// Remove everything but the TLD because these aren't displayed.
String mExpectedUrlBarViewText = mTestServerSiteUrl.substring(HTTP_SCHEME.length());
mExpectedUrlBarViewText =
mExpectedUrlBarViewText.substring(0, mExpectedUrlBarViewText.indexOf("/echo"));
Assert.assertEquals(getDisplayedUrl(), mExpectedUrlBarViewText);
}
/**
* Tests that UrlBar TextView is updated when the active tab changes.
*/
@Test
@SmallTest
public void testUrlBarTextViewOnNewActiveTab() {
String url = mActivityTestRule.getTestDataURL(NEW_TAB_URL);
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(url);
Assert.assertNotNull(activity);
NewTabCallbackImpl callback = new NewTabCallbackImpl();
Tab firstTab = TestThreadUtils.runOnUiThreadBlockingNoException(() -> {
Tab tab = activity.getBrowser().getActiveTab();
tab.setNewTabCallback(callback);
return tab;
});
// This should launch a new tab and navigate to about:blank.
EventUtils.simulateTouchCenterOfView(activity.getWindow().getDecorView());
callback.waitForNewTab();
TestThreadUtils.runOnUiThreadBlocking(() -> {
Assert.assertEquals(2, activity.getBrowser().getTabs().size());
Tab secondTab = activity.getBrowser().getActiveTab();
Assert.assertNotSame(firstTab, secondTab);
});
View urlBarView = activity.getUrlBarView();
Assert.assertEquals(getDisplayedUrl(), ABOUT_BLANK_URL);
}
}
......@@ -5,9 +5,6 @@
package org.chromium.weblayer_private.test;
import android.os.IBinder;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
......@@ -166,17 +163,4 @@ public final class TestWebLayerImpl extends ITestWebLayer.Stub {
public boolean canInfoBarContainerScroll(ITab tab) {
return ((TabImpl) tab).canInfoBarContainerScrollForTesting();
}
@Override
public String getDisplayedUrl(IObjectWrapper /* View */ view) {
View urlBarView = ObjectWrapper.unwrap(view, View.class);
assert (urlBarView instanceof LinearLayout);
LinearLayout urlBarLayout = (LinearLayout) urlBarView;
assert (urlBarLayout.getChildCount() == 2);
View textView = urlBarLayout.getChildAt(1);
assert (textView instanceof TextView);
TextView urlBarTextView = (TextView) textView;
return urlBarTextView.getText().toString();
}
}
......@@ -44,6 +44,4 @@ interface ITestWebLayer {
void forceNetworkConnectivityState(in boolean networkAvailable) = 13;
boolean canInfoBarContainerScroll(in ITab tab) = 14;
String getDisplayedUrl(IObjectWrapper /* View */ urlBarView) = 15;
}
......@@ -114,8 +114,4 @@ public final class TestWebLayer {
public boolean canInfoBarContainerScroll(Tab tab) throws RemoteException {
return mITestWebLayer.canInfoBarContainerScroll(tab.getITab());
}
public String getDisplayedUrl(View urlBarView) throws RemoteException {
return mITestWebLayer.getDisplayedUrl(ObjectWrapper.wrap(urlBarView));
}
}
......@@ -11,9 +11,12 @@ import android.os.Bundle;
import android.os.StrictMode;
import android.os.StrictMode.ThreadPolicy;
import android.os.StrictMode.VmPolicy;
import android.text.InputType;
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;
......@@ -24,13 +27,14 @@ import androidx.fragment.app.FragmentTransaction;
import org.chromium.base.ContextUtils;
import org.chromium.weblayer.Browser;
import org.chromium.weblayer.NavigationController;
import org.chromium.weblayer.NewTabCallback;
import org.chromium.weblayer.NewTabType;
import org.chromium.weblayer.Profile;
import org.chromium.weblayer.Tab;
import org.chromium.weblayer.TabCallback;
import org.chromium.weblayer.TabListCallback;
import org.chromium.weblayer.UnsupportedVersionException;
import org.chromium.weblayer.UrlBarOptions;
import org.chromium.weblayer.WebLayer;
import java.util.ArrayList;
......@@ -45,7 +49,6 @@ public class InstrumentationActivity extends FragmentActivity {
public static final String EXTRA_PERSISTENCE_ID = "EXTRA_PERSISTENCE_ID";
public static final String EXTRA_PROFILE_NAME = "EXTRA_PROFILE_NAME";
private static final float DEFAULT_TEXT_SIZE = 15.0F;
// Used in tests to specify whether WebLayer should be created automatically on launch.
// True by default. If set to false, the test should call loadWebLayerSync.
......@@ -55,12 +58,13 @@ public class InstrumentationActivity extends FragmentActivity {
private Fragment mFragment;
private Browser mBrowser;
private Tab mTab;
private EditText mUrlView;
private View mMainView;
private int mMainViewId;
private ViewGroup mTopContentsContainer;
private View mUrlBarView;
private IntentInterceptor mIntentInterceptor;
private Bundle mSavedInstanceState;
private TabCallback mTabCallback;
private TabListCallback mTabListCallback;
private List<Tab> mPreviousTabList = new ArrayList<>();
......@@ -170,8 +174,20 @@ public class InstrumentationActivity extends FragmentActivity {
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));
if (getIntent().getBooleanExtra(EXTRA_CREATE_WEBLAYER, true)) {
// If activity is re-created during process restart, FragmentManager attaches
......@@ -197,6 +213,10 @@ public class InstrumentationActivity extends FragmentActivity {
}
private void removeCallbacks() {
if (mTabCallback != null) {
mTab.unregisterTabCallback(mTabCallback);
mTabCallback = null;
}
if (mTabListCallback != null) {
mBrowser.unregisterTabListCallback(mTabListCallback);
mTabListCallback = null;
......@@ -265,34 +285,32 @@ public class InstrumentationActivity extends FragmentActivity {
}
}
private void createUrlBarView() {
mUrlBarView = mBrowser.getUrlBarController().createUrlBarView(
UrlBarOptions.builder()
.setTextSizeSP(DEFAULT_TEXT_SIZE)
.setTextColor(android.R.color.black)
.setIconColor(android.R.color.black)
.build());
// 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.
mUrlBarView.setBackgroundColor(0xFFa9a9a9);
mTopContentsContainer.removeAllViews();
mTopContentsContainer.addView(mUrlBarView,
new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
// Clears the state associated with |mTab| and sets |tab|, if non-null, as |mTab| and the
// active tab in the browser.
private void setTab(Tab tab) {
if (mTab != null) {
mTab.unregisterTabCallback(mTabCallback);
mTabCallback = null;
mTab = null;
}
mTab = tab;
if (mTab == null) return;
// TODO(crbug.com/1066382): This will not be correct in the case where the initial
// navigation in |tab| was a failed navigation and there have been no more navigations since
// then.
mUrlView.setText(getLastCommittedUrlInTab(mTab));
mTabCallback = new TabCallback() {
@Override
public void onVisibleUriChanged(Uri uri) {
mUrlView.setText(uri.toString());
}
};
mTab.registerTabCallback(mTabCallback);
mTab.setNewTabCallback(new NewTabCallback() {
@Override
public void onNewTab(Tab newTab, @NewTabType int type) {
......@@ -307,9 +325,6 @@ public class InstrumentationActivity extends FragmentActivity {
// Will be a no-op if this tab is already the active tab.
mBrowser.setActiveTab(mTab);
// Creates and adds a new UrlBarView to |mTopContentsContainer|.
createUrlBarView();
}
private Fragment getOrCreateBrowserFragment() {
......@@ -346,18 +361,29 @@ public class InstrumentationActivity extends FragmentActivity {
return fragment;
}
// Returns the display URL of the last committed navigation entry in |tab|. This will
// return an empty URL if there have been no committed navigations in |tab|.
public String getLastCommittedUrlInTab(Tab tab) {
NavigationController navController = tab.getNavigationController();
int currentIndex = navController.getNavigationListCurrentIndex();
return currentIndex == -1
? ""
: navController.getNavigationEntryDisplayUri(currentIndex).toString();
}
public String getCurrentDisplayUrl() {
return mUrlView.getText().toString();
}
public void loadUrl(String url) {
mTab.getNavigationController().navigate(Uri.parse(url));
mUrlView.clearFocus();
}
public void setRetainInstance(boolean retain) {
mFragment.setRetainInstance(retain);
}
public View getUrlBarView() {
return mUrlBarView;
}
private static String getUrlFromIntent(Intent intent) {
return intent != null ? intent.getDataString() : null;
}
......
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