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