Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(583)

Unified Diff: blimp/engine/browser_tests/integration_test.cc

Issue 2320923002: Add a full Blimp integration test. (Closed)
Patch Set: Fixed this a bit more. Still some thread violations :(. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: blimp/engine/browser_tests/integration_test.cc
diff --git a/blimp/engine/browser_tests/integration_test.cc b/blimp/engine/browser_tests/integration_test.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f7cc15abe2d7a5940d3490a6e7d39fd131fb018d
--- /dev/null
+++ b/blimp/engine/browser_tests/integration_test.cc
@@ -0,0 +1,146 @@
+// Copyright 2016 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 "base/callback.h"
+#include "base/macros.h"
+#include "base/memory/ptr_util.h"
+#include "base/run_loop.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/threading/thread_restrictions.h"
+#include "base/time/time.h"
+#include "blimp/client/public/blimp_client_context.h"
+#include "blimp/client/public/contents/blimp_contents.h"
+#include "blimp/client/public/contents/blimp_contents_observer.h"
+#include "blimp/client/public/contents/blimp_contents_view.h"
+#include "blimp/client/public/contents/blimp_navigation_controller.h"
+#include "blimp/client/test/compositor/mock_compositor_dependencies.h"
+#include "blimp/client/test/compositor/test_display_compositor.h"
+#include "blimp/client/test/test_blimp_client_context_delegate.h"
+#include "blimp/engine/browser_tests/blimp_browser_test.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/test/browser_test.h"
+#include "content/public/test/test_utils.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/gl/init/gl_factory.h"
+
+namespace blimp {
+namespace {
+
+class PageLoadWaitBlimpContentsObserver : public client::BlimpContentsObserver {
+ public:
+ 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
+ : client::BlimpContentsObserver(contents), waiter_(nullptr) {}
+ ~PageLoadWaitBlimpContentsObserver() override = default;
+
+ // BlimpContentsObserver implementation.
+ void OnPageLoadingStateChanged(bool loading) override {
+ if (!loading && waiter_)
+ waiter_->Signal();
+ }
+
+ void WaitForPageLoadToFinish(base::WaitableEvent* waiter) {
+ waiter_ = waiter;
+ }
+
+ private:
+ base::WaitableEvent* waiter_;
+};
+
+void WaitFor(base::WaitableEvent* waiter) {
+ while (!waiter->IsSignaled()) {
+ content::RunAllPendingInMessageLoop(content::BrowserThread::UI);
+ content::RunAllPendingInMessageLoop(content::BrowserThread::IO);
+ content::RunAllPendingInMessageLoop(content::BrowserThread::FILE);
+ }
+ waiter->Reset();
+}
+
+class BlimpIntegrationTest : public BlimpBrowserTest {
+ public:
+ BlimpIntegrationTest() {}
+
+ protected:
+ void SetUpOnMainThread() override {
+ BlimpBrowserTest::SetUpOnMainThread();
+
+ {
+ // TODO(me): Sigh... try to fix this before landing :(.
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+ ASSERT_TRUE(gl::init::InitializeGLOneOff());
+ }
+
+ std::unique_ptr<client::CompositorDependencies> compositor_dependencies =
+ 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.
+
+ compositor_ = base::MakeUnique<client::TestDisplayCompositor>(
+ compositor_dependencies.get());
+
+ delegate_ = base::MakeUnique<client::TestBlimpClientContextDelegate>();
+
+ context_ = base::WrapUnique<client::BlimpClientContext>(
+ client::BlimpClientContext::Create(
+ content::BrowserThread::GetTaskRunnerForThread(
+ content::BrowserThread::IO),
+ content::BrowserThread::GetTaskRunnerForThread(
+ content::BrowserThread::FILE),
+ std::move(compositor_dependencies)));
+
+ context_->SetDelegate(delegate_.get());
+ context_->ConnectWithAssignment(GetAssignment());
+ contents_ = context_->CreateBlimpContents(nullptr);
+
+ compositor_->SetContentLayer(contents_->GetView()->GetLayer());
+ }
+
+ void TearDownOnMainThread() override {
+ // Tear down the client objects.
+ contents_.reset();
+ compositor_.reset();
+ context_.reset();
+ delegate_.reset();
+ BlimpBrowserTest::TearDownOnMainThread();
+ }
+
+ std::unique_ptr<client::BlimpClientContextDelegate> delegate_;
+ std::unique_ptr<client::BlimpClientContext> context_;
+ std::unique_ptr<client::TestDisplayCompositor> compositor_;
+ std::unique_ptr<client::BlimpContents> contents_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BlimpIntegrationTest);
+};
+
+IN_PROC_BROWSER_TEST_F(BlimpIntegrationTest, TestBasicRenderPath) {
+ base::WaitableEvent waiter(base::WaitableEvent::ResetPolicy::MANUAL,
+ base::WaitableEvent::InitialState::NOT_SIGNALED);
+
+ PageLoadWaitBlimpContentsObserver observer(contents_.get());
+ compositor_->SetSize(gfx::Size(1, 1));
+ contents_->GetView()->SetSizeAndScale(gfx::Size(1, 1), 1.f);
+
+ contents_->Show();
+ contents_->GetNavigationController().LoadURL(
+ GURL("data:text/html;charset=utf-8,<html><body "
+ "style=background-color:#FF0000></body></html>"));
+
+ observer.WaitForPageLoadToFinish(&waiter);
+ WaitFor(&waiter);
+
+ client::TestDisplayCompositor::CopyRequest copy_request;
+ compositor_->GetBitmap(&copy_request);
+ WaitFor(&copy_request.waiter);
+
+ EXPECT_NE(nullptr, copy_request.result);
+ EXPECT_EQ(1, copy_request.result->width());
+ EXPECT_EQ(1, copy_request.result->height());
+
+ SkAutoLockPixels bitmap_lock(*copy_request.result);
+ EXPECT_EQ(SK_ColorRED, copy_request.result->getColor(0, 0));
+}
+
+} // namespace
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698