OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/callback.h" |
| 6 #include "base/macros.h" |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" |
| 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/threading/thread_restrictions.h" |
| 11 #include "base/time/time.h" |
| 12 #include "blimp/client/public/blimp_client_context.h" |
| 13 #include "blimp/client/public/contents/blimp_contents.h" |
| 14 #include "blimp/client/public/contents/blimp_contents_observer.h" |
| 15 #include "blimp/client/public/contents/blimp_contents_view.h" |
| 16 #include "blimp/client/public/contents/blimp_navigation_controller.h" |
| 17 #include "blimp/client/support/compositor/compositor_dependencies_impl.h" |
| 18 #include "blimp/client/test/compositor/test_blimp_embedder_compositor.h" |
| 19 #include "blimp/client/test/test_blimp_client_context_delegate.h" |
| 20 #include "blimp/engine/browser_tests/blimp_browser_test.h" |
| 21 #include "blimp/engine/browser_tests/blimp_contents_view_readback_helper.h" |
| 22 #include "blimp/engine/browser_tests/waitable_content_pump.h" |
| 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/test/browser_test.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "third_party/skia/include/core/SkColor.h" |
| 29 #include "third_party/skia/include/core/SkGraphics.h" |
| 30 #include "ui/gl/gl_implementation.h" |
| 31 #include "ui/gl/init/gl_factory.h" |
| 32 |
| 33 namespace blimp { |
| 34 namespace { |
| 35 |
| 36 class PageLoadWaitBlimpContentsObserver : public client::BlimpContentsObserver { |
| 37 public: |
| 38 explicit PageLoadWaitBlimpContentsObserver(client::BlimpContents* contents) |
| 39 : client::BlimpContentsObserver(contents), waiter_(nullptr) {} |
| 40 ~PageLoadWaitBlimpContentsObserver() override = default; |
| 41 |
| 42 // BlimpContentsObserver implementation. |
| 43 void OnPageLoadingStateChanged(bool loading) override { |
| 44 if (!loading && waiter_) |
| 45 waiter_->Signal(); |
| 46 } |
| 47 |
| 48 void WaitForPageLoadToFinish(base::WaitableEvent* waiter) { |
| 49 waiter_ = waiter; |
| 50 } |
| 51 |
| 52 private: |
| 53 base::WaitableEvent* waiter_; |
| 54 }; |
| 55 |
| 56 class BlimpIntegrationTest : public BlimpBrowserTest { |
| 57 public: |
| 58 BlimpIntegrationTest() {} |
| 59 |
| 60 protected: |
| 61 void SetUpOnMainThread() override { |
| 62 BlimpBrowserTest::SetUpOnMainThread(); |
| 63 |
| 64 AllowUIWaits(); |
| 65 |
| 66 { |
| 67 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 68 ASSERT_TRUE(gl::init::InitializeGLOneOff()); |
| 69 } |
| 70 SkGraphics::Init(); |
| 71 |
| 72 // After GL is initialized, build a gl::DisableNullDrawGLBindings to make |
| 73 // sure GL actually draws for this test. |
| 74 scoped_enable_gl_bindings_ = |
| 75 base::MakeUnique<gl::DisableNullDrawGLBindings>(); |
| 76 |
| 77 std::unique_ptr<client::CompositorDependencies> compositor_dependencies = |
| 78 base::MakeUnique<client::CompositorDependenciesImpl>(); |
| 79 |
| 80 compositor_ = base::MakeUnique<client::TestBlimpEmbedderCompositor>( |
| 81 compositor_dependencies.get()); |
| 82 |
| 83 delegate_ = base::MakeUnique<client::TestBlimpClientContextDelegate>(); |
| 84 |
| 85 context_ = base::WrapUnique<client::BlimpClientContext>( |
| 86 client::BlimpClientContext::Create( |
| 87 content::BrowserThread::GetTaskRunnerForThread( |
| 88 content::BrowserThread::IO), |
| 89 content::BrowserThread::GetTaskRunnerForThread( |
| 90 content::BrowserThread::FILE), |
| 91 std::move(compositor_dependencies))); |
| 92 |
| 93 context_->SetDelegate(delegate_.get()); |
| 94 context_->ConnectWithAssignment(GetAssignment()); |
| 95 contents_ = context_->CreateBlimpContents(nullptr); |
| 96 |
| 97 compositor_->SetContentLayer(contents_->GetView()->GetLayer()); |
| 98 } |
| 99 |
| 100 void TearDownOnMainThread() override { |
| 101 // Tear down the client objects. Ordering is important. |
| 102 contents_.reset(); |
| 103 compositor_.reset(); |
| 104 context_.reset(); |
| 105 delegate_.reset(); |
| 106 BlimpBrowserTest::TearDownOnMainThread(); |
| 107 } |
| 108 |
| 109 std::unique_ptr<client::BlimpClientContextDelegate> delegate_; |
| 110 std::unique_ptr<client::BlimpClientContext> context_; |
| 111 std::unique_ptr<client::TestBlimpEmbedderCompositor> compositor_; |
| 112 std::unique_ptr<client::BlimpContents> contents_; |
| 113 |
| 114 private: |
| 115 std::unique_ptr<gl::DisableNullDrawGLBindings> scoped_enable_gl_bindings_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(BlimpIntegrationTest); |
| 118 }; |
| 119 |
| 120 IN_PROC_BROWSER_TEST_F(BlimpIntegrationTest, TestFullRenderPath) { |
| 121 WaitableContentPump waiter; |
| 122 |
| 123 PageLoadWaitBlimpContentsObserver observer(contents_.get()); |
| 124 |
| 125 // Set up the compositor viewport to be a 1x1 screen. We only need a single |
| 126 // pixel for validation. |
| 127 compositor_->SetSize(gfx::Size(1, 1)); |
| 128 contents_->GetView()->SetSizeAndScale(gfx::Size(1, 1), 1.f); |
| 129 |
| 130 // Show the BlimpContents and trigger a load of a URL that sets a red |
| 131 // background. |
| 132 contents_->Show(); |
| 133 contents_->GetNavigationController().LoadURL( |
| 134 GURL("data:text/html;charset=utf-8,<html><body " |
| 135 "style=background-color:#FF0000></body></html>")); |
| 136 |
| 137 // Block the test execution until loading finishes. |
| 138 observer.WaitForPageLoadToFinish(waiter.event()); |
| 139 waiter.Wait(); |
| 140 |
| 141 // Grab a readback of the page content. Block the test execution until the |
| 142 // readback completes. |
| 143 BlimpContentsViewReadbackHelper readback_helper; |
| 144 contents_->GetView()->CopyFromCompositingSurface( |
| 145 readback_helper.GetCallback()); |
| 146 WaitableContentPump::WaitFor(readback_helper.event()); |
| 147 |
| 148 // Validate the readback bitmap basic characteristics. |
| 149 SkBitmap* bitmap = readback_helper.GetBitmap(); |
| 150 EXPECT_NE(nullptr, bitmap); |
| 151 EXPECT_EQ(1, bitmap->width()); |
| 152 EXPECT_EQ(1, bitmap->height()); |
| 153 |
| 154 // Validate the readback bitmap contents. |
| 155 SkAutoLockPixels bitmap_lock(*bitmap); |
| 156 EXPECT_EQ(SK_ColorRED, bitmap->getColor(0, 0)); |
| 157 } |
| 158 |
| 159 } // namespace |
| 160 } // namespace blimp |
OLD | NEW |