Chromium Code Reviews| 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/test/compositor/mock_compositor_dependencies.h" | |
| 18 #include "blimp/client/test/compositor/test_display_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 "content/public/browser/browser_thread.h" | |
| 22 #include "content/public/test/browser_test.h" | |
| 23 #include "content/public/test/test_utils.h" | |
| 24 #include "testing/gmock/include/gmock/gmock.h" | |
| 25 #include "testing/gtest/include/gtest/gtest.h" | |
| 26 #include "third_party/skia/include/core/SkBitmap.h" | |
| 27 #include "third_party/skia/include/core/SkColor.h" | |
| 28 #include "ui/gl/init/gl_factory.h" | |
| 29 | |
| 30 namespace blimp { | |
| 31 namespace { | |
| 32 | |
| 33 class PageLoadWaitBlimpContentsObserver : public client::BlimpContentsObserver { | |
| 34 public: | |
| 35 explicit PageLoadWaitBlimpContentsObserver(client::BlimpContents* contents) | |
|
Khushal
2016/09/13 04:47:24
How about just creating this object after you load
David Trainor- moved to gerrit
2016/09/13 06:18:05
Wait logic cleaned up a bit. Let's talk about thi
| |
| 36 : client::BlimpContentsObserver(contents), waiter_(nullptr) {} | |
| 37 ~PageLoadWaitBlimpContentsObserver() override = default; | |
| 38 | |
| 39 // BlimpContentsObserver implementation. | |
| 40 void OnPageLoadingStateChanged(bool loading) override { | |
| 41 if (!loading && waiter_) | |
| 42 waiter_->Signal(); | |
| 43 } | |
| 44 | |
| 45 void WaitForPageLoadToFinish(base::WaitableEvent* waiter) { | |
| 46 waiter_ = waiter; | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 base::WaitableEvent* waiter_; | |
| 51 }; | |
| 52 | |
| 53 void WaitFor(base::WaitableEvent* waiter) { | |
| 54 while (!waiter->IsSignaled()) { | |
| 55 content::RunAllPendingInMessageLoop(content::BrowserThread::UI); | |
| 56 content::RunAllPendingInMessageLoop(content::BrowserThread::IO); | |
| 57 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | |
| 58 } | |
| 59 waiter->Reset(); | |
| 60 } | |
| 61 | |
| 62 class BlimpIntegrationTest : public BlimpBrowserTest { | |
| 63 public: | |
| 64 BlimpIntegrationTest() {} | |
| 65 | |
| 66 protected: | |
| 67 void SetUpOnMainThread() override { | |
| 68 BlimpBrowserTest::SetUpOnMainThread(); | |
| 69 | |
| 70 { | |
| 71 // TODO(me): Sigh... try to fix this before landing :(. | |
| 72 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
| 73 ASSERT_TRUE(gl::init::InitializeGLOneOff()); | |
| 74 } | |
| 75 | |
| 76 std::unique_ptr<client::CompositorDependencies> compositor_dependencies = | |
| 77 base::MakeUnique<client::MockCompositorDependencies>(); | |
|
Khushal
2016/09/13 04:47:24
We can use the real BlimpCompositorDependencies he
David Trainor- moved to gerrit
2016/09/13 06:18:05
Acknowledged.
| |
| 78 | |
| 79 compositor_ = base::MakeUnique<client::TestDisplayCompositor>( | |
| 80 compositor_dependencies.get()); | |
| 81 | |
| 82 delegate_ = base::MakeUnique<client::TestBlimpClientContextDelegate>(); | |
| 83 | |
| 84 context_ = base::WrapUnique<client::BlimpClientContext>( | |
| 85 client::BlimpClientContext::Create( | |
| 86 content::BrowserThread::GetTaskRunnerForThread( | |
| 87 content::BrowserThread::IO), | |
| 88 content::BrowserThread::GetTaskRunnerForThread( | |
| 89 content::BrowserThread::FILE), | |
| 90 std::move(compositor_dependencies))); | |
| 91 | |
| 92 context_->SetDelegate(delegate_.get()); | |
| 93 context_->ConnectWithAssignment(GetAssignment()); | |
| 94 contents_ = context_->CreateBlimpContents(nullptr); | |
| 95 | |
| 96 compositor_->SetContentLayer(contents_->GetView()->GetLayer()); | |
| 97 } | |
| 98 | |
| 99 void TearDownOnMainThread() override { | |
| 100 // Tear down the client objects. | |
| 101 contents_.reset(); | |
| 102 compositor_.reset(); | |
| 103 context_.reset(); | |
| 104 delegate_.reset(); | |
| 105 BlimpBrowserTest::TearDownOnMainThread(); | |
| 106 } | |
| 107 | |
| 108 std::unique_ptr<client::BlimpClientContextDelegate> delegate_; | |
| 109 std::unique_ptr<client::BlimpClientContext> context_; | |
| 110 std::unique_ptr<client::TestDisplayCompositor> compositor_; | |
| 111 std::unique_ptr<client::BlimpContents> contents_; | |
| 112 | |
| 113 private: | |
| 114 DISALLOW_COPY_AND_ASSIGN(BlimpIntegrationTest); | |
| 115 }; | |
| 116 | |
| 117 IN_PROC_BROWSER_TEST_F(BlimpIntegrationTest, TestBasicRenderPath) { | |
| 118 base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::MANUAL, | |
| 119 base::WaitableEvent::InitialState::NOT_SIGNALED); | |
| 120 | |
| 121 PageLoadWaitBlimpContentsObserver observer(contents_.get()); | |
| 122 compositor_->SetSize(gfx::Size(1, 1)); | |
| 123 contents_->GetView()->SetSizeAndScale(gfx::Size(1, 1), 1.f); | |
| 124 | |
| 125 contents_->Show(); | |
| 126 contents_->GetNavigationController().LoadURL( | |
| 127 GURL("data:text/html;charset=utf-8,<html><body " | |
| 128 "style=background-color:#FF0000></body></html>")); | |
| 129 | |
| 130 observer.WaitForPageLoadToFinish(&waiter); | |
| 131 WaitFor(&waiter); | |
| 132 | |
| 133 client::TestDisplayCompositor::CopyRequest copy_request; | |
| 134 compositor_->GetBitmap(©_request); | |
| 135 WaitFor(©_request.waiter); | |
| 136 | |
| 137 EXPECT_NE(nullptr, copy_request.result); | |
| 138 EXPECT_EQ(1, copy_request.result->width()); | |
| 139 EXPECT_EQ(1, copy_request.result->height()); | |
| 140 | |
| 141 SkAutoLockPixels bitmap_lock(*copy_request.result); | |
| 142 EXPECT_EQ(SK_ColorRED, copy_request.result->getColor(0, 0)); | |
| 143 } | |
| 144 | |
| 145 } // namespace | |
| 146 } // namespace blimp | |
| OLD | NEW |