Commit 9cc448d4 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

Extend PrefetchFeedFlowTest to test running in Reduced Mode.

Tests are largely the same as PrefetchFeedFlowTest with a couple of
changes in external code and in the test itself so it works in Reduced
Mode.

Bug: 959957
Change-Id: I75bdf3e149460e8734572f0b7fe6aaae61b796b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1669656
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarDan H <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677031}
parent eb26f201
...@@ -111,6 +111,20 @@ public class OfflineTestUtil { ...@@ -111,6 +111,20 @@ public class OfflineTestUtil {
return result.get(); return result.get();
} }
public static byte[] getRawThumbnail(long offlineId)
throws TimeoutException, InterruptedException {
final AtomicReference<byte[]> result = new AtomicReference<>();
final CallbackHelper callbackHelper = new CallbackHelper();
TestThreadUtils.runOnUiThreadBlocking(() -> {
nativeGetRawThumbnail(offlineId, (byte[] rawThumbnail) -> {
result.set(rawThumbnail);
callbackHelper.notifyCalled();
});
});
callbackHelper.waitForCallback(0);
return result.get();
}
// Waits for the offline model to initialize and returns an OfflinePageBridge. // Waits for the offline model to initialize and returns an OfflinePageBridge.
public static OfflinePageBridge getOfflinePageBridge() public static OfflinePageBridge getOfflinePageBridge()
throws TimeoutException, InterruptedException { throws TimeoutException, InterruptedException {
...@@ -175,6 +189,7 @@ public class OfflineTestUtil { ...@@ -175,6 +189,7 @@ public class OfflineTestUtil {
private static native void nativeGetRequestsInQueue(Callback<SavePageRequest[]> callback); private static native void nativeGetRequestsInQueue(Callback<SavePageRequest[]> callback);
private static native void nativeGetAllPages( private static native void nativeGetAllPages(
List<OfflinePageItem> offlinePages, final Callback<List<OfflinePageItem>> callback); List<OfflinePageItem> offlinePages, final Callback<List<OfflinePageItem>> callback);
private static native void nativeGetRawThumbnail(long offlineId, Callback<byte[]> callback);
private static native void nativeStartRequestCoordinatorProcessing(); private static native void nativeStartRequestCoordinatorProcessing();
private static native void nativeInterceptWithOfflineError(String url, Runnable readyRunnable); private static native void nativeInterceptWithOfflineError(String url, Runnable readyRunnable);
private static native void nativeClearIntercepts(); private static native void nativeClearIntercepts();
......
...@@ -46,7 +46,7 @@ RequestCoordinator* GetRequestCoordinator() { ...@@ -46,7 +46,7 @@ RequestCoordinator* GetRequestCoordinator() {
return RequestCoordinatorFactory::GetForBrowserContext(GetProfile()); return RequestCoordinatorFactory::GetForBrowserContext(GetProfile());
} }
OfflinePageModel* GetOfflinePageModel() { OfflinePageModel* GetOfflinePageModel() {
return OfflinePageModelFactory::GetForBrowserContext(GetProfile()); return OfflinePageModelFactory::GetForKey(::android::GetLastUsedProfileKey());
} }
void OnGetAllRequestsDone( void OnGetAllRequestsDone(
...@@ -67,6 +67,15 @@ void OnGetAllPagesDone( ...@@ -67,6 +67,15 @@ void OnGetAllPagesDone(
base::android::RunObjectCallbackAndroid(j_callback_obj, j_result_obj); base::android::RunObjectCallbackAndroid(j_callback_obj, j_result_obj);
} }
void OnGetVisualsDoneExtractThumbnail(
const ScopedJavaGlobalRef<jobject>& j_callback_obj,
std::unique_ptr<OfflinePageVisuals> visuals) {
JNIEnv* env = base::android::AttachCurrentThread();
ScopedJavaLocalRef<jbyteArray> j_bytes =
base::android::ToJavaByteArray(env, visuals->thumbnail);
base::android::RunObjectCallbackAndroid(j_callback_obj, j_bytes);
}
void OnDeletePageDone(const ScopedJavaGlobalRef<jobject>& j_callback_obj, void OnDeletePageDone(const ScopedJavaGlobalRef<jobject>& j_callback_obj,
OfflinePageModel::DeletePageResult result) { OfflinePageModel::DeletePageResult result) {
base::android::RunIntCallbackAndroid(j_callback_obj, base::android::RunIntCallbackAndroid(j_callback_obj,
...@@ -191,6 +200,18 @@ void JNI_OfflineTestUtil_GetAllPages( ...@@ -191,6 +200,18 @@ void JNI_OfflineTestUtil_GetAllPages(
&OnGetAllPagesDone, std::move(j_result_ref), std::move(j_callback_ref))); &OnGetAllPagesDone, std::move(j_result_ref), std::move(j_callback_ref)));
} }
void JNI_OfflineTestUtil_GetRawThumbnail(
JNIEnv* env,
jlong j_offline_id,
const JavaParamRef<jobject>& j_callback_obj) {
DCHECK(j_offline_id);
GetOfflinePageModel()->GetVisualsByOfflineId(
j_offline_id,
base::BindOnce(&OnGetVisualsDoneExtractThumbnail,
ScopedJavaGlobalRef<jobject>(j_callback_obj)));
}
void JNI_OfflineTestUtil_DeletePagesByOfflineId( void JNI_OfflineTestUtil_DeletePagesByOfflineId(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jlongArray>& j_offline_ids_array, const JavaParamRef<jlongArray>& j_offline_ids_array,
......
...@@ -71,10 +71,13 @@ void PrefetchServiceImpl::ForceRefreshSuggestions() { ...@@ -71,10 +71,13 @@ void PrefetchServiceImpl::ForceRefreshSuggestions() {
if (suggestions_provider_) { if (suggestions_provider_) {
// Feed only. // Feed only.
NewSuggestionsAvailable(); NewSuggestionsAvailable();
} else { } else if (suggested_articles_observer_) {
// Zine only. // Zine only.
DCHECK(suggested_articles_observer_);
suggested_articles_observer_->ConsumeSuggestions(); suggested_articles_observer_->ConsumeSuggestions();
} else {
// Neither |suggestions_provider_| nor |suggested_articles_observer_| are
// set in reduced mode, which is only supported with Feed.
// ForceRefreshSuggestions() is only called in reduced mode in tests.
} }
} }
......
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