Commit 67d86f63 authored by yusufo's avatar yusufo Committed by Commit bot

Make hasCookieStoreLoaded visible for testing

We need to start using this method for testing purposes downstream
but without the annotations it is getting stripped our by proguard.

BUG=372774

Review URL: https://codereview.chromium.org/615843004

Cr-Commit-Position: refs/heads/master@{#297867}
parent 5887c778
......@@ -5,6 +5,7 @@
package org.chromium.chrome.browser.prerender;
import org.chromium.base.JNINamespace;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ContentViewUtil;
import org.chromium.chrome.browser.profiles.Profile;
......@@ -20,6 +21,15 @@ public class ExternalPrerenderHandler {
mNativeExternalPrerenderHandler = nativeInit();
}
/**
* Add a prerender for the given url and given content view dimensions.
* @param profile The profile to use for the prerender.
* @param url The url to prerender.
* @param referrer The referrer for the prerender request.
* @param width The width for the content view (render widget host view) for the prerender.
* @param height The height for the content view (render widget host view) for the prerender.
* @return The native web contents pointer that is linked to this prerender. 0 if unsuccessful.
*/
public long addPrerender(Profile profile, String url, String referrer, int width, int height) {
long webContentsPtr = ContentViewUtil.createNativeWebContents(false);
if (nativeAddPrerender(mNativeExternalPrerenderHandler, profile, webContentsPtr,
......@@ -30,15 +40,33 @@ public class ExternalPrerenderHandler {
return 0;
}
/**
* Cancel the current prerender action on this {@link ExternalPrerenderHandler}.
*/
public void cancelCurrentPrerender() {
nativeCancelCurrentPrerender(mNativeExternalPrerenderHandler);
}
/**
* Check whether a given url has been prerendering for the given profile and session id for the
* given web contents.
* @param profile The profile to check for prerendering.
* @param url The url to check for prerender.
* @param webContentsPtr The native pointer for which to compare the session info.
* @return Whether the given url was prerendered.
*/
public static boolean hasPrerenderedUrl(Profile profile, String url, long webContentsPtr) {
return nativeHasPrerenderedUrl(profile, url, webContentsPtr);
}
public static boolean hasCookieStoreLoaded(Profile profile) {
/**
* Check whether the cookie store has been loaded. This is needed for prerender manager to allow
* to add prerenders and this call is to be used to wait until that happens in tests.
* @param profile The profile to be used.
* @return Whether the cookie store has been loaded.
*/
@VisibleForTesting
public static boolean checkCookieStoreLoadedForTesting(Profile profile) {
return nativeHasCookieStoreLoaded(profile);
}
......
......@@ -14,6 +14,8 @@ import org.chromium.chrome.browser.ContentViewUtil;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.shell.ChromeShellTestBase;
import org.chromium.chrome.test.util.TestHttpServerClient;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import java.util.concurrent.Callable;
......@@ -48,8 +50,18 @@ public class ExternalPrerenderRequestTest extends ChromeShellTestBase {
}
};
mProfile = ThreadUtils.runOnUiThreadBlocking(profileCallable);
while (!ExternalPrerenderHandler.hasCookieStoreLoaded(mProfile))
Thread.sleep(CHECK_COOKIE_STORE_FREQUENCY_MS);
final Callable<Boolean> cookieStoreCallable = new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return ExternalPrerenderHandler.checkCookieStoreLoadedForTesting(mProfile);
}
};
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
public boolean isSatisfied() {
return ThreadUtils.runOnUiThreadBlockingNoException(cookieStoreCallable);
}
}, CHECK_COOKIE_STORE_FREQUENCY_MS, 5000));
}
@MediumTest
......
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