Commit a8592a5e authored by Mehran Mahmoudi's avatar Mehran Mahmoudi Committed by Commit Bot

[Paint Preview] Add intstrumentation test harness for the player

This adds some of the required harness for testing the paint preview
player. It also implements a basic smoke test for the player.

A follow-up CL will add more comprehensive tests to this suite.

Bug: 1049303,1032580
Change-Id: I7694a6b264c3f654476714de38fd613c356dbfde
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2040061Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarCalder Kitagawa <ckitagawa@chromium.org>
Commit-Queue: Mehran Mahmoudi <mahmoudi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739462}
parent 54f5d106
...@@ -817,6 +817,7 @@ android_library("chrome_test_java") { ...@@ -817,6 +817,7 @@ android_library("chrome_test_java") {
"//components/offline_items_collection/core:core_java", "//components/offline_items_collection/core:core_java",
"//components/offline_pages/core/prefetch:offline_prefetch_proto_java", "//components/offline_pages/core/prefetch:offline_prefetch_proto_java",
"//components/omnibox/browser:browser_java", "//components/omnibox/browser:browser_java",
"//components/paint_preview/player/android:javatests",
"//components/payments/content/android:java", "//components/payments/content/android:java",
"//components/payments/mojom:mojom_java", "//components/payments/mojom:mojom_java",
"//components/policy/android:policy_java", "//components/policy/android:policy_java",
...@@ -1179,6 +1180,7 @@ chrome_common_shared_library("libchromefortest") { ...@@ -1179,6 +1180,7 @@ chrome_common_shared_library("libchromefortest") {
"//components/autofill_assistant/browser:test_support", "//components/autofill_assistant/browser:test_support",
"//components/crash/android:crash_android", "//components/crash/android:crash_android",
"//components/minidump_uploader", "//components/minidump_uploader",
"//components/paint_preview/player/android:test_support",
"//components/sync", "//components/sync",
"//components/sync/test/fake_server:fake_server_android", "//components/sync/test/fake_server:fake_server_android",
"//content/public/test/android:content_native_test_support", "//content/public/test/android:content_native_test_support",
...@@ -1500,6 +1502,7 @@ java_group("chrome_public_base_module_java_for_test") { ...@@ -1500,6 +1502,7 @@ java_group("chrome_public_base_module_java_for_test") {
"//chrome/browser/subresource_filter:subresource_filter_java_test_support", "//chrome/browser/subresource_filter:subresource_filter_java_test_support",
"//chrome/browser/thumbnail:thumbnail_java_test_support", "//chrome/browser/thumbnail:thumbnail_java_test_support",
"//components/minidump_uploader:minidump_uploader_java", "//components/minidump_uploader:minidump_uploader_java",
"//components/paint_preview/player/android:javatests",
"//content/public/test/android:content_java_test_support", "//content/public/test/android:content_java_test_support",
] ]
} }
......
...@@ -68,11 +68,14 @@ source_set("test_support") { ...@@ -68,11 +68,14 @@ source_set("test_support") {
sources = [ sources = [
"paint_preview_base_service_test_factory.cc", "paint_preview_base_service_test_factory.cc",
"paint_preview_base_service_test_factory.h", "paint_preview_base_service_test_factory.h",
"test_paint_preview_policy.cc",
"test_paint_preview_policy.h",
] ]
deps = [ deps = [
"//base", "//base",
"//components/keyed_service/core", "//components/keyed_service/core",
"//content/public/browser",
] ]
public_deps = [ ":browser" ] public_deps = [ ":browser" ]
......
// Copyright 2020 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.
#include "components/paint_preview/browser/test_paint_preview_policy.h"
#include "base/callback.h"
#include "base/optional.h"
#include "components/paint_preview/browser/paint_preview_policy.h"
#include "content/public/browser/web_contents.h"
namespace paint_preview {
TestPaintPreviewPolicy::TestPaintPreviewPolicy() = default;
TestPaintPreviewPolicy::~TestPaintPreviewPolicy() = default;
bool TestPaintPreviewPolicy::SupportedForContents(
content::WebContents* web_contents) {
return supported_for_contents_;
}
} // namespace paint_preview
// Copyright 2020 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.
#ifndef COMPONENTS_PAINT_PREVIEW_BROWSER_TEST_PAINT_PREVIEW_POLICY_H_
#define COMPONENTS_PAINT_PREVIEW_BROWSER_TEST_PAINT_PREVIEW_POLICY_H_
#include "components/paint_preview/browser/paint_preview_policy.h"
namespace content {
class WebContents;
}
namespace paint_preview {
// Simple implementation of PaintPreviewPolicy used in tests.
// SupportedForContents defaults to true, but tests may change
// this by calling SetSupportedForContents.
class TestPaintPreviewPolicy : public PaintPreviewPolicy {
public:
TestPaintPreviewPolicy();
~TestPaintPreviewPolicy() override;
bool SupportedForContents(content::WebContents* web_contents) override;
void SetSupportedForContents(bool supported_for_contents) {
supported_for_contents_ = supported_for_contents;
}
private:
bool supported_for_contents_ = true;
};
} // namespace paint_preview
#endif // COMPONENTS_PAINT_PREVIEW_BROWSER_TEST_PAINT_PREVIEW_POLICY_H_
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
source_set("player_android") { source_set("android") {
sources = [ sources = [
"player_compositor_delegate_android.cc", "player_compositor_delegate_android.cc",
"player_compositor_delegate_android.h", "player_compositor_delegate_android.h",
...@@ -28,7 +28,7 @@ source_set("unit_tests") { ...@@ -28,7 +28,7 @@ source_set("unit_tests") {
testonly = true testonly = true
sources = [ "player_compositor_delegate_android_unittest.cc" ] sources = [ "player_compositor_delegate_android_unittest.cc" ]
deps = [ deps = [
":player_android", ":android",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/paint_preview/browser", "//components/paint_preview/browser",
...@@ -70,6 +70,55 @@ android_library("java") { ...@@ -70,6 +70,55 @@ android_library("java") {
] ]
} }
android_library("javatests") {
testonly = true
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
sources = [
"javatests/src/org/chromium/components/paintpreview/player/PaintPreviewPlayerTest.java",
"javatests/src/org/chromium/components/paintpreview/player/PaintPreviewTestRule.java",
"javatests/src/org/chromium/components/paintpreview/player/TestImplementerService.java",
]
deps = [
":java",
"//base:base_java",
"//base:base_java_test_support",
"//base:jni_java",
"//components/paint_preview/browser/android:java",
"//components/signin/core/browser/android:java",
"//components/signin/core/browser/android:signin_java_test_support",
"//content/public/android:content_java",
"//content/public/test/android:content_java_test_support",
"//third_party/android_support_test_runner:rules_java",
"//third_party/android_support_test_runner:runner_java",
"//third_party/junit",
"//ui/android:ui_java_test_support",
]
}
generate_jni("javatests_jni_headers") {
testonly = true
sources = [ "javatests/src/org/chromium/components/paintpreview/player/TestImplementerService.java" ]
}
source_set("test_support") {
testonly = true
sources = [
"javatests/test_implementer_service.cc",
"javatests/test_implementer_service.h",
]
deps = [
":android",
":javatests_jni_headers",
"//base",
"//components/paint_preview/browser",
"//components/paint_preview/browser:test_support",
]
}
junit_binary("paint_preview_junit_tests") { junit_binary("paint_preview_junit_tests") {
sources = [ sources = [
"junit/src/org/chromium/components/paintpreview/player/PlayerManagerTest.java", "junit/src/org/chromium/components/paintpreview/player/PlayerManagerTest.java",
......
include_rules = [
"+components/signin/core/browser",
"+content/public/android",
"+content/public/test/android",
]
// Copyright 2020 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.components.paintpreview.player;
import android.os.Environment;
import android.support.test.filters.MediumTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.task.PostTask;
import org.chromium.base.test.BaseJUnit4ClassRunner;
import org.chromium.base.test.util.ScalableTimeout;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
/**
* Instrumentation tests for the Paint Preview player.
*/
@RunWith(BaseJUnit4ClassRunner.class)
public class PaintPreviewPlayerTest extends DummyUiActivityTestCase {
private static final long TIMEOUT_MS = ScalableTimeout.scaleTimeout(5000);
private static final long POLLING_INTERVAL_MS = ScalableTimeout.scaleTimeout(50);
// TODO(crbug.com/1049303) Change to test data directory when test Proto and SKP files are
// added.
private static final String TEST_DATA_DIR = Environment.getExternalStorageDirectory().getPath();
private static final String TEST_URL = "https://www.google.com";
@Rule
public PaintPreviewTestRule mPaintPreviewTestRule = new PaintPreviewTestRule();
private PlayerManager mPlayerManager;
/**
* Initializes {@link TestImplementerService} and {@link PlayerManager}.
*/
@Test
@MediumTest
public void smokeTest() {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
TestImplementerService service = new TestImplementerService(TEST_DATA_DIR);
mPlayerManager = new PlayerManager(getActivity(), service, TEST_URL);
});
CriteriaHelper.pollUiThread(() -> mPlayerManager != null,
"PlayerManager took too long to initialize.", TIMEOUT_MS,
POLLING_INTERVAL_MS);
}
}
// Copyright 2020 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.components.paintpreview.player;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.test.util.FakeAccountManagerDelegate;
import org.chromium.content_public.browser.test.NativeLibraryTestRule;
/**
* Loads native and initializes the browser process for Paint Preview instrumentation tests.
*/
public class PaintPreviewTestRule extends NativeLibraryTestRule {
private FakeAccountManagerDelegate mAccountManager;
/**
* {@link AccountManagerFacade#get()} is called in the browser initialization path. If we don't
* mock {@link AccountManagerFacade}, we'll run into a failed assertion.
*/
private void setUp() {
mAccountManager = new FakeAccountManagerDelegate(
FakeAccountManagerDelegate.DISABLE_PROFILE_DATA_SOURCE);
AccountManagerFacade.overrideAccountManagerFacadeForTests(mAccountManager);
loadNativeLibraryAndInitBrowserProcess();
}
@Override
public Statement apply(final Statement base, Description description) {
return super.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
setUp();
base.evaluate();
}
}, description);
}
}
// Copyright 2020 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.components.paintpreview.player;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.components.paintpreview.browser.PaintPreviewBaseService;
/**
* A simple implementation of {@link PaintPreviewBaseService} used in tests.
*/
@JNINamespace("paint_preview")
public class TestImplementerService extends PaintPreviewBaseService {
public TestImplementerService(String storagePath) {
super(TestImplementerServiceJni.get().getInstance(storagePath));
}
@NativeMethods
interface Natives {
long getInstance(String storagePath);
}
}
// Copyright 2020 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.
#include "components/paint_preview/player/android/javatests/test_implementer_service.h"
#include <memory>
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/files/file_path.h"
#include "components/paint_preview/browser/paint_preview_base_service.h"
#include "components/paint_preview/browser/test_paint_preview_policy.h"
#include "components/paint_preview/player/android/javatests_jni_headers/TestImplementerService_jni.h"
using base::android::JavaParamRef;
namespace paint_preview {
jlong JNI_TestImplementerService_GetInstance(
JNIEnv* env,
const JavaParamRef<jstring>& j_string_path) {
base::FilePath file_path(
base::android::ConvertJavaStringToUTF8(env, j_string_path));
TestImplementerService* service =
new TestImplementerService(file_path, false);
return reinterpret_cast<intptr_t>(service);
}
TestImplementerService::TestImplementerService(
const base::FilePath& profile_path,
bool is_off_the_record)
: PaintPreviewBaseService(profile_path,
"TestImplementerService",
std::make_unique<TestPaintPreviewPolicy>(),
is_off_the_record) {}
TestImplementerService::~TestImplementerService() = default;
} // namespace paint_preview
// Copyright 2020 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.
#ifndef COMPONENTS_PAINT_PREVIEW_PLAYER_ANDROID_JAVATESTS_TEST_IMPLEMENTER_SERVICE_H_
#define COMPONENTS_PAINT_PREVIEW_PLAYER_ANDROID_JAVATESTS_TEST_IMPLEMENTER_SERVICE_H_
#include "base/files/file_path.h"
#include "components/paint_preview/browser/paint_preview_base_service.h"
#include "components/paint_preview/common/proto/paint_preview.pb.h"
namespace paint_preview {
// A simple implementation of PaintPreviewBaseService used in tests.
class TestImplementerService : public PaintPreviewBaseService {
public:
TestImplementerService(const base::FilePath& profile_dir,
bool is_off_the_record);
~TestImplementerService() override;
TestImplementerService(const TestImplementerService&) = delete;
TestImplementerService& operator=(const TestImplementerService&) = delete;
};
} // namespace paint_preview
#endif // COMPONENTS_PAINT_PREVIEW_PLAYER_ANDROID_JAVATESTS_TEST_IMPLEMENTER_SERVICE_H_
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