Commit f78f315d authored by aruslan@chromium.org's avatar aruslan@chromium.org

JavascriptAppModalDialog tests and necessary infrastructure.

BUG=155330


Review URL: https://chromiumcodereview.appspot.com/11778005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175429 0039d316-1c4b-4281-b951-d872f2087c98
parent babc76f2
...@@ -70,6 +70,9 @@ public class TabBase { ...@@ -70,6 +70,9 @@ public class TabBase {
* be used. * be used.
*/ */
public void destroy() { public void destroy() {
for (int i = 0; i < mObservers.size(); ++i) {
mObservers.get(i).onCloseTab(TabBase.this);
}
destroyContentView(); destroyContentView();
if (mNativeTabBaseAndroidImpl != 0) { if (mNativeTabBaseAndroidImpl != 0) {
mCleanupReference.cleanupNow(); mCleanupReference.cleanupNow();
......
...@@ -25,4 +25,10 @@ public interface TabObserver { ...@@ -25,4 +25,10 @@ public interface TabObserver {
* @param url The new URL. * @param url The new URL.
*/ */
public void onUpdateUrl(TabBase tab, String url); public void onUpdateUrl(TabBase tab, String url);
/**
* Called when the tab is about to close.
* @param tab The closing {@link TabBase}.
*/
public void onCloseTab(TabBase tab);
} }
\ No newline at end of file
// Copyright (c) 2013 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.chrome.browser.test.util;
import org.chromium.chrome.browser.TabBase;
import org.chromium.chrome.browser.TabObserver;
import org.chromium.content.browser.test.util.CallbackHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content.browser.test.util.TestContentViewClient;
import org.chromium.content.browser.test.util.TestContentViewClientWrapper;
import org.chromium.content.browser.test.util.TestWebContentsObserver;
import org.chromium.content.browser.ContentViewClient;
/**
* A utility class that contains methods generic to all Tabs tests.
*/
public class TabBaseUtils {
private final static String TAG = TabBaseUtils.class.getSimpleName();
private static TestContentViewClient createTestContentViewClientForTab(TabBase tab) {
ContentViewClient client = tab.getContentView().getContentViewClient();
if (client instanceof TestContentViewClient) return (TestContentViewClient) client;
TestContentViewClient testClient = new TestContentViewClientWrapper(client);
tab.getContentView().setContentViewClient(testClient);
return testClient;
}
public static class TestCallbackHelperContainerForTab
extends TestCallbackHelperContainer implements TabObserver {
private OnCloseTabHelper mOnCloseTabHelper;
public TestCallbackHelperContainerForTab(TabBase tab) {
super(createTestContentViewClientForTab(tab),
new TestWebContentsObserver(tab.getContentView().getContentViewCore()));
mOnCloseTabHelper = new OnCloseTabHelper();
tab.addObserver(this);
}
public static class OnCloseTabHelper extends CallbackHelper {
}
public OnCloseTabHelper getOnCloseTabHelper() {
return mOnCloseTabHelper;
}
@Override
public void onLoadProgressChanged(TabBase tab, int progress) {
}
@Override
public void onUpdateUrl(TabBase tab, String url) {
}
@Override
public void onCloseTab(TabBase tab) {
mOnCloseTabHelper.notifyCalled();
}
}
/**
* Creates, binds and returns a TestCallbackHelperContainer for a given Tab.
*/
public static TestCallbackHelperContainerForTab getTestCallbackHelperContainer(
final TabBase tab) {
return tab == null ? null : new TestCallbackHelperContainerForTab(tab);
}
}
...@@ -130,6 +130,14 @@ public class ChromiumTestShellActivity extends ChromiumActivity { ...@@ -130,6 +130,14 @@ public class ChromiumTestShellActivity extends ChromiumActivity {
return tab != null ? tab.getContentView() : null; return tab != null ? tab.getContentView() : null;
} }
/**
* Creates a {@link TabBase} with a URL specified by {@code url}.
* @param url The URL the new {@link TabBase} should start with.
*/
public void createTab(String url) {
mTabManager.createTab(url);
}
private void waitForDebuggerIfNeeded() { private void waitForDebuggerIfNeeded() {
if (CommandLine.getInstance().hasSwitch(CommandLine.WAIT_FOR_JAVA_DEBUGGER)) { if (CommandLine.getInstance().hasSwitch(CommandLine.WAIT_FOR_JAVA_DEBUGGER)) {
Log.e(TAG, "Waiting for Java debugger to connect..."); Log.e(TAG, "Waiting for Java debugger to connect...");
......
...@@ -152,5 +152,9 @@ public class TestShellToolbar extends LinearLayout { ...@@ -152,5 +152,9 @@ public class TestShellToolbar extends LinearLayout {
public void onUpdateUrl(TabBase tab, String url) { public void onUpdateUrl(TabBase tab, String url) {
if (tab == mTab) TestShellToolbar.this.onUpdateUrl(url); if (tab == mTab) TestShellToolbar.this.onUpdateUrl(url);
} }
@Override
public void onCloseTab(TabBase tab) {
}
} }
} }
...@@ -57,7 +57,7 @@ public class ChromiumTestShellTestBase extends ...@@ -57,7 +57,7 @@ public class ChromiumTestShellTestBase extends
* @return Whether or not the Shell was actually finished loading. * @return Whether or not the Shell was actually finished loading.
* @throws Exception * @throws Exception
*/ */
protected boolean waitForActiveShellToBeDoneLoading() throws Exception { protected boolean waitForActiveShellToBeDoneLoading() throws InterruptedException {
final ChromiumTestShellActivity activity = getActivity(); final ChromiumTestShellActivity activity = getActivity();
// Wait for the Content Shell to be initialized. // Wait for the Content Shell to be initialized.
...@@ -86,4 +86,18 @@ public class ChromiumTestShellTestBase extends ...@@ -86,4 +86,18 @@ public class ChromiumTestShellTestBase extends
} }
}, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
} }
/**
* Navigates the currently active tab to a sanitized version of {@code url}.
* @param url The potentially unsanitized URL to navigate to.
*/
public void loadUrlWithSanitization(final String url) throws InterruptedException {
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
getActivity().getActiveTab().loadUrlWithSanitization(url);
}
});
waitForActiveShellToBeDoneLoading();
}
} }
...@@ -211,7 +211,8 @@ public class ContentView extends FrameLayout implements ContentViewCore.Internal ...@@ -211,7 +211,8 @@ public class ContentView extends FrameLayout implements ContentViewCore.Internal
mContentViewCore.setContentViewClient(client); mContentViewCore.setContentViewClient(client);
} }
ContentViewClient getContentViewClient() { // @VisibleForTesting
public ContentViewClient getContentViewClient() {
return mContentViewCore.getContentViewClient(); return mContentViewCore.getContentViewClient();
} }
......
// Copyright (c) 2013 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.content.browser.test.util;
import android.content.Context;
import android.view.ActionMode;
import android.view.KeyEvent;
import org.chromium.content.browser.ContentViewClient;
import org.chromium.content.browser.SelectActionModeCallback;
import org.chromium.content.browser.SelectActionModeCallback.ActionHandler;
import org.chromium.content.browser.test.util.TestContentViewClient;
/**
* Simplistic {@link TestContentViewClient} for browser tests.
* Wraps around existing client so that specific methods can be overridden if needed.
* This class MUST override ALL METHODS OF the ContentViewClient and pass them
* to the wrapped client.
*/
public class TestContentViewClientWrapper extends TestContentViewClient {
private ContentViewClient mWrappedClient;
public TestContentViewClientWrapper(ContentViewClient wrappedClient) {
assert wrappedClient != null;
mWrappedClient = wrappedClient;
}
@Override
public void onUpdateTitle(String title) {
super.onUpdateTitle(title);
mWrappedClient.onUpdateTitle(title);
}
@Override
public void onScaleChanged(float oldScale, float newScale) {
super.onScaleChanged(oldScale, newScale);
mWrappedClient.onScaleChanged(oldScale, newScale);
}
@Override
public void onTabCrash() {
super.onTabCrash();
mWrappedClient.onTabCrash();
}
@Override
public boolean shouldOverrideKeyEvent(KeyEvent event) {
return mWrappedClient.shouldOverrideKeyEvent(event);
}
@Override
public void onImeEvent() {
super.onImeEvent();
mWrappedClient.onImeEvent();
}
@Override
public void onEvaluateJavaScriptResult(int id, String jsonResult) {
super.onEvaluateJavaScriptResult(id, jsonResult);
mWrappedClient.onEvaluateJavaScriptResult(id, jsonResult);
}
@Override
public boolean shouldOverrideScroll(float deltaX, float deltaY, float currX, float currY) {
return mWrappedClient.shouldOverrideScroll(deltaX, deltaY, currX, currX);
}
@Override
public ActionMode.Callback getSelectActionModeCallback(
Context context, ActionHandler actionHandler, boolean incognito) {
return mWrappedClient.getSelectActionModeCallback(context, actionHandler, incognito);
}
@Override
public void onContextualActionBarShown() {
super.onContextualActionBarShown();
mWrappedClient.onContextualActionBarShown();
}
@Override
public void onContextualActionBarHidden() {
super.onContextualActionBarHidden();
mWrappedClient.onContextualActionBarHidden();
}
@Override
public void onStartContentIntent(Context context, String contentUrl) {
super.onStartContentIntent(context, contentUrl);
mWrappedClient.onStartContentIntent(context, contentUrl);
}
}
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