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

Side by Side Diff: cc/layers/delegated_frame_resource_collection_unittest.cc

Issue 485043003: cc: Use correct message loop proxy in BlockingTaskRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits. Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/delegated_frame_resource_collection.cc ('k') | cc/layers/delegated_renderer_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "cc/layers/delegated_frame_resource_collection.h" 9 #include "cc/layers/delegated_frame_resource_collection.h"
10 #include "cc/resources/returned_resource.h" 10 #include "cc/resources/returned_resource.h"
11 #include "cc/resources/transferable_resource.h" 11 #include "cc/resources/transferable_resource.h"
12 #include "cc/trees/blocking_task_runner.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace cc { 15 namespace cc {
15 namespace { 16 namespace {
16 17
17 class DelegatedFrameResourceCollectionTest 18 class DelegatedFrameResourceCollectionTest
18 : public testing::Test, 19 : public testing::Test,
19 public DelegatedFrameResourceCollectionClient { 20 public DelegatedFrameResourceCollectionClient {
20 protected: 21 protected:
21 DelegatedFrameResourceCollectionTest() : resources_available_(false) {} 22 DelegatedFrameResourceCollectionTest() : resources_available_(false) {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 74
74 ReturnCallback return_callback = 75 ReturnCallback return_callback =
75 resource_collection_->GetReturnResourcesCallbackForImplThread(); 76 resource_collection_->GetReturnResourcesCallbackForImplThread();
76 77
77 // Callback shouldn't take a ref since it's sent to other threads. 78 // Callback shouldn't take a ref since it's sent to other threads.
78 EXPECT_TRUE(resource_collection_->HasOneRef()); 79 EXPECT_TRUE(resource_collection_->HasOneRef());
79 } 80 }
80 81
81 void ReturnResourcesOnThread(ReturnCallback callback, 82 void ReturnResourcesOnThread(ReturnCallback callback,
82 const ReturnedResourceArray& resources, 83 const ReturnedResourceArray& resources,
83 base::WaitableEvent* event) { 84 base::WaitableEvent* event,
84 callback.Run(resources); 85 BlockingTaskRunner* main_thread_task_runner) {
86 callback.Run(resources, main_thread_task_runner);
85 if (event) 87 if (event)
86 event->Wait(); 88 event->Wait();
87 } 89 }
88 90
89 // Tests that the ReturnCallback can run safely on threads even after the 91 // Tests that the ReturnCallback can run safely on threads even after the
90 // last references to the collection were dropped. 92 // last references to the collection were dropped.
91 // Flaky: crbug.com/313441 93 // Flaky: crbug.com/313441
92 TEST_F(DelegatedFrameResourceCollectionTest, Thread) { 94 TEST_F(DelegatedFrameResourceCollectionTest, Thread) {
93 base::Thread thread("test thread"); 95 base::Thread thread("test thread");
94 thread.Start(); 96 thread.Start();
97 scoped_ptr<BlockingTaskRunner> main_thread_task_runner(
98 BlockingTaskRunner::Create(base::MessageLoopProxy::current()));
95 99
96 TransferableResourceArray resources = CreateResourceArray(); 100 TransferableResourceArray resources = CreateResourceArray();
97 resource_collection_->ReceivedResources(resources); 101 resource_collection_->ReceivedResources(resources);
98 resource_collection_->RefResources(resources); 102 resource_collection_->RefResources(resources);
99 103
100 ReturnedResourceArray returned_resources; 104 ReturnedResourceArray returned_resources;
101 TransferableResource::ReturnResources(resources, &returned_resources); 105 TransferableResource::ReturnResources(resources, &returned_resources);
102 106
103 base::WaitableEvent event(false, false); 107 base::WaitableEvent event(false, false);
104 108
105 { 109 {
106 base::RunLoop run_loop; 110 base::RunLoop run_loop;
107 resources_available_closure_ = run_loop.QuitClosure(); 111 resources_available_closure_ = run_loop.QuitClosure();
108 112
109 thread.message_loop()->PostTask( 113 thread.message_loop()->PostTask(
110 FROM_HERE, 114 FROM_HERE,
111 base::Bind( 115 base::Bind(
112 &ReturnResourcesOnThread, 116 &ReturnResourcesOnThread,
113 resource_collection_->GetReturnResourcesCallbackForImplThread(), 117 resource_collection_->GetReturnResourcesCallbackForImplThread(),
114 returned_resources, 118 returned_resources,
115 &event)); 119 &event,
120 main_thread_task_runner.get()));
116 121
117 run_loop.Run(); 122 run_loop.Run();
118 } 123 }
119 EXPECT_TRUE(ReturnAndResetResourcesAvailable()); 124 EXPECT_TRUE(ReturnAndResetResourcesAvailable());
120 EXPECT_EQ(1u, returned_resources_.size()); 125 EXPECT_EQ(1u, returned_resources_.size());
121 EXPECT_EQ(444u, returned_resources_[0].id); 126 EXPECT_EQ(444u, returned_resources_[0].id);
122 EXPECT_EQ(1, returned_resources_[0].count); 127 EXPECT_EQ(1, returned_resources_[0].count);
123 returned_resources_.clear(); 128 returned_resources_.clear();
124 129
125 // The event prevents the return resources callback from being deleted. 130 // The event prevents the return resources callback from being deleted.
(...skipping 18 matching lines...) Expand all
144 EXPECT_EQ(444u, returned_resources_[0].id); 149 EXPECT_EQ(444u, returned_resources_[0].id);
145 EXPECT_EQ(1, returned_resources_[0].count); 150 EXPECT_EQ(1, returned_resources_[0].count);
146 EXPECT_TRUE(returned_resources_[0].lost); 151 EXPECT_TRUE(returned_resources_[0].lost);
147 returned_resources_.clear(); 152 returned_resources_.clear();
148 153
149 base::WaitableEvent* null_event = NULL; 154 base::WaitableEvent* null_event = NULL;
150 thread.message_loop()->PostTask(FROM_HERE, 155 thread.message_loop()->PostTask(FROM_HERE,
151 base::Bind(&ReturnResourcesOnThread, 156 base::Bind(&ReturnResourcesOnThread,
152 return_callback, 157 return_callback,
153 returned_resources, 158 returned_resources,
154 null_event)); 159 null_event,
160 main_thread_task_runner.get()));
155 161
156 thread.Stop(); 162 thread.Stop();
157 } 163 }
158 164
159 } // namespace 165 } // namespace
160 } // namespace cc 166 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/delegated_frame_resource_collection.cc ('k') | cc/layers/delegated_renderer_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698