diff options
Diffstat (limited to 'android_webview/javatests')
3 files changed, 102 insertions, 52 deletions
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwQuotaManagerBridgeTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwQuotaManagerBridgeTest.java index 8b356f9..c7f2cc1 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwQuotaManagerBridgeTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwQuotaManagerBridgeTest.java @@ -11,6 +11,7 @@ import android.webkit.ValueCallback; import org.chromium.android_webview.AwContents; import org.chromium.android_webview.AwQuotaManagerBridge; import org.chromium.android_webview.AwSettings; +import org.chromium.android_webview.test.util.AwQuotaManagerBridgeTestUtil; import org.chromium.base.test.util.Feature; import org.chromium.content.browser.test.util.CallbackHelper; import org.chromium.content.browser.test.util.Criteria; @@ -53,17 +54,9 @@ public class AwQuotaManagerBridgeTest extends AwTestBase { super.tearDown(); } - private AwQuotaManagerBridge getQuotaManagerBridge() throws Exception { - return runTestOnUiThreadAndGetResult(new Callable<AwQuotaManagerBridge>() { - @Override - public AwQuotaManagerBridge call() throws Exception { - return AwQuotaManagerBridge.getInstance(); - } - }); - } - private void deleteAllData() throws Exception { - final AwQuotaManagerBridge bridge = getQuotaManagerBridge(); + final AwQuotaManagerBridge bridge = + AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(this); getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { @@ -73,7 +66,8 @@ public class AwQuotaManagerBridgeTest extends AwTestBase { } private void deleteOrigin(final String origin) throws Exception { - final AwQuotaManagerBridge bridge = getQuotaManagerBridge(); + final AwQuotaManagerBridge bridge = + AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(this); getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { @@ -82,43 +76,6 @@ public class AwQuotaManagerBridgeTest extends AwTestBase { }); } - private static class GetOriginsCallbackHelper extends CallbackHelper { - private AwQuotaManagerBridge.Origins mOrigins; - - public void notifyCalled(AwQuotaManagerBridge.Origins origins) { - mOrigins = origins; - notifyCalled(); - } - - public AwQuotaManagerBridge.Origins getOrigins() { - assert getCallCount() > 0; - return mOrigins; - } - } - - private AwQuotaManagerBridge.Origins getOrigins() throws Exception { - final GetOriginsCallbackHelper callbackHelper = new GetOriginsCallbackHelper(); - final AwQuotaManagerBridge bridge = getQuotaManagerBridge(); - - int callCount = callbackHelper.getCallCount(); - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - bridge.getOrigins( - new ValueCallback<AwQuotaManagerBridge.Origins>() { - @Override - public void onReceiveValue(AwQuotaManagerBridge.Origins origins) { - callbackHelper.notifyCalled(origins); - } - } - ); - } - }); - callbackHelper.waitForCallback(callCount); - - return callbackHelper.getOrigins(); - } - private static class LongValueCallbackHelper extends CallbackHelper { private long mValue; @@ -135,7 +92,8 @@ public class AwQuotaManagerBridgeTest extends AwTestBase { private long getQuotaForOrigin(final String origin) throws Exception { final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper(); - final AwQuotaManagerBridge bridge = getQuotaManagerBridge(); + final AwQuotaManagerBridge bridge = + AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(this); int callCount = callbackHelper.getCallCount(); getInstrumentation().runOnMainSync(new Runnable() { @@ -158,7 +116,8 @@ public class AwQuotaManagerBridgeTest extends AwTestBase { private long getUsageForOrigin(final String origin) throws Exception { final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper(); - final AwQuotaManagerBridge bridge = getQuotaManagerBridge(); + final AwQuotaManagerBridge bridge = + AwQuotaManagerBridgeTestUtil.getQuotaManagerBridge(this); int callCount = callbackHelper.getCallCount(); getInstrumentation().runOnMainSync(new Runnable() { @@ -271,14 +230,15 @@ public class AwQuotaManagerBridgeTest extends AwTestBase { @Override public boolean isSatisfied() { try { - return getOrigins().mOrigins.length > 0; + return AwQuotaManagerBridgeTestUtil.getOrigins( + AwQuotaManagerBridgeTest.this).mOrigins.length > 0; } catch (Exception e) { return false; } } }); - AwQuotaManagerBridge.Origins origins = getOrigins(); + AwQuotaManagerBridge.Origins origins = AwQuotaManagerBridgeTestUtil.getOrigins(this); assertEquals(origins.mOrigins.length, origins.mUsages.length); assertEquals(origins.mOrigins.length, origins.mQuotas.length); diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/StandaloneAwQuotaManagerBridgeTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/StandaloneAwQuotaManagerBridgeTest.java new file mode 100644 index 0000000..43b75bf --- /dev/null +++ b/android_webview/javatests/src/org/chromium/android_webview/test/StandaloneAwQuotaManagerBridgeTest.java @@ -0,0 +1,22 @@ +// Copyright 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 org.chromium.android_webview.AwContents; +import org.chromium.android_webview.AwQuotaManagerBridge; +import org.chromium.android_webview.test.util.AwQuotaManagerBridgeTestUtil; + +/** + * This class tests AwQuotaManagerBridge runs without AwContents etc. It simulates + * use case that user calls WebStorage getInstance() without WebView. + */ +public class StandaloneAwQuotaManagerBridgeTest extends AwTestBase { + public void testStartup() throws Exception { + // AwQuotaManager should run without any issue. + AwQuotaManagerBridge.Origins origins = AwQuotaManagerBridgeTestUtil.getOrigins(this); + assertEquals(origins.mOrigins.length, 0); + assertEquals(AwContents.getNativeInstanceCount(), 0); + } +} diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/util/AwQuotaManagerBridgeTestUtil.java b/android_webview/javatests/src/org/chromium/android_webview/test/util/AwQuotaManagerBridgeTestUtil.java new file mode 100644 index 0000000..6d0782d --- /dev/null +++ b/android_webview/javatests/src/org/chromium/android_webview/test/util/AwQuotaManagerBridgeTestUtil.java @@ -0,0 +1,68 @@ +// Copyright 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.util; + +import android.webkit.ValueCallback; + +import org.chromium.android_webview.AwQuotaManagerBridge; +import org.chromium.android_webview.test.AwTestBase; +import org.chromium.content.browser.test.util.CallbackHelper; + +import java.util.concurrent.Callable; + +/** + * This class provides common methods for AwQuotaManagerBridge related tests + */ +public class AwQuotaManagerBridgeTestUtil { + + public static AwQuotaManagerBridge getQuotaManagerBridge(AwTestBase awTestBase) + throws Exception { + return awTestBase.runTestOnUiThreadAndGetResult(new Callable<AwQuotaManagerBridge>() { + @Override + public AwQuotaManagerBridge call() throws Exception { + return AwQuotaManagerBridge.getInstance(); + } + }); + } + + private static class GetOriginsCallbackHelper extends CallbackHelper { + private AwQuotaManagerBridge.Origins mOrigins; + + public void notifyCalled(AwQuotaManagerBridge.Origins origins) { + mOrigins = origins; + notifyCalled(); + } + + public AwQuotaManagerBridge.Origins getOrigins() { + assert getCallCount() > 0; + return mOrigins; + } + } + + public static AwQuotaManagerBridge.Origins getOrigins(AwTestBase awTestBase) + throws Exception { + final GetOriginsCallbackHelper callbackHelper = new GetOriginsCallbackHelper(); + final AwQuotaManagerBridge bridge = getQuotaManagerBridge(awTestBase); + + int callCount = callbackHelper.getCallCount(); + awTestBase.getInstrumentation().runOnMainSync(new Runnable() { + @Override + public void run() { + bridge.getOrigins( + new ValueCallback<AwQuotaManagerBridge.Origins>() { + @Override + public void onReceiveValue(AwQuotaManagerBridge.Origins origins) { + callbackHelper.notifyCalled(origins); + } + } + ); + } + }); + callbackHelper.waitForCallback(callCount); + + return callbackHelper.getOrigins(); + } + +} |