| Index: android_webview/browser/browser_view_renderer_unittest.cc
|
| diff --git a/android_webview/browser/browser_view_renderer_unittest.cc b/android_webview/browser/browser_view_renderer_unittest.cc
|
| index 0eba0a82c17b8268e9e38db6ec8c1f22b9e7dbfa..1bcfd0fe381c2eb21c193c961bad2751f36dfd5f 100644
|
| --- a/android_webview/browser/browser_view_renderer_unittest.cc
|
| +++ b/android_webview/browser/browser_view_renderer_unittest.cc
|
| @@ -13,6 +13,7 @@
|
| #include "android_webview/browser/test/rendering_test.h"
|
| #include "base/location.h"
|
| #include "base/single_thread_task_runner.h"
|
| +#include "base/threading/thread_task_runner_handle.h"
|
| #include "cc/output/compositor_frame.h"
|
| #include "content/public/test/test_synchronous_compositor_android.h"
|
|
|
| @@ -123,6 +124,10 @@ class TestAnimateInAndOutOfScreen : public RenderingTest {
|
| ParentCompositorDrawConstraints constraints =
|
| GetCompositorFrameConsumer()->GetParentDrawConstraintsOnUI();
|
| switch (on_draw_count_) {
|
| + case 0u:
|
| + // This OnParentDrawConstraintsUpdated is generated by
|
| + // connecting the compositor frame consumer to the producer.
|
| + break;
|
| case 1u:
|
| EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_));
|
| break;
|
| @@ -257,21 +262,9 @@ class SwitchOutputSurfaceIdTest : public ResourceRenderingTest {
|
| int frame_number) override {
|
| static const FrameInfo infos[] = {
|
| // First output surface.
|
| - {0u, 1u},
|
| - {0u, 1u},
|
| - {0u, 2u},
|
| - {0u, 2u},
|
| - {0u, 3u},
|
| - {0u, 3u},
|
| - {0u, 4u},
|
| + {0u, 1u}, {0u, 1u}, {0u, 2u}, {0u, 2u}, {0u, 3u}, {0u, 3u}, {0u, 4u},
|
| // Second output surface.
|
| - {1u, 1u},
|
| - {1u, 1u},
|
| - {1u, 2u},
|
| - {1u, 2u},
|
| - {1u, 3u},
|
| - {1u, 3u},
|
| - {1u, 4u},
|
| + {1u, 1u}, {1u, 1u}, {1u, 2u}, {1u, 2u}, {1u, 3u}, {1u, 3u}, {1u, 4u},
|
| };
|
| if (frame_number >= static_cast<int>(arraysize(infos))) {
|
| return nullptr;
|
| @@ -334,7 +327,7 @@ class RenderThreadManagerDeletionTest : public ResourceRenderingTest {
|
|
|
| void CheckResults() override {
|
| OutputSurfaceResourceCountMap resource_counts;
|
| - render_thread_manager_.reset();
|
| + functor_.reset();
|
| // Make sure resources for the last frame are returned.
|
| EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts());
|
| EndTest();
|
| @@ -346,4 +339,67 @@ class RenderThreadManagerDeletionTest : public ResourceRenderingTest {
|
|
|
| RENDERING_TEST_F(RenderThreadManagerDeletionTest);
|
|
|
| +class RenderThreadManagerSwitchTest : public ResourceRenderingTest {
|
| + std::unique_ptr<content::SynchronousCompositor::Frame> GetFrame(
|
| + int frame_number) override {
|
| + switch (frame_number) {
|
| + case 0: {
|
| + // Draw a frame with initial RTM.
|
| + break;
|
| + }
|
| + case 1: {
|
| + // Switch to new RTM.
|
| + std::unique_ptr<FakeFunctor> functor(new FakeFunctor);
|
| + functor->Init(window_.get(),
|
| + base::WrapUnique(new RenderThreadManager(
|
| + functor.get(), base::ThreadTaskRunnerHandle::Get())));
|
| + browser_view_renderer_->SetCurrentCompositorFrameConsumer(
|
| + functor->GetCompositorFrameConsumer());
|
| + saved_functor_ = std::move(functor_);
|
| + functor_ = std::move(functor);
|
| + break;
|
| + }
|
| + case 2: {
|
| + // Draw a frame with the new RTM, but also redraw the initial RTM.
|
| + window_->RequestDrawGL(saved_functor_.get());
|
| + break;
|
| + }
|
| + case 3: {
|
| + // Switch back to the initial RTM, allowing the new RTM to be destroyed.
|
| + functor_ = std::move(saved_functor_);
|
| + browser_view_renderer_->SetCurrentCompositorFrameConsumer(
|
| + functor_->GetCompositorFrameConsumer());
|
| + break;
|
| + }
|
| + default:
|
| + return nullptr;
|
| + }
|
| +
|
| + const uint32_t output_surface_id = 0u;
|
| + const cc::ResourceId resource_id =
|
| + static_cast<cc::ResourceId>(frame_number);
|
| +
|
| + std::unique_ptr<content::SynchronousCompositor::Frame> frame(
|
| + new content::SynchronousCompositor::Frame);
|
| + frame->output_surface_id = output_surface_id;
|
| + frame->frame = ConstructFrame(resource_id);
|
| + ++expected_return_count_[output_surface_id][resource_id];
|
| + return frame;
|
| + }
|
| +
|
| + void CheckResults() override {
|
| + OutputSurfaceResourceCountMap resource_counts;
|
| + functor_.reset();
|
| + // Make sure resources for all frames are returned.
|
| + EXPECT_EQ(expected_return_count_, GetReturnedResourceCounts());
|
| + EndTest();
|
| + }
|
| +
|
| + private:
|
| + std::unique_ptr<FakeFunctor> saved_functor_;
|
| + OutputSurfaceResourceCountMap expected_return_count_;
|
| +};
|
| +
|
| +RENDERING_TEST_F(RenderThreadManagerSwitchTest);
|
| +
|
| } // namespace android_webview
|
|
|