OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "base/cancelable_callback.h" | 7 #include "base/cancelable_callback.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
10 #include "cc/proxy.h" | 10 #include "cc/proxy.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 protected: | 39 protected: |
40 virtual void initializeCompositor() = 0; | 40 virtual void initializeCompositor() = 0; |
41 virtual WebLayerTreeViewClient* client() = 0; | 41 virtual WebLayerTreeViewClient* client() = 0; |
42 | 42 |
43 public: | 43 public: |
44 virtual void SetUp() | 44 virtual void SetUp() |
45 { | 45 { |
46 initializeCompositor(); | 46 initializeCompositor(); |
47 m_rootLayer.reset(new WebLayerImpl); | 47 m_rootLayer.reset(new WebLayerImpl); |
48 m_view.reset(new WebLayerTreeViewImpl(client())); | 48 m_view.reset(new WebLayerTreeViewImpl(client())); |
49 scoped_ptr<cc::Thread> implCCThread(NULL); | 49 ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings())); |
50 if (m_implThread) | |
51 implCCThread = cc::ThreadImpl::createForDifferentThread( | |
52 m_implThread->message_loop_proxy()); | |
53 ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings(), | |
54 implCCThread.Pass())); | |
55 m_view->setRootLayer(*m_rootLayer); | 50 m_view->setRootLayer(*m_rootLayer); |
56 m_view->setSurfaceReady(); | 51 m_view->setSurfaceReady(); |
57 } | 52 } |
58 | 53 |
59 virtual void TearDown() | 54 virtual void TearDown() |
60 { | 55 { |
61 Mock::VerifyAndClearExpectations(client()); | 56 Mock::VerifyAndClearExpectations(client()); |
62 | 57 |
63 m_rootLayer.reset(); | 58 m_rootLayer.reset(); |
64 m_view.reset(); | 59 m_view.reset(); |
65 } | 60 } |
66 | 61 |
67 protected: | 62 protected: |
68 scoped_ptr<WebLayer> m_rootLayer; | 63 scoped_ptr<WebLayer> m_rootLayer; |
69 scoped_ptr<WebLayerTreeViewImpl> m_view; | 64 scoped_ptr<WebLayerTreeViewImpl> m_view; |
70 scoped_ptr<base::Thread> m_implThread; | |
71 }; | 65 }; |
72 | 66 |
73 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase { | 67 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase { |
74 protected: | 68 protected: |
75 void composite() | 69 void composite() |
76 { | 70 { |
77 m_view->composite(); | 71 m_view->composite(); |
78 } | 72 } |
79 | 73 |
80 virtual void initializeCompositor() OVERRIDE | 74 virtual void initializeCompositor() OVERRIDE |
81 { | 75 { |
82 } | 76 } |
83 | 77 |
84 virtual WebLayerTreeViewClient* client() OVERRIDE | 78 virtual WebLayerTreeViewClient* client() OVERRIDE |
85 { | 79 { |
86 return &m_client; | 80 return &m_client; |
87 } | 81 } |
88 | 82 |
89 MockWebLayerTreeViewClient m_client; | 83 MockWebLayerTreeViewClient m_client; |
90 }; | 84 }; |
91 | 85 |
92 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase { | 86 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase { |
93 protected: | 87 protected: |
94 virtual ~WebLayerTreeViewThreadedTest() | 88 virtual ~WebLayerTreeViewThreadedTest() |
95 { | 89 { |
| 90 cc::Proxy::setImplThread(0); |
96 } | 91 } |
97 | 92 |
98 void composite() | 93 void composite() |
99 { | 94 { |
100 m_view->setNeedsRedraw(); | 95 m_view->setNeedsRedraw(); |
101 base::CancelableClosure timeout(base::Bind(&MessageLoop::Quit, base::Unr
etained(MessageLoop::current()))); | 96 base::CancelableClosure timeout(base::Bind(&MessageLoop::Quit, base::Unr
etained(MessageLoop::current()))); |
102 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 97 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
103 timeout.callback(), | 98 timeout.callback(), |
104 base::TimeDelta::FromSeconds(5))
; | 99 base::TimeDelta::FromSeconds(5))
; |
105 MessageLoop::current()->Run(); | 100 MessageLoop::current()->Run(); |
106 m_view->finishAllRendering(); | 101 m_view->finishAllRendering(); |
107 } | 102 } |
108 | 103 |
109 virtual void initializeCompositor() OVERRIDE | 104 virtual void initializeCompositor() OVERRIDE |
110 { | 105 { |
111 m_implThread.reset(new base::Thread("ThreadedTest")); | 106 m_implThread.reset(new base::Thread("ThreadedTest")); |
112 ASSERT_TRUE(m_implThread->Start()); | 107 ASSERT_TRUE(m_implThread->Start()); |
| 108 m_implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->
message_loop_proxy()); |
| 109 cc::Proxy::setImplThread(m_implCCThread.get()); |
113 } | 110 } |
114 | 111 |
115 virtual WebLayerTreeViewClient* client() OVERRIDE | 112 virtual WebLayerTreeViewClient* client() OVERRIDE |
116 { | 113 { |
117 return &m_client; | 114 return &m_client; |
118 } | 115 } |
119 | 116 |
120 MockWebLayerTreeViewClientForThreadedTests m_client; | 117 MockWebLayerTreeViewClientForThreadedTests m_client; |
| 118 scoped_ptr<base::Thread> m_implThread; |
| 119 scoped_ptr<cc::Thread> m_implCCThread; |
121 base::CancelableClosure m_timeout; | 120 base::CancelableClosure m_timeout; |
122 }; | 121 }; |
123 | 122 |
124 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks) | 123 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks) |
125 { | 124 { |
126 ::testing::InSequence dummy; | 125 ::testing::InSequence dummy; |
127 | 126 |
128 EXPECT_CALL(m_client, willCommit()); | 127 EXPECT_CALL(m_client, willCommit()); |
129 EXPECT_CALL(m_client, didCommit()); | 128 EXPECT_CALL(m_client, didCommit()); |
130 EXPECT_CALL(m_client, didBeginFrame()); | 129 EXPECT_CALL(m_client, didBeginFrame()); |
131 | 130 |
132 composite(); | 131 composite(); |
133 } | 132 } |
134 | 133 |
135 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks) | 134 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks) |
136 { | 135 { |
137 ::testing::InSequence dummy; | 136 ::testing::InSequence dummy; |
138 | 137 |
139 EXPECT_CALL(m_client, willBeginFrame()); | 138 EXPECT_CALL(m_client, willBeginFrame()); |
140 EXPECT_CALL(m_client, willCommit()); | 139 EXPECT_CALL(m_client, willCommit()); |
141 EXPECT_CALL(m_client, didCommit()); | 140 EXPECT_CALL(m_client, didCommit()); |
142 EXPECT_CALL(m_client, didBeginFrame()); | 141 EXPECT_CALL(m_client, didBeginFrame()); |
143 | 142 |
144 composite(); | 143 composite(); |
145 } | 144 } |
146 | 145 |
147 } // namespace | 146 } // namespace |
OLD | NEW |