diff options
author | mkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-19 19:02:38 +0000 |
---|---|---|
committer | mkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-19 19:02:38 +0000 |
commit | a4f99345e6beb043826a4da147f72fb49c554f29 (patch) | |
tree | fb1d9ff9996b2c185bf3f95761bfd0beb3bb6ae6 /android_webview | |
parent | 30591e06f6c96933813d700ae255b2182f6e15e5 (diff) | |
download | chromium_src-a4f99345e6beb043826a4da147f72fb49c554f29.zip chromium_src-a4f99345e6beb043826a4da147f72fb49c554f29.tar.gz chromium_src-a4f99345e6beb043826a4da147f72fb49c554f29.tar.bz2 |
[android_webview] Fix race conditions in AwContentsTest.
Waiting for onPageFinished is not a sufficient condition for a different
AwContentsClient callback to fire. Due to the Java memory model even if a
callback is guaranteed to happen at a later time than onPageFinished there is
no guarantee that the other thread will see the updates.
I also used this as an opportunity to split stuff out from AwContentsTest
because it was way too big.
Finally, I've re-enabled some of the tests since they've been passing locally for me.
BUG=None
TEST=AndroidWebViewTests
Review URL: https://codereview.chromium.org/12279004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183260 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
4 files changed, 403 insertions, 241 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientAutoLoginTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientAutoLoginTest.java new file mode 100644 index 0000000..1053591 --- /dev/null +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientAutoLoginTest.java @@ -0,0 +1,133 @@ +// 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.android_webview.test; + +import android.test.suitebuilder.annotation.SmallTest; +import android.util.Pair; + +import org.chromium.base.test.util.Feature; +import org.chromium.content.browser.test.util.CallbackHelper; +import org.chromium.android_webview.AwContents; +import org.chromium.net.test.util.TestWebServer; + +import java.util.ArrayList; +import java.util.List; + +/** + * Tests for the AwContentsClient.onReceivedLoginRequest callback. + */ +public class AwContentsClientAutoLoginTest extends AndroidWebViewTestBase { + public static class OnReceivedLoginRequestHelper extends CallbackHelper { + String mRealm; + String mAccount; + String mArgs; + + public String getRealm() { + assert getCallCount() > 0; + return mRealm; + } + + public String getAccount() { + assert getCallCount() > 0; + return mAccount; + } + + public String getArgs() { + assert getCallCount() > 0; + return mArgs; + } + + public void notifyCalled(String realm, String account, String args) { + mRealm = realm; + mAccount = account; + mArgs = args; + notifyCalled(); + } + } + + private static class TestAwContentsClient + extends org.chromium.android_webview.test.TestAwContentsClient { + + private OnReceivedLoginRequestHelper mOnReceivedLoginRequestHelper; + + public TestAwContentsClient() { + mOnReceivedLoginRequestHelper = new OnReceivedLoginRequestHelper(); + } + + public OnReceivedLoginRequestHelper getOnReceivedLoginRequestHelper() { + return mOnReceivedLoginRequestHelper; + } + + @Override + public void onReceivedLoginRequest(String realm, String account, String args) { + getOnReceivedLoginRequestHelper().notifyCalled(realm, account, args); + } + } + + private TestAwContentsClient mContentsClient = new TestAwContentsClient(); + + private void autoLoginTestHelper(final String testName, final String xAutoLoginHeader, + final String expectedRealm, final String expectedAccount, final String expectedArgs) + throws Throwable { + AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); + AwContents awContents = testView.getAwContents(); + final OnReceivedLoginRequestHelper loginRequestHelper = + mContentsClient.getOnReceivedLoginRequestHelper(); + + final String path = "/" + testName + ".html"; + final String html = testName; + List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>(); + headers.add(Pair.create("x-auto-login", xAutoLoginHeader)); + + TestWebServer webServer = null; + try { + webServer = new TestWebServer(false); + final String pageUrl = webServer.setResponse(path, html, headers); + final int callCount = loginRequestHelper.getCallCount(); + loadUrlAsync(awContents, pageUrl); + loginRequestHelper.waitForCallback(callCount); + + assertEquals(expectedRealm, loginRequestHelper.getRealm()); + assertEquals(expectedAccount, loginRequestHelper.getAccount()); + assertEquals(expectedArgs, loginRequestHelper.getArgs()); + } finally { + if (webServer != null) webServer.shutdown(); + } + } + + @Feature({"AndroidWebView"}) + @SmallTest + public void testAutoLoginOnGoogleCom() throws Throwable { + autoLoginTestHelper( + "testAutoLoginOnGoogleCom", /* testName */ + "realm=com.google&account=foo%40bar.com&args=random_string", /* xAutoLoginHeader */ + "com.google", /* expectedRealm */ + "foo@bar.com", /* expectedAccount */ + "random_string" /* expectedArgs */); + + } + + @Feature({"AndroidWebView"}) + @SmallTest + public void testAutoLoginWithNullAccount() throws Throwable { + autoLoginTestHelper( + "testAutoLoginOnGoogleCom", /* testName */ + "realm=com.google&args=not.very.inventive", /* xAutoLoginHeader */ + "com.google", /* expectedRealm */ + null, /* expectedAccount */ + "not.very.inventive" /* expectedArgs */); + } + + @Feature({"AndroidWebView"}) + @SmallTest + public void testAutoLoginOnNonGoogle() throws Throwable { + autoLoginTestHelper( + "testAutoLoginOnGoogleCom", /* testName */ + "realm=com.bar&account=foo%40bar.com&args=args", /* xAutoLoginHeader */ + "com.bar", /* expectedRealm */ + "foo@bar.com", /* expectedAccount */ + "args" /* expectedArgs */); + } +} diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientVisitedHistoryTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientVisitedHistoryTest.java new file mode 100644 index 0000000..3269137 --- /dev/null +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientVisitedHistoryTest.java @@ -0,0 +1,177 @@ +// 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.android_webview.test; + +import android.webkit.ValueCallback; +import android.test.suitebuilder.annotation.SmallTest; + +import org.chromium.content.browser.test.util.CallbackHelper; +import org.chromium.base.test.util.Feature; +import org.chromium.android_webview.AwContents; +import org.chromium.net.test.util.TestWebServer; + +/** + * Tests for AwContentsClient.getVisitedHistory and AwContents.doUpdateVisitedHistory callbacks. + */ +public class AwContentsClientVisitedHistoryTest extends AndroidWebViewTestBase { + public static class GetVisitedHistoryHelper extends CallbackHelper { + private ValueCallback<String[]> mCallback; + private boolean mSaveCallback = false; + + public ValueCallback<String[]> getCallback() { + assert getCallCount() > 0; + return mCallback; + } + + public void setSaveCallback(boolean value) { + mSaveCallback = value; + } + + public void notifyCalled(ValueCallback<String[]> callback) { + if (mSaveCallback) { + mCallback = callback; + } + notifyCalled(); + } + } + + public static class DoUpdateVisitedHistoryHelper extends CallbackHelper { + String mUrl; + boolean mIsReload; + + public String getUrl() { + assert getCallCount() > 0; + return mUrl; + } + + public boolean getIsReload() { + assert getCallCount() > 0; + return mIsReload; + } + + public void notifyCalled(String url, boolean isReload) { + mUrl = url; + mIsReload = isReload; + notifyCalled(); + } + } + + private static class TestAwContentsClient + extends org.chromium.android_webview.test.TestAwContentsClient { + + private GetVisitedHistoryHelper mGetVisitedHistoryHelper; + private DoUpdateVisitedHistoryHelper mDoUpdateVisitedHistoryHelper; + + public TestAwContentsClient() { + mGetVisitedHistoryHelper = new GetVisitedHistoryHelper(); + mDoUpdateVisitedHistoryHelper = new DoUpdateVisitedHistoryHelper(); + } + + public GetVisitedHistoryHelper getGetVisitedHistoryHelper() { + return mGetVisitedHistoryHelper; + } + + public DoUpdateVisitedHistoryHelper getDoUpdateVisitedHistoryHelper() { + return mDoUpdateVisitedHistoryHelper; + } + + @Override + public void getVisitedHistory(ValueCallback<String[]> callback) { + getGetVisitedHistoryHelper().notifyCalled(callback); + } + + @Override + public void doUpdateVisitedHistory(String url, boolean isReload) { + getDoUpdateVisitedHistoryHelper().notifyCalled(url, isReload); + } + } + + private TestAwContentsClient mContentsClient = new TestAwContentsClient(); + + @Feature({"AndroidWebView"}) + @SmallTest + public void testUpdateVisitedHistoryCallback() throws Throwable { + AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); + AwContents awContents = testView.getAwContents(); + + final String path = "/testUpdateVisitedHistoryCallback.html"; + final String html = "testUpdateVisitedHistoryCallback"; + + TestWebServer webServer = null; + try { + webServer = new TestWebServer(false); + final String pageUrl = webServer.setResponse(path, html, null); + final DoUpdateVisitedHistoryHelper doUpdateVisitedHistoryHelper = + mContentsClient.getDoUpdateVisitedHistoryHelper(); + int callCount = doUpdateVisitedHistoryHelper.getCallCount(); + loadUrlAsync(awContents, pageUrl); + doUpdateVisitedHistoryHelper.waitForCallback(callCount); + assertEquals(pageUrl, doUpdateVisitedHistoryHelper.getUrl()); + assertEquals(false, doUpdateVisitedHistoryHelper.getIsReload()); + + // Reload + callCount = doUpdateVisitedHistoryHelper.getCallCount(); + loadUrlAsync(awContents, pageUrl); + doUpdateVisitedHistoryHelper.waitForCallback(callCount); + assertEquals(pageUrl, doUpdateVisitedHistoryHelper.getUrl()); + assertEquals(true, doUpdateVisitedHistoryHelper.getIsReload()); + } finally { + if (webServer != null) webServer.shutdown(); + } + } + + @Feature({"AndroidWebView"}) + @SmallTest + public void testGetVisitedHistoryExerciseCodePath() throws Throwable { + // Due to security/privacy restrictions around the :visited css property, it is not + // possible test this end to end without using the flaky and brittle capturing picture of + // the web page. So we are doing the next best thing, exercising all the code paths. + final GetVisitedHistoryHelper visitedHistoryHelper = + mContentsClient.getGetVisitedHistoryHelper(); + final int callCount = visitedHistoryHelper.getCallCount(); + visitedHistoryHelper.setSaveCallback(true); + + AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); + AwContents awContents = testView.getAwContents(); + + final String path = "/testGetVisitedHistoryExerciseCodePath.html"; + final String visitedLinks[] = {"http://foo.com", "http://bar.com", null}; + final String html = "<a src=\"http://foo.com\">foo</a><a src=\"http://bar.com\">bar</a>"; + + TestWebServer webServer = null; + try { + webServer = new TestWebServer(false); + final String pageUrl = webServer.setResponse(path, html, null); + loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); + visitedHistoryHelper.waitForCallback(callCount); + assertNotNull(visitedHistoryHelper.getCallback()); + + visitedHistoryHelper.getCallback().onReceiveValue(visitedLinks); + visitedHistoryHelper.getCallback().onReceiveValue(null); + + loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); + } finally { + if (webServer != null) webServer.shutdown(); + } + } + + @Feature({"AndroidWebView"}) + @SmallTest + public void testGetVisitedHistoryCallbackAfterDestroy() throws Throwable { + GetVisitedHistoryHelper visitedHistoryHelper = + mContentsClient.getGetVisitedHistoryHelper(); + visitedHistoryHelper.setSaveCallback(true); + final int callCount = visitedHistoryHelper.getCallCount(); + AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); + AwContents awContents = testView.getAwContents(); + loadUrlAsync(awContents, "about:blank"); + visitedHistoryHelper.waitForCallback(callCount); + assertNotNull(visitedHistoryHelper.getCallback()); + + destroyAwContentsOnMainSync(awContents); + visitedHistoryHelper.getCallback().onReceiveValue(new String[] {"abc.def"}); + visitedHistoryHelper.getCallback().onReceiveValue(null); + } +} diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java index 4f64c4c..62fda510 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsTest.java @@ -18,7 +18,6 @@ import org.chromium.android_webview.AwContents; import org.chromium.android_webview.test.util.CommonResources; import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.Feature; -import org.chromium.base.test.util.UrlUtils; import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.CriteriaHelper; @@ -28,17 +27,81 @@ import java.io.InputStream; import java.net.URL; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.Callable; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * AwContents tests. */ public class AwContentsTest extends AndroidWebViewTestBase { + public static class OnDownloadStartHelper extends CallbackHelper { + String mUrl; + String mUserAgent; + String mContentDisposition; + String mMimeType; + long mContentLength; + + public String getUrl() { + assert getCallCount() > 0; + return mUrl; + } + + public String getUserAgent() { + assert getCallCount() > 0; + return mUserAgent; + } + + public String getContentDisposition() { + assert getCallCount() > 0; + return mContentDisposition; + } + + public String getMimeType() { + assert getCallCount() > 0; + return mMimeType; + } + + public long getContentLength() { + assert getCallCount() > 0; + return mContentLength; + } + + public void notifyCalled(String url, String userAgent, String contentDisposition, + String mimeType, long contentLength) { + mUrl = url; + mUserAgent = userAgent; + mContentDisposition = contentDisposition; + mMimeType = mimeType; + mContentLength = contentLength; + notifyCalled(); + } + } + + private static class TestAwContentsClient + extends org.chromium.android_webview.test.TestAwContentsClient { + + private OnDownloadStartHelper mOnDownloadStartHelper; + + public TestAwContentsClient() { + mOnDownloadStartHelper = new OnDownloadStartHelper(); + } + + public OnDownloadStartHelper getOnDownloadStartHelper() { + return mOnDownloadStartHelper; + } + + @Override + public void onDownloadStart(String url, + String userAgent, + String contentDisposition, + String mimeType, + long contentLength) { + getOnDownloadStartHelper().notifyCalled(url, userAgent, contentDisposition, mimeType, + contentLength); + } + } + private TestAwContentsClient mContentsClient = new TestAwContentsClient(); @SmallTest @@ -49,12 +112,8 @@ public class AwContentsTest extends AndroidWebViewTestBase { createAwTestContainerView(mContentsClient).getAwContents().destroy(); } - /* - * @LargeTest - * @Feature({"AndroidWebView"}) - * Disabled until we switch to final rendering pipeline. - */ - @DisabledTest + @LargeTest + @Feature({"AndroidWebView"}) public void testCreateLoadDestroyManyTimes() throws Throwable { final int CREATE_AND_DESTROY_REPEAT_COUNT = 10; for (int i = 0; i < CREATE_AND_DESTROY_REPEAT_COUNT; ++i) { @@ -88,7 +147,6 @@ public class AwContentsTest extends AndroidWebViewTestBase { } } - private int callDocumentHasImagesSync(final AwContents awContents) throws Throwable, InterruptedException { // Set up a container to hold the result object and a semaphore to @@ -139,9 +197,8 @@ public class AwContentsTest extends AndroidWebViewTestBase { @SmallTest @Feature({"AndroidWebView"}) public void testClearCacheMemoryAndDisk() throws Throwable { - final TestAwContentsClient contentClient = new TestAwContentsClient(); final AwTestContainerView testContainer = - createAwTestContainerViewOnMainSync(contentClient); + createAwTestContainerViewOnMainSync(mContentsClient); final AwContents awContents = testContainer.getAwContents(); TestWebServer webServer = null; @@ -158,31 +215,31 @@ public class AwContentsTest extends AndroidWebViewTestBase { // First load to populate cache. clearCacheOnUiThread(awContents, true); loadUrlSync(awContents, - contentClient.getOnPageFinishedHelper(), + mContentsClient.getOnPageFinishedHelper(), pageUrl); assertEquals(1, webServer.getRequestCount(pagePath)); // Load about:blank so next load is not treated as reload by webkit and force // revalidate with the server. loadUrlSync(awContents, - contentClient.getOnPageFinishedHelper(), + mContentsClient.getOnPageFinishedHelper(), "about:blank"); // No clearCache call, so should be loaded from cache. loadUrlSync(awContents, - contentClient.getOnPageFinishedHelper(), + mContentsClient.getOnPageFinishedHelper(), pageUrl); assertEquals(1, webServer.getRequestCount(pagePath)); // Same as above. loadUrlSync(awContents, - contentClient.getOnPageFinishedHelper(), + mContentsClient.getOnPageFinishedHelper(), "about:blank"); // Clear cache, so should hit server again. clearCacheOnUiThread(awContents, true); loadUrlSync(awContents, - contentClient.getOnPageFinishedHelper(), + mContentsClient.getOnPageFinishedHelper(), pageUrl); assertEquals(2, webServer.getRequestCount(pagePath)); } finally { @@ -273,162 +330,18 @@ public class AwContentsTest extends AndroidWebViewTestBase { webServer = new TestWebServer(false); final String pageUrl = webServer.setResponse( "/download.txt", data, downloadHeaders); - loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); - - assertTrue(pollOnUiThread(new Callable<Boolean>() { - @Override - public Boolean call() { - // Assert failures are treated as return false. - assertEquals(pageUrl, mContentsClient.mLastDownloadUrl); - assertEquals(contentDisposition, - mContentsClient.mLastDownloadContentDisposition); - assertEquals(mimeType, - mContentsClient.mLastDownloadMimeType); - assertEquals(data.length(), - mContentsClient.mLastDownloadContentLength); - return true; - } - })); - } finally { - if (webServer != null) webServer.shutdown(); - } - } - - @Feature({"AndroidWebView"}) - @SmallTest - public void testUpdateVisitedHistoryCallback() throws Throwable { - AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); - AwContents awContents = testView.getAwContents(); - - final String path = "/testUpdateVisitedHistoryCallback.html"; - final String html = "testUpdateVisitedHistoryCallback"; - - TestWebServer webServer = null; - try { - webServer = new TestWebServer(false); - final String pageUrl = webServer.setResponse(path, html, null); - - loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); - assertEquals(pageUrl, mContentsClient.mLastVisitedUrl); - assertEquals(false, mContentsClient.mLastVisitIsReload); - - // Reload - loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); - assertEquals(pageUrl, mContentsClient.mLastVisitedUrl); - assertEquals(true, mContentsClient.mLastVisitIsReload); - } finally { - if (webServer != null) webServer.shutdown(); - } - } - - @Feature({"AndroidWebView"}) - @SmallTest - public void testGetVisitedHistoryExerciseCodePath() throws Throwable { - // Due to security/privacy restrictions around the :visited css property, it is not - // possible test this end to end without using the flaky and brittle capturing picture of - // the web page. So we are doing the next best thing, exercising all the code paths. - - mContentsClient.mSaveGetVisitedHistoryCallback = true; - AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); - AwContents awContents = testView.getAwContents(); - - final String path = "/testGetVisitedHistoryExerciseCodePath.html"; - final String visitedLinks[] = {"http://foo.com", "http://bar.com", null}; - final String html = "<a src=\"http://foo.com\">foo</a><a src=\"http://bar.com\">bar</a>"; - - TestWebServer webServer = null; - try { - webServer = new TestWebServer(false); - final String pageUrl = webServer.setResponse(path, html, null); - - loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); - assertNotNull(mContentsClient.mGetVisitedHistoryCallback); - - mContentsClient.mGetVisitedHistoryCallback.onReceiveValue(visitedLinks); - mContentsClient.mGetVisitedHistoryCallback.onReceiveValue(null); - - loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); + final OnDownloadStartHelper downloadStartHelper = + mContentsClient.getOnDownloadStartHelper(); + final int callCount = downloadStartHelper.getCallCount(); + loadUrlAsync(awContents, pageUrl); + downloadStartHelper.waitForCallback(callCount); + + assertEquals(pageUrl, downloadStartHelper.getUrl()); + assertEquals(contentDisposition, downloadStartHelper.getContentDisposition()); + assertEquals(mimeType, downloadStartHelper.getMimeType()); + assertEquals(data.length(), downloadStartHelper.getContentLength()); } finally { if (webServer != null) webServer.shutdown(); } } - - /* - * @Feature({"AndroidWebView"}) - * @SmallTest - * Exercising code after destroy causes gpu related crashes. See crbug.com/172184. - */ - @DisabledTest - public void testGetVisitedHistoryCallbackAfterDestroy() throws Throwable { - mContentsClient.mSaveGetVisitedHistoryCallback = true; - AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); - AwContents awContents = testView.getAwContents(); - - loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), "about:blank"); - assertNotNull(mContentsClient.mGetVisitedHistoryCallback); - - destroyAwContentsOnMainSync(awContents); - mContentsClient.mGetVisitedHistoryCallback.onReceiveValue(new String[] {"abc.def"}); - mContentsClient.mGetVisitedHistoryCallback.onReceiveValue(null); - } - - private void autoLoginTestHelper(final String testName, final String xAutoLoginHeader, - final String expectedRealm, final String expectedAccount, final String expectedArgs) - throws Throwable { - AwTestContainerView testView = createAwTestContainerViewOnMainSync(mContentsClient); - AwContents awContents = testView.getAwContents(); - - final String path = "/" + testName + ".html"; - final String html = testName; - List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>(); - headers.add(Pair.create("x-auto-login", xAutoLoginHeader)); - - TestWebServer webServer = null; - try { - webServer = new TestWebServer(false); - final String pageUrl = webServer.setResponse(path, html, headers); - - loadUrlSync(awContents, mContentsClient.getOnPageFinishedHelper(), pageUrl); - - assertEquals(expectedRealm, mContentsClient.mLastAutoLoginRealm); - assertEquals(expectedAccount, mContentsClient.mLastAutoLoginAccount); - assertEquals(expectedArgs, mContentsClient.mLastAutoLoginArgs); - } finally { - if (webServer != null) webServer.shutdown(); - } - } - - @Feature({"AndroidWebView"}) - @SmallTest - public void testAutoLoginOnGoogleCom() throws Throwable { - autoLoginTestHelper( - "testAutoLoginOnGoogleCom", /* testName */ - "realm=com.google&account=foo%40bar.com&args=random_string", /* xAutoLoginHeader */ - "com.google", /* expectedRealm */ - "foo@bar.com", /* expectedAccount */ - "random_string" /* expectedArgs */); - - } - - @Feature({"AndroidWebView"}) - @SmallTest - public void testAutoLoginWithNullAccount() throws Throwable { - autoLoginTestHelper( - "testAutoLoginOnGoogleCom", /* testName */ - "realm=com.google&args=not.very.inventive", /* xAutoLoginHeader */ - "com.google", /* expectedRealm */ - null, /* expectedAccount */ - "not.very.inventive" /* expectedArgs */); - } - - @Feature({"AndroidWebView"}) - @SmallTest - public void testAutoLoginOnNonGoogle() throws Throwable { - autoLoginTestHelper( - "testAutoLoginOnGoogleCom", /* testName */ - "realm=com.bar&account=foo%40bar.com&args=args", /* xAutoLoginHeader */ - "com.bar", /* expectedRealm */ - "foo@bar.com", /* expectedAccount */ - "args" /* expectedArgs */); - } } diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java index 7d99adf3..8e113d9 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java @@ -5,7 +5,6 @@ package org.chromium.android_webview.test; import android.webkit.ConsoleMessage; -import android.webkit.ValueCallback; import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageStartedHelper; @@ -75,11 +74,8 @@ class TestAwContentsClient extends NullContentsClient { @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { - mAddMessageToConsoleHelper.setLevel(consoleMessage.messageLevel().ordinal()); - mAddMessageToConsoleHelper.setMessage(consoleMessage.message()); - mAddMessageToConsoleHelper.setLineNumber(consoleMessage.lineNumber()); - mAddMessageToConsoleHelper.setSourceId(consoleMessage.sourceId()); - mAddMessageToConsoleHelper.notifyCalled(); + mAddMessageToConsoleHelper.notifyCalled(consoleMessage.messageLevel().ordinal(), + consoleMessage.message(), consoleMessage.lineNumber(), consoleMessage.sourceId()); return false; } @@ -89,22 +85,6 @@ class TestAwContentsClient extends NullContentsClient { private int mLineNumber; private String mSourceId; - void setLevel(int level) { - mLevel = level; - } - - void setMessage(String message) { - mMessage = message; - } - - void setLineNumber(int lineNumber) { - mLineNumber = lineNumber; - } - - void setSourceId(String sourceId) { - mSourceId = sourceId; - } - public int getLevel() { assert getCallCount() > 0; return mLevel; @@ -124,54 +104,13 @@ class TestAwContentsClient extends NullContentsClient { assert getCallCount() > 0; return mSourceId; } - } - ValueCallback<String[]> mGetVisitedHistoryCallback; - boolean mSaveGetVisitedHistoryCallback = false; - - @Override - public void getVisitedHistory(ValueCallback<String[]> callback) { - if (mSaveGetVisitedHistoryCallback) { - mGetVisitedHistoryCallback = callback; + void notifyCalled(int level, String message, int lineNumer, String sourceId) { + mLevel = level; + mMessage = message; + mLineNumber = lineNumer; + mSourceId = sourceId; + notifyCalled(); } } - - String mLastVisitedUrl; - boolean mLastVisitIsReload; - - @Override - public void doUpdateVisitedHistory(String url, boolean isReload) { - mLastVisitedUrl = url; - mLastVisitIsReload = isReload; - } - - String mLastDownloadUrl; - String mLastDownloadUserAgent; - String mLastDownloadContentDisposition; - String mLastDownloadMimeType; - long mLastDownloadContentLength; - - @Override - public void onDownloadStart(String url, - String userAgent, - String contentDisposition, - String mimeType, - long contentLength) { - mLastDownloadUrl = url; - mLastDownloadUserAgent = userAgent; - mLastDownloadContentDisposition = contentDisposition; - mLastDownloadMimeType = mimeType; - mLastDownloadContentLength = contentLength; - } - - String mLastAutoLoginRealm; - String mLastAutoLoginAccount; - String mLastAutoLoginArgs; - - @Override - public void onReceivedLoginRequest(String realm, String account, String args) { - mLastAutoLoginRealm = realm; - mLastAutoLoginAccount = account; - mLastAutoLoginArgs = args; - } } |