Index: cc/test/layer_tree_test.cc |
diff --git a/cc/test/layer_tree_test.cc b/cc/test/layer_tree_test.cc |
index 2a0762d39cccda553f015b318ba79ea8711e8bd5..17d653e8dbc6a5d29e7910aaf1c61129ad796af6 100644 |
--- a/cc/test/layer_tree_test.cc |
+++ b/cc/test/layer_tree_test.cc |
@@ -46,6 +46,41 @@ base::TimeDelta TestHooks::LowFrequencyAnimationInterval() const { |
return base::TimeDelta::FromMilliseconds(16); |
} |
+// Adapts ThreadProxy for test. Injects test hooks for testing. |
+class ThreadProxyForTest : public ThreadProxy { |
+ public: |
+ static scoped_ptr<Proxy> Create( |
+ TestHooks* test_hooks, |
+ LayerTreeHost* host, |
+ scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
+ return make_scoped_ptr( |
+ new ThreadProxyForTest(test_hooks, |
+ host, |
+ impl_task_runner)).PassAs<Proxy>(); |
+ } |
+ |
+ const ThreadProxy::MainThreadOnly& main() const { |
+ return ThreadProxy::main(); |
+ } |
+ |
+ const ThreadProxy::CompositorThreadOnly& impl() const { |
+ return ThreadProxy::impl(); |
+ } |
+ |
+ virtual ~ThreadProxyForTest() {} |
+ |
+ private: |
+ TestHooks* test_hooks_; |
+ |
+ ThreadProxyForTest( |
+ TestHooks* test_hooks, |
+ LayerTreeHost* host, |
+ scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) |
+ : ThreadProxy(host, impl_task_runner), |
+ test_hooks_(test_hooks) { |
+ } |
+}; |
+ |
// Adapts LayerTreeHostImpl for test. Runs real code, then invokes test hooks. |
class LayerTreeHostImplForTesting : public LayerTreeHostImpl { |
public: |
@@ -287,10 +322,15 @@ class LayerTreeHostForTesting : public LayerTreeHost { |
scoped_refptr<base::SingleThreadTaskRunner> impl_task_runner) { |
scoped_ptr<LayerTreeHostForTesting> layer_tree_host( |
new LayerTreeHostForTesting(test_hooks, client, settings)); |
- if (impl_task_runner.get()) |
- layer_tree_host->InitializeThreaded(impl_task_runner); |
- else |
- layer_tree_host->InitializeSingleThreaded(client); |
+ if (impl_task_runner.get()) { |
+ layer_tree_host->InitializeForTesting( |
+ ThreadProxyForTest::Create(test_hooks, |
+ layer_tree_host.get(), |
+ impl_task_runner)); |
+ } else { |
+ layer_tree_host->InitializeForTesting( |
+ SingleThreadProxy::Create(layer_tree_host.get(), client)); |
+ } |
return layer_tree_host.Pass(); |
} |
@@ -662,6 +702,20 @@ void LayerTreeTest::RunTestWithImplSidePainting() { |
RunTest(true, false, true); |
} |
+const ThreadProxy::MainThreadOnly& |
+LayerTreeTest::ThreadProxyMainOnly() const { |
+ DCHECK(proxy()); |
+ DCHECK(proxy()->HasImplThread()); |
+ return static_cast<ThreadProxyForTest*>(proxy())->main(); |
+} |
+ |
+const ThreadProxy::CompositorThreadOnly& |
+LayerTreeTest::ThreadProxyImplOnly() const { |
+ DCHECK(proxy()); |
+ DCHECK(proxy()->HasImplThread()); |
+ return static_cast<ThreadProxyForTest*>(proxy())->impl(); |
+} |
+ |
scoped_ptr<OutputSurface> LayerTreeTest::CreateOutputSurface(bool fallback) { |
scoped_ptr<FakeOutputSurface> output_surface = |
CreateFakeOutputSurface(fallback); |