OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 TEST_F(ResourceManagerTest, PreloadEnsureResource) { | 134 TEST_F(ResourceManagerTest, PreloadEnsureResource) { |
135 const cc::UIResourceId kResourceId = 99; | 135 const cc::UIResourceId kResourceId = 99; |
136 PreloadResource(kTestResourceType); | 136 PreloadResource(kTestResourceType); |
137 EXPECT_CALL(ui_resource_manager_, CreateUIResource(_)) | 137 EXPECT_CALL(ui_resource_manager_, CreateUIResource(_)) |
138 .WillOnce(Return(kResourceId)) | 138 .WillOnce(Return(kResourceId)) |
139 .RetiresOnSaturation(); | 139 .RetiresOnSaturation(); |
140 SetResourceAsLoaded(kTestResourceType); | 140 SetResourceAsLoaded(kTestResourceType); |
141 EXPECT_EQ(kResourceId, GetUIResourceId(kTestResourceType)); | 141 EXPECT_EQ(kResourceId, GetUIResourceId(kTestResourceType)); |
142 } | 142 } |
143 | 143 |
144 TEST_F(ResourceManagerTest, ProcessCrushedSpriteFrameRects) { | |
145 const size_t kNumFrames = 3; | |
146 | |
147 // Create input | |
148 std::vector<int> frame0 = {35, 30, 38, 165, 18, 12, 0, 70, 0, 146, 72, 2}; | |
149 std::vector<int> frame1 = {}; | |
150 std::vector<int> frame2 = {0, 0, 73, 0, 72, 72}; | |
151 std::vector<std::vector<int>> frame_rects_vector; | |
152 frame_rects_vector.push_back(frame0); | |
153 frame_rects_vector.push_back(frame1); | |
154 frame_rects_vector.push_back(frame2); | |
155 | |
156 // Create expected output | |
157 CrushedSpriteResource::SrcDstRects expected_rects(kNumFrames); | |
158 gfx::Rect frame0_rect0_src(38, 165, 18, 12); | |
159 gfx::Rect frame0_rect0_dst(35, 30, 18, 12); | |
160 gfx::Rect frame0_rect1_src(0, 146, 72, 2); | |
161 gfx::Rect frame0_rect1_dst(0, 70, 72, 2); | |
162 gfx::Rect frame2_rect0_src(73, 0, 72, 72); | |
163 gfx::Rect frame2_rect0_dst(0, 0, 72, 72); | |
164 expected_rects[0].push_back( | |
165 std::pair<gfx::Rect, gfx::Rect>(frame0_rect0_src, frame0_rect0_dst)); | |
166 expected_rects[0].push_back( | |
167 std::pair<gfx::Rect, gfx::Rect>(frame0_rect1_src, frame0_rect1_dst)); | |
168 expected_rects[2].push_back( | |
169 std::pair<gfx::Rect, gfx::Rect>(frame2_rect0_src, frame2_rect0_dst)); | |
170 | |
171 // Check actual against expected | |
172 CrushedSpriteResource::SrcDstRects actual_rects = | |
173 resource_manager_.ProcessCrushedSpriteFrameRects(frame_rects_vector); | |
174 EXPECT_EQ(kNumFrames, actual_rects.size()); | |
175 for (size_t i = 0; i < kNumFrames; i++) { | |
176 EXPECT_EQ(expected_rects[i].size(), actual_rects[i].size()); | |
177 for (size_t j = 0; j < actual_rects[i].size(); j++) { | |
178 EXPECT_EQ(expected_rects[i][j], actual_rects[i][j]); | |
179 } | |
180 } | |
181 } | |
182 | |
183 TEST_F(ResourceManagerTest, TestOnMemoryDumpEmitsData) { | 144 TEST_F(ResourceManagerTest, TestOnMemoryDumpEmitsData) { |
184 SetResourceAsLoaded(kTestResourceType); | 145 SetResourceAsLoaded(kTestResourceType); |
185 | 146 |
186 base::trace_event::MemoryDumpArgs dump_args = { | 147 base::trace_event::MemoryDumpArgs dump_args = { |
187 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; | 148 base::trace_event::MemoryDumpLevelOfDetail::DETAILED}; |
188 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump = | 149 std::unique_ptr<base::trace_event::ProcessMemoryDump> process_memory_dump = |
189 base::MakeUnique<base::trace_event::ProcessMemoryDump>(nullptr, | 150 base::MakeUnique<base::trace_event::ProcessMemoryDump>(nullptr, |
190 dump_args); | 151 dump_args); |
191 resource_manager_.OnMemoryDump(dump_args, process_memory_dump.get()); | 152 resource_manager_.OnMemoryDump(dump_args, process_memory_dump.get()); |
192 const auto& allocator_dumps = process_memory_dump->allocator_dumps(); | 153 const auto& allocator_dumps = process_memory_dump->allocator_dumps(); |
193 const char* system_allocator_pool_name = | 154 const char* system_allocator_pool_name = |
194 base::trace_event::MemoryDumpManager::GetInstance() | 155 base::trace_event::MemoryDumpManager::GetInstance() |
195 ->system_allocator_pool_name(); | 156 ->system_allocator_pool_name(); |
196 size_t expected_dump_count = system_allocator_pool_name ? 2 : 1; | 157 size_t expected_dump_count = system_allocator_pool_name ? 2 : 1; |
197 EXPECT_EQ(expected_dump_count, allocator_dumps.size()); | 158 EXPECT_EQ(expected_dump_count, allocator_dumps.size()); |
198 for (const auto& dump : allocator_dumps) { | 159 for (const auto& dump : allocator_dumps) { |
199 ASSERT_TRUE(dump.first.find("ui/resource_manager") == 0 || | 160 ASSERT_TRUE(dump.first.find("ui/resource_manager") == 0 || |
200 dump.first.find(system_allocator_pool_name) == 0); | 161 dump.first.find(system_allocator_pool_name) == 0); |
201 } | 162 } |
202 } | 163 } |
203 | 164 |
204 } // namespace ui | 165 } // namespace ui |
OLD | NEW |