Commit 0c79994f authored by Nate Fischer's avatar Nate Fischer Committed by Commit Bot

AW: implement flushCookie for the network service

This implements CookieManager#flush() for the network service code path.

Now that this is implemented, we can easily test this functionality
(and this renames HttpCacheTest -> OnDiskFileTest since the file is now
more general).

This removes a TODO to implement more CookieManager APIs, because this
is the final API for AwCookieManagerWrapper.

Bug: 902641, 933456, 933462
Test: run_webview_instrumentation_test_apk \
Test: --enable-features=NetworkService,NetworkServiceInProcess \
Test: -f=OnDiskFileTest#*
Cq-Include-Trybots: master.tryserver.chromium.android:android_mojo
Change-Id: Ic99990719e87f8b1ed9bdc51aa7f1920c1ee5b88
Reviewed-on: https://chromium-review.googlesource.com/c/1481195
Commit-Queue: Nate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarChangwan Ryu <changwan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635699}
parent 8f861fa4
......@@ -511,7 +511,11 @@ void CookieManager::FlushCookieStore() {
}
void CookieManager::FlushCookieStoreAsyncHelper(base::OnceClosure complete) {
GetCookieStore()->FlushStore(std::move(complete));
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
GetCookieManagerWrapper()->FlushCookieStore(std::move(complete));
} else {
GetCookieStore()->FlushStore(std::move(complete));
}
}
bool CookieManager::HasCookies() {
......
......@@ -55,4 +55,11 @@ void AwCookieManagerWrapper::GetAllCookies(GetCookieListCallback callback) {
cookie_manager_->GetAllCookies(std::move(callback));
}
void AwCookieManagerWrapper::FlushCookieStore(
FlushCookieStoreCallback callback) {
// TODO(ntfschr): handle the case where content layer isn't initialized yet
// (http://crbug.com/933461).
cookie_manager_->FlushCookieStore(std::move(callback));
}
} // namespace android_webview
......@@ -30,6 +30,8 @@ class AwCookieManagerWrapper {
network::mojom::CookieManager::SetCanonicalCookieCallback;
using DeleteCookiesCallback =
network::mojom::CookieManager::DeleteCookiesCallback;
using FlushCookieStoreCallback =
network::mojom::CookieManager::FlushCookieStoreCallback;
// Called when content layer starts up, to pass in a NetworkContextPtr for us
// to use for Cookies APIs.
......@@ -37,7 +39,6 @@ class AwCookieManagerWrapper {
network::mojom::CookieManagerPtrInfo cookie_manager_info);
// Thin wrappers around network::mojom::CookieManager APIs.
// TODO(ntfschr): implement the other APIs we need (http://crbug.com/933462).
void GetCookieList(const GURL& url,
const net::CookieOptions& cookie_options,
GetCookieListCallback callback);
......@@ -52,6 +53,8 @@ class AwCookieManagerWrapper {
void GetAllCookies(GetCookieListCallback callback);
void FlushCookieStore(FlushCookieStoreCallback callback);
private:
// A CookieManagerPtr which is cloned from the NetworkContext's
// CookieManagerPtr (but, lives on this thread).
......
......@@ -4,6 +4,7 @@
package org.chromium.android_webview.test;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
......@@ -13,6 +14,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.android_webview.AwContents;
import org.chromium.android_webview.AwCookieManager;
import org.chromium.base.FileUtils;
import org.chromium.base.test.util.Feature;
import org.chromium.net.test.util.TestWebServer;
......@@ -20,14 +22,16 @@ import org.chromium.net.test.util.TestWebServer;
import java.io.File;
/**
* Test suite for the HTTP cache.
* Test suite for files WebView creates on disk. This includes HTTP cache and the cookies file.
*/
@RunWith(AwJUnit4ClassRunner.class)
public class HttpCacheTest {
public class OnDiskFileTest {
@Rule
public AwActivityTestRule mActivityTestRule = new AwActivityTestRule() {
@Override
public boolean needsBrowserProcessStarted() {
// We need to control when the browser process starts, so that we can delete the
// file-under-test before the test starts up.
return false;
}
};
......@@ -67,4 +71,24 @@ public class HttpCacheTest {
Assert.assertTrue(webViewCacheDir.isDirectory());
Assert.assertTrue(webViewCacheDir.list().length > 0);
}
@Test
@SmallTest
@Feature({"AndroidWebView"})
public void testCookiePathIsInsideDataDir() throws Exception {
File webViewCookiePath = new File(InstrumentationRegistry.getInstrumentation()
.getTargetContext()
.getDir("webview", Context.MODE_PRIVATE)
.getPath(),
"Cookies");
webViewCookiePath.delete();
// Set a cookie and flush it to disk. This should guarantee the cookie file is created.
final AwCookieManager cookieManager = new AwCookieManager();
final String url = "http://www.example.com";
cookieManager.setCookie(url, "key=value");
cookieManager.flushCookieStore();
Assert.assertTrue(webViewCookiePath.isFile());
}
}
......@@ -242,12 +242,12 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
"../javatests/src/org/chromium/android_webview/test/GetTitleTest.java",
"../javatests/src/org/chromium/android_webview/test/HeapProfilingTest.java",
"../javatests/src/org/chromium/android_webview/test/HttpAuthDatabaseTest.java",
"../javatests/src/org/chromium/android_webview/test/HttpCacheTest.java",
"../javatests/src/org/chromium/android_webview/test/KeySystemTest.java",
"../javatests/src/org/chromium/android_webview/test/LoadDataWithBaseUrlTest.java",
"../javatests/src/org/chromium/android_webview/test/LoadUrlTest.java",
"../javatests/src/org/chromium/android_webview/test/MediaAccessPermissionRequestTest.java",
"../javatests/src/org/chromium/android_webview/test/NavigationHistoryTest.java",
"../javatests/src/org/chromium/android_webview/test/OnDiskFileTest.java",
"../javatests/src/org/chromium/android_webview/test/PlatformMediaCodecTest.java",
"../javatests/src/org/chromium/android_webview/test/PolicyUrlFilteringTest.java",
"../javatests/src/org/chromium/android_webview/test/PopupWindowTest.java",
......
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