Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "android_webview/browser/test/rendering_test.h" | 5 #include "android_webview/browser/test/rendering_test.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/browser_view_renderer.h" | 7 #include "android_webview/browser/browser_view_renderer.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | |
| 10 #include "content/public/test/test_synchronous_compositor_android.h" | 9 #include "content/public/test/test_synchronous_compositor_android.h" |
| 11 | 10 |
| 12 namespace android_webview { | 11 namespace android_webview { |
| 13 | 12 |
| 14 RenderingTest::RenderingTest() : message_loop_(new base::MessageLoop) { | 13 RenderingTest::RenderingTest() : message_loop_(new base::MessageLoop) { |
| 14 ui_proxy_ = base::MessageLoopProxy::current(); | |
|
hush (inactive)
2014/12/10 22:41:38
why do you remove it from initialization list?
boliu
2014/12/10 23:14:11
Initializer list must come in the order things are
| |
| 15 } | 15 } |
| 16 | 16 |
| 17 RenderingTest::~RenderingTest() { | 17 RenderingTest::~RenderingTest() { |
| 18 if (window_.get()) | |
| 19 window_->Detach(); | |
| 18 } | 20 } |
| 19 | 21 |
| 20 void RenderingTest::SetUpTestHarness() { | 22 void RenderingTest::SetUpTestHarness() { |
| 21 DCHECK(!browser_view_renderer_.get()); | 23 DCHECK(!browser_view_renderer_.get()); |
| 22 browser_view_renderer_.reset( | 24 browser_view_renderer_.reset( |
| 23 new BrowserViewRenderer(this, base::MessageLoopProxy::current())); | 25 new BrowserViewRenderer(this, base::MessageLoopProxy::current())); |
| 26 InitializeCompositor(); | |
| 27 Attach(); | |
| 24 } | 28 } |
| 25 | 29 |
| 26 class RenderingTest::ScopedInitializeCompositor { | |
| 27 public: | |
| 28 explicit ScopedInitializeCompositor(RenderingTest* test) : test_(test) { | |
| 29 test_->InitializeCompositor(); | |
| 30 } | |
| 31 | |
| 32 ~ScopedInitializeCompositor() { test_->TeardownCompositor(); } | |
| 33 | |
| 34 private: | |
| 35 RenderingTest* test_; | |
| 36 DISALLOW_COPY_AND_ASSIGN(ScopedInitializeCompositor); | |
| 37 }; | |
| 38 | |
| 39 void RenderingTest::InitializeCompositor() { | 30 void RenderingTest::InitializeCompositor() { |
| 40 DCHECK(!compositor_.get()); | 31 DCHECK(!compositor_.get()); |
| 41 DCHECK(browser_view_renderer_.get()); | 32 DCHECK(browser_view_renderer_.get()); |
| 42 compositor_.reset(new content::TestSynchronousCompositor); | 33 compositor_.reset(new content::TestSynchronousCompositor); |
| 43 compositor_->SetClient(browser_view_renderer_.get()); | 34 compositor_->SetClient(browser_view_renderer_.get()); |
| 44 } | 35 } |
| 45 | 36 |
| 46 void RenderingTest::TeardownCompositor() { | 37 void RenderingTest::Attach() { |
| 47 DCHECK(compositor_.get()); | 38 window_.reset( |
| 48 DCHECK(browser_view_renderer_.get()); | 39 new FakeWindow(browser_view_renderer_.get(), this, gfx::Rect(100, 100))); |
| 49 compositor_.reset(); | |
| 50 } | 40 } |
| 51 | 41 |
| 52 void RenderingTest::RunTest() { | 42 void RenderingTest::RunTest() { |
| 53 ScopedInitializeCompositor initialize_compositor(this); | 43 SetUpTestHarness(); |
| 54 StartTest(); | 44 |
| 45 ui_proxy_->PostTask( | |
| 46 FROM_HERE, base::Bind(&RenderingTest::StartTest, base::Unretained(this))); | |
| 47 message_loop_->Run(); | |
| 48 } | |
| 49 | |
| 50 void RenderingTest::StartTest() { | |
| 51 EndTest(); | |
| 52 } | |
| 53 | |
| 54 void RenderingTest::EndTest() { | |
| 55 ui_proxy_->PostTask(FROM_HERE, base::Bind(&RenderingTest::QuitMessageLoop, | |
| 56 base::Unretained(this))); | |
| 57 } | |
| 58 | |
| 59 void RenderingTest::QuitMessageLoop() { | |
| 60 DCHECK_EQ(base::MessageLoop::current(), message_loop_.get()); | |
| 61 message_loop_->QuitWhenIdle(); | |
| 55 } | 62 } |
| 56 | 63 |
| 57 bool RenderingTest::RequestDrawGL(bool wait_for_completion) { | 64 bool RenderingTest::RequestDrawGL(bool wait_for_completion) { |
| 58 return false; | 65 window_->RequestDrawGL(wait_for_completion); |
| 66 return true; | |
| 59 } | 67 } |
| 60 | 68 |
| 61 void RenderingTest::OnNewPicture() { | 69 void RenderingTest::OnNewPicture() { |
| 62 } | 70 } |
| 63 | 71 |
| 64 void RenderingTest::PostInvalidate() { | 72 void RenderingTest::PostInvalidate() { |
| 73 window_->PostInvalidate(); | |
| 65 } | 74 } |
| 66 | 75 |
| 67 void RenderingTest::InvalidateOnFunctorDestroy() { | 76 void RenderingTest::InvalidateOnFunctorDestroy() { |
| 68 } | 77 } |
| 69 | 78 |
| 70 gfx::Point RenderingTest::GetLocationOnScreen() { | 79 gfx::Point RenderingTest::GetLocationOnScreen() { |
| 71 return gfx::Point(); | 80 return gfx::Point(); |
| 72 } | 81 } |
| 73 | 82 |
| 74 bool RenderingTest::IsFlingActive() const { | 83 bool RenderingTest::IsFlingActive() const { |
| 75 return false; | 84 return false; |
| 76 } | 85 } |
| 77 | 86 |
| 78 } // namespace android_webview | 87 } // namespace android_webview |
| OLD | NEW |