Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2687)

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwQuotaManagerBridgeTest.java

Issue 12253057: Implement WebStorage API methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tests still work in progress :( Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/javatests/src/org/chromium/android_webview/test/AwQuotaManagerBridgeTest.java
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
new file mode 100644
index 0000000000000000000000000000000000000000..74e4145f0d3b857a81d630399e15808b9518415b
--- /dev/null
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwQuotaManagerBridgeTest.java
@@ -0,0 +1,207 @@
+// 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.test.suitebuilder.annotation.LargeTest;
+import android.util.Pair;
+import android.webkit.ValueCallback;
+
+import org.chromium.android_webview.AwContents;
+import org.chromium.android_webview.AwQuotaManagerBridge;
+import org.chromium.content.browser.ContentSettings;
+import org.chromium.content.browser.test.util.CallbackHelper;
+import org.chromium.net.test.util.TestWebServer;
+
+import java.util.ArrayList;
+import java.util.concurrent.Callable;
+import java.util.List;
+
+public class AwQuotaManagerBridgeTest extends AndroidWebViewTestBase {
+ private TestAwContentsClient mContentsClient;
+ private AwTestContainerView mTestView;
+ private AwContents mAwContents;
+ private TestWebServer mWebServer;
+ private String mOrigin;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ mContentsClient = new TestAwContentsClient();
+ mTestView = createAwTestContainerViewOnMainSync(mContentsClient);
+ mAwContents = mTestView.getAwContents();
+ mWebServer = new TestWebServer(false);
+ mOrigin = mWebServer.getBaseUrl();
+
+ ContentSettings settings = getContentSettingsOnUiThread(mAwContents);
+ settings.setJavaScriptEnabled(true);
+ settings.setDomStorageEnabled(true);
+ settings.setAppCacheEnabled(true);
+ settings.setAppCachePath("whatever"); // Enables AppCache.
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ if (mWebServer != null) {
+ mWebServer.shutdown();
+ }
+ super.tearDown();
+ }
+
+ private AwQuotaManagerBridge getQuotaManagerBridge() throws Throwable {
mkosiba (inactive) 2013/02/21 11:38:30 nit: this should throw an Exception, not Throwable
boliu 2013/02/21 18:44:45 Apparently the tests can just throw Exception as w
+ return runTestOnUiThreadAndGetResult(new Callable<AwQuotaManagerBridge>() {
+ @Override
+ public AwQuotaManagerBridge call() throws Exception {
+ return AwQuotaManagerBridge.getInstance();
+ }
+ });
+ }
+
+ private void deleteAllData() throws Throwable {
mkosiba (inactive) 2013/02/21 11:38:30 nit: same here and in any method that isn't a test
+ final AwQuotaManagerBridge bridge = getQuotaManagerBridge();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ bridge.deleteAllData();
+ }
+ });
+ }
+
+ private void deleteOrigin(final String origin) throws Throwable {
+ final AwQuotaManagerBridge bridge = getQuotaManagerBridge();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ bridge.deleteOrigin(origin);
+ }
+ });
+ }
+
+ private static class GetOriginsCallbackHelper extends CallbackHelper {
+ AwQuotaManagerBridge.Origins mOrigins;
mkosiba (inactive) 2013/02/21 11:38:30 nit: please expose a getOrigins() method that asse
boliu 2013/02/21 18:44:45 Done.
+
+ public void notifyCalled(AwQuotaManagerBridge.Origins origins) {
+ mOrigins = origins;
+ notifyCalled();
+ }
+ }
+
+ private AwQuotaManagerBridge.Origins getOrigins() throws Throwable {
+ 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.mOrigins;
+ }
+
+ private static class LongValueCallbackHelper extends CallbackHelper {
+ long mValue;
mkosiba (inactive) 2013/02/21 11:38:30 same thing here, please use a getter method.
boliu 2013/02/21 18:44:45 Done.
+
+ public void notifyCalled(long value) {
+ mValue = mValue;
boliu 2013/02/21 18:44:45 And the problem was this. Fixed
+ notifyCalled();
+ }
+ }
+
+ private long getQuotaForOrigin(final String origin) throws Throwable {
+ final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper();
+ final AwQuotaManagerBridge bridge = getQuotaManagerBridge();
+
+ int callCount = callbackHelper.getCallCount();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ bridge.getQuotaForOrigin("foo.com",
+ new ValueCallback<Long>() {
+ @Override
+ public void onReceiveValue(Long quota) {
+ callbackHelper.notifyCalled(quota);
+ }
+ }
+ );
+ }
+ });
+ callbackHelper.waitForCallback(callCount);
+
+ return callbackHelper.mValue;
+ }
+
+ private long getUsageForOrigin(final String origin) throws Throwable {
+ final LongValueCallbackHelper callbackHelper = new LongValueCallbackHelper();
+ final AwQuotaManagerBridge bridge = getQuotaManagerBridge();
+
+ int callCount = callbackHelper.getCallCount();
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ bridge.getUsageForOrigin(origin,
+ new ValueCallback<Long>() {
+ @Override
+ public void onReceiveValue(Long usage) {
+ callbackHelper.notifyCalled(usage);
+ }
+ }
+ );
+ }
+ });
+ callbackHelper.waitForCallback(callCount);
+
+ return callbackHelper.mValue;
+ }
+
+ private void useAppCache() throws Throwable {
+ final String CACHED_FILE_PATH = "/foo.js";
+ final String CACHED_FILE_CONTENTS = "1 + 1;";
+ mWebServer.setResponse(CACHED_FILE_PATH, CACHED_FILE_CONTENTS, null);
+
+ final String MANIFEST_PATH = "/foo.manifest";
+ final String MANIFEST_CONTENTS = "CACHE MANIFEST\nCACHE:\n" + CACHED_FILE_PATH;
+ List<Pair<String, String>> manifestHeaders = new ArrayList<Pair<String, String>>();
+ manifestHeaders.add(Pair.create("Content-Disposition", "text/cache-manifest"));
+ mWebServer.setResponse(MANIFEST_PATH, MANIFEST_CONTENTS, manifestHeaders);
+
+ final String PAGE_PATH = "/appcache.html";
+ final String PAGE_CONTENTS = "<html manifest=\"" + MANIFEST_PATH + "\">" +
+ "<head><script src=\"" + CACHED_FILE_PATH + "\"></script></head></html>";
+ String url = mWebServer.setResponse(PAGE_PATH, PAGE_CONTENTS, null);
+
+ loadUrlSync(mAwContents, mContentsClient.getOnPageFinishedHelper(), url);
+ executeJavaScriptAndWaitForResult(mAwContents, mContentsClient,
+ "window.applicationCache.update();");
+ }
+
+ @LargeTest
+ public void testDeleteAllWithAppCache() throws Throwable {
+ deleteAllData();
+ assertEquals(0, getUsageForOrigin(mOrigin));
+ useAppCache();
+ assertTrue(getUsageForOrigin(mOrigin) > 0);
boliu 2013/02/21 02:36:04 This passes if we use getOrigins to check the usag
+ deleteAllData();
+ assertEquals(0, getUsageForOrigin(mOrigin));
+ }
+
+ @LargeTest
+ public void testDeleteOriginWithAppCache() throws Throwable {
+ }
+
+ @LargeTest
+ public void testGetResultsMatch() throws Throwable {
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698