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

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: Help gn deal with it. 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
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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // Start with one ref. 72 // Start with one ref.
72 EXPECT_TRUE(resource_collection_->HasOneRef()); 73 EXPECT_TRUE(resource_collection_->HasOneRef());
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(
82 const ReturnedResourceArray& resources, 83 ReturnCallback callback,
83 base::WaitableEvent* event) { 84 const ReturnedResourceArray& resources,
84 callback.Run(resources); 85 base::WaitableEvent* event,
86 scoped_refptr<BlockingTaskRunner> main_thread_task_runner) {
87 callback.Run(resources, main_thread_task_runner);
85 if (event) 88 if (event)
86 event->Wait(); 89 event->Wait();
87 } 90 }
88 91
89 // Tests that the ReturnCallback can run safely on threads even after the 92 // Tests that the ReturnCallback can run safely on threads even after the
90 // last references to the collection were dropped. 93 // last references to the collection were dropped.
91 // Flaky: crbug.com/313441 94 // Flaky: crbug.com/313441
92 TEST_F(DelegatedFrameResourceCollectionTest, Thread) { 95 TEST_F(DelegatedFrameResourceCollectionTest, Thread) {
93 base::Thread thread("test thread"); 96 base::Thread thread("test thread");
94 thread.Start(); 97 thread.Start();
98 scoped_refptr<BlockingTaskRunner> main_thread_task_runner(
99 BlockingTaskRunner::Create(base::MessageLoopProxy::current()));
95 100
96 TransferableResourceArray resources = CreateResourceArray(); 101 TransferableResourceArray resources = CreateResourceArray();
97 resource_collection_->ReceivedResources(resources); 102 resource_collection_->ReceivedResources(resources);
98 resource_collection_->RefResources(resources); 103 resource_collection_->RefResources(resources);
99 104
100 ReturnedResourceArray returned_resources; 105 ReturnedResourceArray returned_resources;
101 TransferableResource::ReturnResources(resources, &returned_resources); 106 TransferableResource::ReturnResources(resources, &returned_resources);
102 107
103 base::WaitableEvent event(false, false); 108 base::WaitableEvent event(false, false);
104 109
105 { 110 {
106 base::RunLoop run_loop; 111 base::RunLoop run_loop;
107 resources_available_closure_ = run_loop.QuitClosure(); 112 resources_available_closure_ = run_loop.QuitClosure();
108 113
109 thread.message_loop()->PostTask( 114 thread.message_loop()->PostTask(
110 FROM_HERE, 115 FROM_HERE,
111 base::Bind( 116 base::Bind(
112 &ReturnResourcesOnThread, 117 &ReturnResourcesOnThread,
113 resource_collection_->GetReturnResourcesCallbackForImplThread(), 118 resource_collection_->GetReturnResourcesCallbackForImplThread(),
114 returned_resources, 119 returned_resources,
115 &event)); 120 &event,
121 main_thread_task_runner));
116 122
117 run_loop.Run(); 123 run_loop.Run();
118 } 124 }
119 EXPECT_TRUE(ReturnAndResetResourcesAvailable()); 125 EXPECT_TRUE(ReturnAndResetResourcesAvailable());
120 EXPECT_EQ(1u, returned_resources_.size()); 126 EXPECT_EQ(1u, returned_resources_.size());
121 EXPECT_EQ(444u, returned_resources_[0].id); 127 EXPECT_EQ(444u, returned_resources_[0].id);
122 EXPECT_EQ(1, returned_resources_[0].count); 128 EXPECT_EQ(1, returned_resources_[0].count);
123 returned_resources_.clear(); 129 returned_resources_.clear();
124 130
125 // The event prevents the return resources callback from being deleted. 131 // The event prevents the return resources callback from being deleted.
(...skipping 18 matching lines...) Expand all
144 EXPECT_EQ(444u, returned_resources_[0].id); 150 EXPECT_EQ(444u, returned_resources_[0].id);
145 EXPECT_EQ(1, returned_resources_[0].count); 151 EXPECT_EQ(1, returned_resources_[0].count);
146 EXPECT_TRUE(returned_resources_[0].lost); 152 EXPECT_TRUE(returned_resources_[0].lost);
147 returned_resources_.clear(); 153 returned_resources_.clear();
148 154
149 base::WaitableEvent* null_event = NULL; 155 base::WaitableEvent* null_event = NULL;
150 thread.message_loop()->PostTask(FROM_HERE, 156 thread.message_loop()->PostTask(FROM_HERE,
151 base::Bind(&ReturnResourcesOnThread, 157 base::Bind(&ReturnResourcesOnThread,
152 return_callback, 158 return_callback,
153 returned_resources, 159 returned_resources,
154 null_event)); 160 null_event,
161 main_thread_task_runner));
155 162
156 thread.Stop(); 163 thread.Stop();
157 } 164 }
158 165
159 } // namespace 166 } // namespace
160 } // namespace cc 167 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698