Commit 281ddc9e authored by Bo Liu's avatar Bo Liu Committed by Commit Bot

weblayer: Make public java API mock-able

For classes that are reasonable to be mocked in tests, ensure they are
not final and has a constructor that do not initialize or use weblayer
implementation in any way. The constructor does not ensure the object is
in a valid state and it's up to the test to mock out all methods and not
rely on any method call to work.

BrowserFragment is still final. It's not really part of the public
interface and tests should profile its own Fragment mocks.

UrlBarOptions is still final. It does not access weblayer internals
and tests can ignore the options and create its own UrlBar mock.

Fixed: 1050428
Change-Id: I716bbb4c51df0a86aefc1cd8aeb57622f595a5e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2045174Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Bo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#740117}
parent b5ff766d
......@@ -27,11 +27,18 @@ import java.util.List;
*
* By default Browser has a single active Tab.
*/
public final class Browser {
public class Browser {
private final IBrowser mImpl;
private final ObserverList<TabListCallback> mTabListCallbacks;
private final UrlBarController mUrlBarController;
// Constructor for test mocking.
protected Browser() {
mImpl = null;
mTabListCallbacks = null;
mUrlBarController = null;
}
Browser(IBrowser impl) {
mImpl = impl;
mTabListCallbacks = new ObserverList<TabListCallback>();
......
......@@ -36,7 +36,7 @@ import org.chromium.weblayer_private.interfaces.StrictModeWorkaround;
* user preference. Knowing that a crash is available can be used as a signal to schedule upload
* work for a later point in time (or favourable power/network conditions).
*/
public final class CrashReporterController {
public class CrashReporterController {
private ICrashReporterController mImpl;
private final ObserverList<CrashReporterCallback> mCallbacks;
......@@ -44,7 +44,8 @@ public final class CrashReporterController {
static CrashReporterController sInstance = new CrashReporterController();
}
private CrashReporterController() {
// Protected so it's available for test mocking.
protected CrashReporterController() {
mCallbacks = new ObserverList<CrashReporterCallback>();
}
......
......@@ -19,9 +19,14 @@ import java.io.File;
*
* @since 81
*/
public final class Download extends IClientDownload.Stub {
public class Download extends IClientDownload.Stub {
private final IDownload mDownloadImpl;
// Constructor for test mocking.
protected Download() {
mDownloadImpl = null;
}
Download(IDownload impl) {
mDownloadImpl = impl;
}
......
......@@ -22,9 +22,13 @@ import org.chromium.weblayer_private.interfaces.StrictModeWorkaround;
*
* @since 81
*/
public final class FindInPageController {
public class FindInPageController {
private final ITab mTab;
protected FindInPageController() {
mTab = null;
}
FindInPageController(ITab tab) {
mTab = tab;
}
......
......@@ -19,9 +19,14 @@ import java.util.List;
/**
* Information about a navigation.
*/
public final class Navigation extends IClientNavigation.Stub {
public class Navigation extends IClientNavigation.Stub {
private final INavigation mNavigationImpl;
// Constructor for test mocking.
protected Navigation() {
mNavigationImpl = null;
}
Navigation(INavigation impl) {
mNavigationImpl = impl;
}
......
......@@ -20,7 +20,7 @@ import org.chromium.weblayer_private.interfaces.StrictModeWorkaround;
/**
* Provides methods to control navigation, along with maintaining the current list of navigations.
*/
public final class NavigationController {
public class NavigationController {
private INavigationController mNavigationController;
private final ObserverList<NavigationCallback> mCallbacks;
......@@ -35,7 +35,8 @@ public final class NavigationController {
return navigationController;
}
private NavigationController() {
// Constructor protected for test mocking.
protected NavigationController() {
mCallbacks = new ObserverList<NavigationCallback>();
}
......
......@@ -23,7 +23,7 @@ import java.util.Map;
* Profile holds state (typically on disk) needed for browsing. Create a
* Profile via WebLayer.
*/
public final class Profile {
public class Profile {
private static final Map<String, Profile> sProfiles = new HashMap<>();
/* package */ static Profile of(IProfile impl) {
......@@ -55,6 +55,12 @@ public final class Profile {
private final String mName;
private IProfile mImpl;
// Constructor for test mocking.
protected Profile() {
mName = null;
mImpl = null;
}
private Profile(String name, IProfile impl) {
mName = name;
mImpl = impl;
......
......@@ -36,7 +36,7 @@ import java.util.Map;
* Represents a single tab in a browser. More specifically, owns a NavigationController, and allows
* configuring state of the tab, such as delegates and callbacks.
*/
public final class Tab {
public class Tab {
/** The top level key of the JSON object returned by executeScript(). */
public static final String SCRIPT_RESULT_KEY = "result";
......@@ -54,6 +54,15 @@ public final class Tab {
// Id from the remote side.
private final int mId;
// Constructor for test mocking.
protected Tab() {
mImpl = null;
mNavigationController = null;
mFindInPageController = null;
mCallbacks = null;
mId = 0;
}
Tab(ITab impl, Browser browser) {
mImpl = impl;
mBrowser = browser;
......
......@@ -14,9 +14,14 @@ import org.chromium.weblayer_private.interfaces.ObjectWrapper;
/**
* UrlBarController enables creation of URL bar views and retrieval of information about them.
*/
public final class UrlBarController {
public class UrlBarController {
private final IUrlBarController mImpl;
// Constructor for test mocking.
protected UrlBarController() {
mImpl = null;
}
UrlBarController(IUrlBarController urlBarController) {
mImpl = urlBarController;
}
......
......@@ -36,7 +36,7 @@ import java.util.List;
/**
* WebLayer is responsible for initializing state necessary to use any of the classes in web layer.
*/
public final class WebLayer {
public class WebLayer {
// This metadata key, if defined, overrides the default behaviour of loading WebLayer from the
// current WebView implementation. This is only intended for testing, and does not enforce any
// signature requirements on the implementation, nor does it use the production code path to
......@@ -330,6 +330,11 @@ public final class WebLayer {
}
}
// Constructor for test mocking.
protected WebLayer() {
mImpl = null;
}
private WebLayer(IWebLayer iWebLayer) {
mImpl = iWebLayer;
}
......
......@@ -9,4 +9,4 @@ import android.support.v4.content.FileProvider;
/**
* Subclass of FileProvider which prevents conflicts with the embedding application manifest.
*/
public final class WebLayerFileProvider extends FileProvider {}
public class WebLayerFileProvider extends FileProvider {}
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