0

[Paint Preview] Add single frame page instrumentation test for player

This adds a new test for the player that displays an already captured
paint preview. The test asserts that the player view is generated.

Bug: 1049303
Change-Id: I3a2c0bb451c8624d18da6926ad9014e7a07ecf48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076099
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Calder Kitagawa <ckitagawa@chromium.org>
Commit-Queue: Mehran Mahmoudi <mahmoudi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748227}
This commit is contained in:
Mehran Mahmoudi
2020-03-09 15:45:15 +00:00
committed by Commit Bot
parent 6c6e11dd22
commit 7759ba43c9
12 changed files with 177 additions and 89 deletions

2
.gitignore vendored

@ -192,6 +192,8 @@ vs-chromium-project.txt
/components/resources/default_300_percent/google_chrome
/components/search_engines/prepopulated_engines.xml
/components/suggestions.xml
/components/test/data/paint_preview/**/*.pb
/components/test/data/paint_preview/**/*.skp
/components/variations.xml
/components/zucchini/testdata/*.exe
/content/browser/service_worker/proto.xml

14
DEPS

@ -4120,6 +4120,20 @@ hooks = [
'src/third_party/arcore-android-sdk/test-apks/update.py',
],
},
# Pull down Paint Preview test data.
{
'name': 'paint_preview_testdata',
'pattern': '\\.sha1',
'condition': 'checkout_android',
'action': [ 'python',
'src/third_party/depot_tools/download_from_google_storage.py',
'--no_auth',
'--num_threads=4',
'--bucket', 'chromium-android-tools/paint-preview-test-data',
'--recursive',
'-d', 'src/components/test/data/paint_preview',
],
},
# Download Oculus SDK if appropriate.
{
'name': 'libovr',

@ -940,6 +940,7 @@ android_library("chrome_test_java") {
"//chrome/test/data/translate/",
"//chrome/test/media_router/resources/",
"//components/test/data/autofill/",
"//components/test/data/paint_preview/",
"//components/test/data/payments/",
"//content/test/data/browsing_data/",
"//content/test/data/android/authenticator.html",

@ -76,7 +76,7 @@ android_library("player_java_test_support") {
sources = [
"javatests/src/org/chromium/components/paintpreview/player/PaintPreviewTestRule.java",
"javatests/src/org/chromium/components/paintpreview/player/TestImplementerService.java",
"javatests/src/org/chromium/components/paintpreview/player/PaintPreviewTestService.java",
]
deps = [
@ -116,15 +116,15 @@ android_library("javatests") {
generate_jni("javatests_jni_headers") {
testonly = true
sources = [ "javatests/src/org/chromium/components/paintpreview/player/TestImplementerService.java" ]
sources = [ "javatests/src/org/chromium/components/paintpreview/player/PaintPreviewTestService.java" ]
}
source_set("test_support") {
testonly = true
sources = [
"javatests/test_implementer_service.cc",
"javatests/test_implementer_service.h",
"javatests/paint_preview_test_service.cc",
"javatests/paint_preview_test_service.h",
]
deps = [

@ -0,0 +1,81 @@
// 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/paint_preview_test_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/common/proto/paint_preview.pb.h"
#include "components/paint_preview/player/android/javatests_jni_headers/PaintPreviewTestService_jni.h"
using base::android::JavaParamRef;
namespace paint_preview {
namespace {
const char kPaintPreviewDir[] = "paint_preview";
const char kTestDirName[] = "PaintPreviewTestService";
void UpdateSkpPaths(const base::FilePath& test_data_dir,
const DirectoryKey& key,
PaintPreviewBaseService::OnReadProtoCallback callback,
std::unique_ptr<PaintPreviewProto> proto) {
// Update the file path for the root SKP to match the isolated test
// environment.
std::string root_skp_file_name =
base::FilePath(proto->root_frame().file_path()).BaseName().AsUTF8Unsafe();
base::FilePath root_skp_file_path =
test_data_dir.AppendASCII(key.AsciiDirname())
.AppendASCII(root_skp_file_name);
proto->mutable_root_frame()->set_file_path(root_skp_file_path.AsUTF8Unsafe());
// Update the file path for the subframe SKPs to match the isolated test
// environment.
for (auto& subframe : *(proto->mutable_subframes())) {
std::string subframe_skp_file_name =
base::FilePath(subframe.file_path()).BaseName().AsUTF8Unsafe();
base::FilePath subframe_skp_file_path =
test_data_dir.AppendASCII(key.AsciiDirname())
.AppendASCII(subframe_skp_file_name);
subframe.set_file_path(subframe_skp_file_path.AsUTF8Unsafe());
}
std::move(callback).Run(std::move(proto));
}
} // namespace
jlong JNI_PaintPreviewTestService_GetInstance(
JNIEnv* env,
const JavaParamRef<jstring>& j_test_data_dir) {
base::FilePath file_path(
base::android::ConvertJavaStringToUTF8(env, j_test_data_dir));
PaintPreviewTestService* service = new PaintPreviewTestService(file_path);
return reinterpret_cast<intptr_t>(service);
}
PaintPreviewTestService::PaintPreviewTestService(
const base::FilePath& test_data_dir)
: PaintPreviewBaseService(test_data_dir,
kTestDirName,
std::make_unique<TestPaintPreviewPolicy>(),
false),
test_data_dir_(test_data_dir.AppendASCII(kPaintPreviewDir)
.AppendASCII(kTestDirName)) {}
PaintPreviewTestService::~PaintPreviewTestService() = default;
void PaintPreviewTestService::GetCapturedPaintPreviewProto(
const DirectoryKey& key,
OnReadProtoCallback on_read_proto_callback) {
PaintPreviewBaseService::GetCapturedPaintPreviewProto(
key, base::BindOnce(&UpdateSkpPaths, test_data_dir_, key,
std::move(on_read_proto_callback)));
}
} // namespace paint_preview

@ -0,0 +1,33 @@
// 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_PAINT_PREVIEW_TEST_SERVICE_H_
#define COMPONENTS_PAINT_PREVIEW_PLAYER_ANDROID_JAVATESTS_PAINT_PREVIEW_TEST_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 PaintPreviewTestService : public PaintPreviewBaseService {
public:
PaintPreviewTestService(const base::FilePath& test_data_dir);
~PaintPreviewTestService() override;
PaintPreviewTestService(const PaintPreviewTestService&) = delete;
PaintPreviewTestService& operator=(const PaintPreviewTestService&) = delete;
void GetCapturedPaintPreviewProto(
const DirectoryKey& key,
OnReadProtoCallback on_read_proto_callback) override;
private:
base::FilePath test_data_dir_;
};
} // namespace paint_preview
#endif // COMPONENTS_PAINT_PREVIEW_PLAYER_ANDROID_JAVATESTS_PAINT_PREVIEW_TEST_SERVICE_H_

@ -4,8 +4,9 @@
package org.chromium.components.paintpreview.player;
import android.os.Environment;
import android.support.test.filters.MediumTest;
import android.view.View;
import android.view.ViewGroup;
import org.junit.Rule;
import org.junit.Test;
@ -14,6 +15,7 @@ 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.base.test.util.UrlUtils;
import org.chromium.content_public.browser.UiThreadTaskTraits;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.ui.test.util.DummyUiActivityTestCase;
@ -24,12 +26,9 @@ import org.chromium.ui.test.util.DummyUiActivityTestCase;
@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_DIRECTORY_KEY = "test_key";
private static final String TEST_DATA_DIR = "components/test/data/";
private static final String TEST_DIRECTORY_KEY = "wikipedia";
@Rule
public PaintPreviewTestRule mPaintPreviewTestRule = new PaintPreviewTestRule();
@ -37,17 +36,41 @@ public class PaintPreviewPlayerTest extends DummyUiActivityTestCase {
private PlayerManager mPlayerManager;
/**
* Initializes {@link TestImplementerService} and {@link PlayerManager}.
* Tests the the player correctly initializes and displays a sample paint preview with 1 frame.
*/
@Test
@MediumTest
public void smokeTest() {
public void singleFrameDisplayTest() {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, () -> {
TestImplementerService service = new TestImplementerService(TEST_DATA_DIR);
PaintPreviewTestService service =
new PaintPreviewTestService(UrlUtils.getIsolatedTestFilePath(TEST_DATA_DIR));
mPlayerManager = new PlayerManager(getActivity(), service, TEST_DIRECTORY_KEY);
getActivity().setContentView(mPlayerManager.getView());
});
// Wait until PlayerManager is initialized.
CriteriaHelper.pollUiThread(() -> mPlayerManager != null,
"PlayerManager took too long to initialize.", TIMEOUT_MS,
POLLING_INTERVAL_MS);
"PlayerManager was not initialized.", TIMEOUT_MS,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
final View playerHostView = mPlayerManager.getView();
final View activityContentView = getActivity().findViewById(android.R.id.content);
// Assert that the player view is added to the player host view.
CriteriaHelper.pollUiThread(() -> ((ViewGroup) playerHostView).getChildCount() > 0,
"Player view is not added to the host view.", TIMEOUT_MS,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
// Assert that the player view has the same dimensions as the content view.
CriteriaHelper.pollUiThread(() -> {
boolean contentSizeNonZero = activityContentView.getWidth() > 0
&& activityContentView.getHeight() > 0;
boolean viewSizeMatchContent =
activityContentView.getWidth() == playerHostView.getWidth()
&& activityContentView.getHeight() == playerHostView.getHeight();
return contentSizeNonZero && viewSizeMatchContent;
},
"Player size doesn't match R.id.content", TIMEOUT_MS,
CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
}

@ -12,20 +12,20 @@ import org.chromium.components.paintpreview.browser.NativePaintPreviewServicePro
* A simple implementation of {@link NativePaintPreviewServiceProvider} used in tests.
*/
@JNINamespace("paint_preview")
public class TestImplementerService implements NativePaintPreviewServiceProvider {
private long mNativeTestImplementerService;
public class PaintPreviewTestService implements NativePaintPreviewServiceProvider {
private long mNativePaintPreviewTestService;
public TestImplementerService(String storagePath) {
mNativeTestImplementerService = TestImplementerServiceJni.get().getInstance(storagePath);
public PaintPreviewTestService(String testDataDir) {
mNativePaintPreviewTestService = PaintPreviewTestServiceJni.get().getInstance(testDataDir);
}
@Override
public long getNativeService() {
return mNativeTestImplementerService;
return mNativePaintPreviewTestService;
}
@NativeMethods
interface Natives {
long getInstance(String storagePath);
long getInstance(String testDataDir);
}
}

@ -1,41 +0,0 @@
// 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

@ -1,27 +0,0 @@
// 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_

@ -0,0 +1 @@
62bdf642706fbded4194323bb00bc684bd7e0395