Add initial unit tests for the android embedding (flutter/engine#17921)

This commit is contained in:
Emmanuel Garcia
2020-04-26 20:45:28 -07:00
committed by GitHub
parent a0b5e3ea3a
commit f6c5bdea96
11 changed files with 122 additions and 9 deletions

View File

@@ -74,6 +74,7 @@ group("flutter") {
"//flutter/lib/ui:ui_unittests",
"//flutter/runtime:runtime_unittests",
"//flutter/shell/common:shell_unittests",
"//flutter/shell/platform/android/external_view_embedder:android_external_view_embedder_unittests",
"//flutter/shell/platform/embedder:embedder_unittests",
"//flutter/testing:testing_unittests",
"//flutter/third_party/txt:txt_unittests",

View File

@@ -641,8 +641,6 @@ FILE: ../../../flutter/shell/platform/android/android_environment_gl.h
FILE: ../../../flutter/shell/platform/android/android_exports.lst
FILE: ../../../flutter/shell/platform/android/android_external_texture_gl.cc
FILE: ../../../flutter/shell/platform/android/android_external_texture_gl.h
FILE: ../../../flutter/shell/platform/android/android_external_view_embedder.cc
FILE: ../../../flutter/shell/platform/android/android_external_view_embedder.h
FILE: ../../../flutter/shell/platform/android/android_native_window.cc
FILE: ../../../flutter/shell/platform/android/android_native_window.h
FILE: ../../../flutter/shell/platform/android/android_shell_holder.cc
@@ -657,6 +655,9 @@ FILE: ../../../flutter/shell/platform/android/android_surface_vulkan.cc
FILE: ../../../flutter/shell/platform/android/android_surface_vulkan.h
FILE: ../../../flutter/shell/platform/android/apk_asset_provider.cc
FILE: ../../../flutter/shell/platform/android/apk_asset_provider.h
FILE: ../../../flutter/shell/platform/android/external_view_embedder/external_view_embedder.cc
FILE: ../../../flutter/shell/platform/android/external_view_embedder/external_view_embedder.h
FILE: ../../../flutter/shell/platform/android/external_view_embedder/external_view_embedder_unittests.cc
FILE: ../../../flutter/shell/platform/android/flutter_main.cc
FILE: ../../../flutter/shell/platform/android/flutter_main.h
FILE: ../../../flutter/shell/platform/android/io/flutter/Log.java

View File

@@ -29,8 +29,6 @@ shared_library("flutter_shell_native") {
"android_environment_gl.h",
"android_external_texture_gl.cc",
"android_external_texture_gl.h",
"android_external_view_embedder.cc",
"android_external_view_embedder.h",
"android_native_window.cc",
"android_native_window.h",
"android_shell_holder.cc",
@@ -67,6 +65,7 @@ shared_library("flutter_shell_native") {
"//flutter/runtime",
"//flutter/runtime:libdart",
"//flutter/shell/common",
"//flutter/shell/platform/android/external_view_embedder",
"//third_party/skia",
]

View File

@@ -12,8 +12,8 @@
#include "flutter/shell/gpu/gpu_surface_gl.h"
#include "flutter/shell/platform/android/android_context_gl.h"
#include "flutter/shell/platform/android/android_environment_gl.h"
#include "flutter/shell/platform/android/android_external_view_embedder.h"
#include "flutter/shell/platform/android/android_surface.h"
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
namespace flutter {

View File

@@ -9,8 +9,8 @@
#include "flutter/fml/platform/android/jni_weak_ref.h"
#include "flutter/fml/platform/android/scoped_java_ref.h"
#include "flutter/shell/gpu/gpu_surface_software.h"
#include "flutter/shell/platform/android/android_external_view_embedder.h"
#include "flutter/shell/platform/android/android_surface.h"
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
namespace flutter {

View File

@@ -9,9 +9,9 @@
#include <memory>
#include "flutter/fml/macros.h"
#include "flutter/shell/gpu/gpu_surface_vulkan_delegate.h"
#include "flutter/shell/platform/android/android_external_view_embedder.h"
#include "flutter/shell/platform/android/android_native_window.h"
#include "flutter/shell/platform/android/android_surface.h"
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
#include "flutter/vulkan/vulkan_window.h"
namespace flutter {

View File

@@ -0,0 +1,47 @@
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/android/config.gni")
import("//flutter/common/config.gni")
import("//flutter/shell/config.gni")
import("//flutter/shell/gpu/gpu.gni")
import("//flutter/shell/version/version.gni")
import("//flutter/testing/testing.gni")
source_set("external_view_embedder") {
sources = [
"external_view_embedder.cc",
"external_view_embedder.h",
]
public_configs = [ "//flutter:config" ]
deps = [
"//flutter/common",
"//flutter/flow",
"//flutter/fml",
"//third_party/skia",
]
}
test_fixtures("external_view_embedder_fixtures") {
fixtures = []
}
executable("android_external_view_embedder_unittests") {
testonly = true
sources = [
"external_view_embedder_unittests.cc",
]
deps = [
":external_view_embedder",
":external_view_embedder_fixtures",
"//flutter/testing",
"//flutter/testing:dart",
"//flutter/testing:skia",
]
}

View File

@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/platform/android/android_external_view_embedder.h"
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
#include "fml/trace_event.h"
#include "flutter/fml/trace_event.h"
namespace flutter {

View File

@@ -0,0 +1,63 @@
// Copyright 2013 The Flutter 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 "gtest/gtest.h"
#include "flutter/shell/platform/android/external_view_embedder/external_view_embedder.h"
namespace flutter {
namespace testing {
TEST(AndroidExternalViewEmbedder, GetCurrentCanvases) {
auto embedder = new AndroidExternalViewEmbedder();
embedder->BeginFrame(SkISize::Make(10, 20), nullptr, 1.0);
embedder->PrerollCompositeEmbeddedView(
0, std::make_unique<EmbeddedViewParams>());
embedder->PrerollCompositeEmbeddedView(
1, std::make_unique<EmbeddedViewParams>());
auto canvases = embedder->GetCurrentCanvases();
ASSERT_EQ(2UL, canvases.size());
ASSERT_EQ(SkISize::Make(10, 20), canvases[0]->getBaseLayerSize());
ASSERT_EQ(SkISize::Make(10, 20), canvases[1]->getBaseLayerSize());
}
TEST(AndroidExternalViewEmbedder, CompositeEmbeddedView) {
auto embedder = new AndroidExternalViewEmbedder();
embedder->PrerollCompositeEmbeddedView(
0, std::make_unique<EmbeddedViewParams>());
ASSERT_TRUE(embedder->CompositeEmbeddedView(0) != nullptr);
embedder->PrerollCompositeEmbeddedView(
1, std::make_unique<EmbeddedViewParams>());
ASSERT_TRUE(embedder->CompositeEmbeddedView(1) != nullptr);
}
TEST(AndroidExternalViewEmbedder, FinishFrame) {
auto embedder = new AndroidExternalViewEmbedder();
embedder->PrerollCompositeEmbeddedView(
0, std::make_unique<EmbeddedViewParams>());
embedder->FinishFrame();
auto canvases = embedder->GetCurrentCanvases();
ASSERT_EQ(0UL, canvases.size());
}
TEST(AndroidExternalViewEmbedder, CancelFrame) {
auto embedder = new AndroidExternalViewEmbedder();
embedder->PrerollCompositeEmbeddedView(
0, std::make_unique<EmbeddedViewParams>());
embedder->CancelFrame();
auto canvases = embedder->GetCurrentCanvases();
ASSERT_EQ(0UL, canvases.size());
}
} // namespace testing
} // namespace flutter

View File

@@ -143,6 +143,8 @@ def RunCCTests(build_dir, filter):
RunEngineExecutable(build_dir, 'testing_unittests', filter, shuffle_flags)
RunEngineExecutable(build_dir, 'android_external_view_embedder_unittests', filter, shuffle_flags)
# These unit-tests are Objective-C and can only run on Darwin.
if IsMac():
RunEngineExecutable(build_dir, 'flutter_channels_unittests', filter, shuffle_flags)