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

Side by Side Diff: cc/trees/layer_tree_impl_unittest.cc

Issue 2030033003: Replace cc::ViewportSelectionBound with gfx::SelectionBound (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use gfx::SelectionBound Created 4 years, 6 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
OLDNEW
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 "cc/trees/layer_tree_impl.h" 5 #include "cc/trees/layer_tree_impl.h"
6 6
7 #include "cc/layers/heads_up_display_layer_impl.h" 7 #include "cc/layers/heads_up_display_layer_impl.h"
8 #include "cc/layers/layer.h" 8 #include "cc/layers/layer.h"
9 #include "cc/layers/solid_color_scrollbar_layer_impl.h" 9 #include "cc/layers/solid_color_scrollbar_layer_impl.h"
10 #include "cc/test/fake_impl_task_runner_provider.h" 10 #include "cc/test/fake_impl_task_runner_provider.h"
(...skipping 2163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 input.start.type = SELECTION_BOUND_LEFT; 2174 input.start.type = SELECTION_BOUND_LEFT;
2175 input.start.edge_top = gfx::Point(10, 10); 2175 input.start.edge_top = gfx::Point(10, 10);
2176 input.start.edge_bottom = gfx::Point(10, 20); 2176 input.start.edge_bottom = gfx::Point(10, 20);
2177 input.start.layer_id = root_layer_id; 2177 input.start.layer_id = root_layer_id;
2178 2178
2179 input.end.type = SELECTION_BOUND_RIGHT; 2179 input.end.type = SELECTION_BOUND_RIGHT;
2180 input.end.edge_top = gfx::Point(50, 10); 2180 input.end.edge_top = gfx::Point(50, 10);
2181 input.end.edge_bottom = gfx::Point(50, 30); 2181 input.end.edge_bottom = gfx::Point(50, 30);
2182 input.end.layer_id = root_layer_id; 2182 input.end.layer_id = root_layer_id;
2183 2183
2184 ViewportSelection output; 2184 Selection<gfx::SelectionBound> output;
2185 2185
2186 // Empty input bounds should produce empty output bounds. 2186 // Empty input bounds should produce empty output bounds.
2187 host_impl().active_tree()->GetViewportSelection(&output); 2187 host_impl().active_tree()->GetViewportSelection(&output);
2188 EXPECT_EQ(ViewportSelectionBound(), output.start); 2188 EXPECT_EQ(gfx::SelectionBound(), output.start);
2189 EXPECT_EQ(ViewportSelectionBound(), output.end); 2189 EXPECT_EQ(gfx::SelectionBound(), output.end);
2190 2190
2191 // Selection bounds should produce distinct left and right bounds. 2191 // Selection bounds should produce distinct left and right bounds.
2192 host_impl().active_tree()->RegisterSelection(input); 2192 host_impl().active_tree()->RegisterSelection(input);
2193 host_impl().active_tree()->GetViewportSelection(&output); 2193 host_impl().active_tree()->GetViewportSelection(&output);
2194 EXPECT_EQ(input.start.type, output.start.type); 2194 // EXPECT_EQ(input.start.type(), output.start.type());
2195 EXPECT_EQ(gfx::PointF(input.start.edge_bottom), output.start.edge_bottom); 2195 EXPECT_EQ(gfx::PointF(input.start.edge_bottom), output.start.edge_bottom());
2196 EXPECT_EQ(gfx::PointF(input.start.edge_top), output.start.edge_top); 2196 EXPECT_EQ(gfx::PointF(input.start.edge_top), output.start.edge_top());
2197 EXPECT_TRUE(output.start.visible); 2197 EXPECT_TRUE(output.start.visible());
2198 EXPECT_EQ(input.end.type, output.end.type); 2198 // EXPECT_EQ(input.end.type(), output.end.type());
2199 EXPECT_EQ(gfx::PointF(input.end.edge_bottom), output.end.edge_bottom); 2199 EXPECT_EQ(gfx::PointF(input.end.edge_bottom), output.end.edge_bottom());
2200 EXPECT_EQ(gfx::PointF(input.end.edge_top), output.end.edge_top); 2200 EXPECT_EQ(gfx::PointF(input.end.edge_top), output.end.edge_top());
2201 EXPECT_TRUE(output.end.visible); 2201 EXPECT_TRUE(output.end.visible());
2202 EXPECT_EQ(input.is_editable, output.is_editable); 2202 EXPECT_EQ(input.is_editable, output.is_editable);
2203 EXPECT_EQ(input.is_empty_text_form_control, 2203 EXPECT_EQ(input.is_empty_text_form_control,
2204 output.is_empty_text_form_control); 2204 output.is_empty_text_form_control);
2205 2205
2206 // Insertion bounds should produce identical left and right bounds. 2206 // Insertion bounds should produce identical left and right bounds.
2207 LayerSelection insertion_input; 2207 LayerSelection insertion_input;
2208 insertion_input.start.type = SELECTION_BOUND_CENTER; 2208 insertion_input.start.type = SELECTION_BOUND_CENTER;
2209 insertion_input.start.edge_top = gfx::Point(15, 10); 2209 insertion_input.start.edge_top = gfx::Point(15, 10);
2210 insertion_input.start.edge_bottom = gfx::Point(15, 30); 2210 insertion_input.start.edge_bottom = gfx::Point(15, 30);
2211 insertion_input.start.layer_id = root_layer_id; 2211 insertion_input.start.layer_id = root_layer_id;
2212 insertion_input.is_editable = true; 2212 insertion_input.is_editable = true;
2213 insertion_input.is_empty_text_form_control = true; 2213 insertion_input.is_empty_text_form_control = true;
2214 insertion_input.end = insertion_input.start; 2214 insertion_input.end = insertion_input.start;
2215 host_impl().active_tree()->RegisterSelection(insertion_input); 2215 host_impl().active_tree()->RegisterSelection(insertion_input);
2216 host_impl().active_tree()->GetViewportSelection(&output); 2216 host_impl().active_tree()->GetViewportSelection(&output);
2217 EXPECT_EQ(insertion_input.start.type, output.start.type); 2217 // EXPECT_EQ(insertion_input.start.type(), output.start.type);
2218 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_bottom), 2218 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_bottom),
2219 output.start.edge_bottom); 2219 output.start.edge_bottom());
2220 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_top), output.start.edge_top); 2220 EXPECT_EQ(gfx::PointF(insertion_input.start.edge_top),
2221 output.start.edge_top());
2221 EXPECT_EQ(insertion_input.is_editable, output.is_editable); 2222 EXPECT_EQ(insertion_input.is_editable, output.is_editable);
2222 EXPECT_EQ(insertion_input.is_empty_text_form_control, 2223 EXPECT_EQ(insertion_input.is_empty_text_form_control,
2223 output.is_empty_text_form_control); 2224 output.is_empty_text_form_control);
2224 EXPECT_TRUE(output.start.visible); 2225 EXPECT_TRUE(output.start.visible());
2225 EXPECT_EQ(output.start, output.end); 2226 EXPECT_EQ(output.start, output.end);
2226 } 2227 }
2227 2228
2228 TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) { 2229 TEST_F(LayerTreeImplTest, SelectionBoundsForPartialOccludedLayers) {
2229 int root_layer_id = 12345; 2230 int root_layer_id = 12345;
2230 int clip_layer_id = 1234; 2231 int clip_layer_id = 1234;
2231 int clipped_layer_id = 123; 2232 int clipped_layer_id = 123;
2232 std::unique_ptr<LayerImpl> root = 2233 std::unique_ptr<LayerImpl> root =
2233 LayerImpl::Create(host_impl().active_tree(), root_layer_id); 2234 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
2234 root->SetDrawsContent(true); 2235 root->SetDrawsContent(true);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2277 input.start.edge_bottom = gfx::Point(25, 30); 2278 input.start.edge_bottom = gfx::Point(25, 30);
2278 input.start.layer_id = clipped_layer_id; 2279 input.start.layer_id = clipped_layer_id;
2279 2280
2280 input.end.type = SELECTION_BOUND_RIGHT; 2281 input.end.type = SELECTION_BOUND_RIGHT;
2281 input.end.edge_top = gfx::Point(75, 10); 2282 input.end.edge_top = gfx::Point(75, 10);
2282 input.end.edge_bottom = gfx::Point(75, 30); 2283 input.end.edge_bottom = gfx::Point(75, 30);
2283 input.end.layer_id = clipped_layer_id; 2284 input.end.layer_id = clipped_layer_id;
2284 host_impl().active_tree()->RegisterSelection(input); 2285 host_impl().active_tree()->RegisterSelection(input);
2285 2286
2286 // The left bound should be occluded by the clip layer. 2287 // The left bound should be occluded by the clip layer.
2287 ViewportSelection output; 2288 Selection<gfx::SelectionBound> output;
2288 host_impl().active_tree()->GetViewportSelection(&output); 2289 host_impl().active_tree()->GetViewportSelection(&output);
2289 EXPECT_EQ(input.start.type, output.start.type); 2290 // EXPECT_EQ(input.start.type, output.start.type);
2290 auto expected_output_start_top = gfx::PointF(input.start.edge_top); 2291 auto expected_output_start_top = gfx::PointF(input.start.edge_top);
2291 auto expected_output_edge_botom = gfx::PointF(input.start.edge_bottom); 2292 auto expected_output_edge_botom = gfx::PointF(input.start.edge_bottom);
2292 expected_output_start_top.Offset(clipping_offset.x(), clipping_offset.y()); 2293 expected_output_start_top.Offset(clipping_offset.x(), clipping_offset.y());
2293 expected_output_edge_botom.Offset(clipping_offset.x(), clipping_offset.y()); 2294 expected_output_edge_botom.Offset(clipping_offset.x(), clipping_offset.y());
2294 EXPECT_EQ(expected_output_start_top, output.start.edge_top); 2295 EXPECT_EQ(expected_output_start_top, output.start.edge_top());
2295 EXPECT_EQ(expected_output_edge_botom, output.start.edge_bottom); 2296 EXPECT_EQ(expected_output_edge_botom, output.start.edge_bottom());
2296 EXPECT_TRUE(output.start.visible); 2297 EXPECT_TRUE(output.start.visible());
2297 EXPECT_EQ(input.end.type, output.end.type); 2298 // EXPECT_EQ(input.end.type, output.end.type());
2298 auto expected_output_end_top = gfx::PointF(input.end.edge_top); 2299 auto expected_output_end_top = gfx::PointF(input.end.edge_top);
2299 auto expected_output_end_bottom = gfx::PointF(input.end.edge_bottom); 2300 auto expected_output_end_bottom = gfx::PointF(input.end.edge_bottom);
2300 expected_output_end_bottom.Offset(clipping_offset.x(), clipping_offset.y()); 2301 expected_output_end_bottom.Offset(clipping_offset.x(), clipping_offset.y());
2301 expected_output_end_top.Offset(clipping_offset.x(), clipping_offset.y()); 2302 expected_output_end_top.Offset(clipping_offset.x(), clipping_offset.y());
2302 EXPECT_EQ(expected_output_end_top, output.end.edge_top); 2303 EXPECT_EQ(expected_output_end_top, output.end.edge_top());
2303 EXPECT_EQ(expected_output_end_bottom, output.end.edge_bottom); 2304 EXPECT_EQ(expected_output_end_bottom, output.end.edge_bottom());
2304 EXPECT_FALSE(output.end.visible); 2305 EXPECT_FALSE(output.end.visible());
2305 2306
2306 // Handles outside the viewport bounds should be marked invisible. 2307 // Handles outside the viewport bounds should be marked invisible.
2307 input.start.edge_top = gfx::Point(-25, 0); 2308 input.start.edge_top = gfx::Point(-25, 0);
2308 input.start.edge_bottom = gfx::Point(-25, 20); 2309 input.start.edge_bottom = gfx::Point(-25, 20);
2309 host_impl().active_tree()->RegisterSelection(input); 2310 host_impl().active_tree()->RegisterSelection(input);
2310 host_impl().active_tree()->GetViewportSelection(&output); 2311 host_impl().active_tree()->GetViewportSelection(&output);
2311 EXPECT_FALSE(output.start.visible); 2312 EXPECT_FALSE(output.start.visible());
2312 2313
2313 input.start.edge_top = gfx::Point(0, -25); 2314 input.start.edge_top = gfx::Point(0, -25);
2314 input.start.edge_bottom = gfx::Point(0, -5); 2315 input.start.edge_bottom = gfx::Point(0, -5);
2315 host_impl().active_tree()->RegisterSelection(input); 2316 host_impl().active_tree()->RegisterSelection(input);
2316 host_impl().active_tree()->GetViewportSelection(&output); 2317 host_impl().active_tree()->GetViewportSelection(&output);
2317 EXPECT_FALSE(output.start.visible); 2318 EXPECT_FALSE(output.start.visible());
2318 2319
2319 // If the handle bottom is partially visible, the handle is marked visible. 2320 // If the handle bottom is partially visible, the handle is marked visible.
2320 input.start.edge_top = gfx::Point(0, -20); 2321 input.start.edge_top = gfx::Point(0, -20);
2321 input.start.edge_bottom = gfx::Point(0, 1); 2322 input.start.edge_bottom = gfx::Point(0, 1);
2322 host_impl().active_tree()->RegisterSelection(input); 2323 host_impl().active_tree()->RegisterSelection(input);
2323 host_impl().active_tree()->GetViewportSelection(&output); 2324 host_impl().active_tree()->GetViewportSelection(&output);
2324 EXPECT_TRUE(output.start.visible); 2325 EXPECT_TRUE(output.start.visible());
2325 } 2326 }
2326 2327
2327 TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) { 2328 TEST_F(LayerTreeImplTest, SelectionBoundsForScaledLayers) {
2328 int root_layer_id = 1; 2329 int root_layer_id = 1;
2329 int sub_layer_id = 2; 2330 int sub_layer_id = 2;
2330 std::unique_ptr<LayerImpl> root = 2331 std::unique_ptr<LayerImpl> root =
2331 LayerImpl::Create(host_impl().active_tree(), root_layer_id); 2332 LayerImpl::Create(host_impl().active_tree(), root_layer_id);
2332 root->SetDrawsContent(true); 2333 root->SetDrawsContent(true);
2333 2334
2334 gfx::Transform identity_matrix; 2335 gfx::Transform identity_matrix;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 input.start.layer_id = root_layer_id; 2379 input.start.layer_id = root_layer_id;
2379 2380
2380 input.end.type = SELECTION_BOUND_RIGHT; 2381 input.end.type = SELECTION_BOUND_RIGHT;
2381 input.end.edge_top = gfx::Point(0, 0); 2382 input.end.edge_top = gfx::Point(0, 0);
2382 input.end.edge_bottom = gfx::Point(0, 20); 2383 input.end.edge_bottom = gfx::Point(0, 20);
2383 input.end.layer_id = sub_layer_id; 2384 input.end.layer_id = sub_layer_id;
2384 host_impl().active_tree()->RegisterSelection(input); 2385 host_impl().active_tree()->RegisterSelection(input);
2385 2386
2386 // The viewport bounds should be properly scaled by the page scale, but should 2387 // The viewport bounds should be properly scaled by the page scale, but should
2387 // remain in DIP coordinates. 2388 // remain in DIP coordinates.
2388 ViewportSelection output; 2389 Selection<gfx::SelectionBound> output;
2389 host_impl().active_tree()->GetViewportSelection(&output); 2390 host_impl().active_tree()->GetViewportSelection(&output);
2390 EXPECT_EQ(input.start.type, output.start.type); 2391 // EXPECT_EQ(input.start.type, output.start.type);
2391 auto expected_output_start_top = gfx::PointF(input.start.edge_top); 2392 auto expected_output_start_top = gfx::PointF(input.start.edge_top);
2392 auto expected_output_edge_bottom = gfx::PointF(input.start.edge_bottom); 2393 auto expected_output_edge_bottom = gfx::PointF(input.start.edge_bottom);
2393 expected_output_start_top.Scale(page_scale_factor); 2394 expected_output_start_top.Scale(page_scale_factor);
2394 expected_output_edge_bottom.Scale(page_scale_factor); 2395 expected_output_edge_bottom.Scale(page_scale_factor);
2395 EXPECT_EQ(expected_output_start_top, output.start.edge_top); 2396 EXPECT_EQ(expected_output_start_top, output.start.edge_top());
2396 EXPECT_EQ(expected_output_edge_bottom, output.start.edge_bottom); 2397 EXPECT_EQ(expected_output_edge_bottom, output.start.edge_bottom());
2397 EXPECT_TRUE(output.start.visible); 2398 EXPECT_TRUE(output.start.visible());
2398 EXPECT_EQ(input.end.type, output.end.type); 2399 // EXPECT_EQ(input.end.type, output.end.type);
2399 2400
2400 auto expected_output_end_top = gfx::PointF(input.end.edge_top); 2401 auto expected_output_end_top = gfx::PointF(input.end.edge_top);
2401 auto expected_output_end_bottom = gfx::PointF(input.end.edge_bottom); 2402 auto expected_output_end_bottom = gfx::PointF(input.end.edge_bottom);
2402 expected_output_end_top.Offset(sub_layer_offset.x(), sub_layer_offset.y()); 2403 expected_output_end_top.Offset(sub_layer_offset.x(), sub_layer_offset.y());
2403 expected_output_end_bottom.Offset(sub_layer_offset.x(), sub_layer_offset.y()); 2404 expected_output_end_bottom.Offset(sub_layer_offset.x(), sub_layer_offset.y());
2404 expected_output_end_top.Scale(page_scale_factor); 2405 expected_output_end_top.Scale(page_scale_factor);
2405 expected_output_end_bottom.Scale(page_scale_factor); 2406 expected_output_end_bottom.Scale(page_scale_factor);
2406 EXPECT_EQ(expected_output_end_top, output.end.edge_top); 2407 EXPECT_EQ(expected_output_end_top, output.end.edge_top());
2407 EXPECT_EQ(expected_output_end_bottom, output.end.edge_bottom); 2408 EXPECT_EQ(expected_output_end_bottom, output.end.edge_bottom());
2408 EXPECT_TRUE(output.end.visible); 2409 EXPECT_TRUE(output.end.visible());
2409 } 2410 }
2410 2411
2411 TEST_F(LayerTreeImplTest, SelectionBoundsWithLargeTransforms) { 2412 TEST_F(LayerTreeImplTest, SelectionBoundsWithLargeTransforms) {
2412 int root_id = 1; 2413 int root_id = 1;
2413 int child_id = 2; 2414 int child_id = 2;
2414 int grand_child_id = 3; 2415 int grand_child_id = 3;
2415 2416
2416 std::unique_ptr<LayerImpl> root = 2417 std::unique_ptr<LayerImpl> root =
2417 LayerImpl::Create(host_impl().active_tree(), root_id); 2418 LayerImpl::Create(host_impl().active_tree(), root_id);
2418 gfx::Size bounds(100, 100); 2419 gfx::Size bounds(100, 100);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 input.start.edge_bottom = gfx::Point(10, 20); 2456 input.start.edge_bottom = gfx::Point(10, 20);
2456 input.start.layer_id = grand_child_id; 2457 input.start.layer_id = grand_child_id;
2457 2458
2458 input.end.type = SELECTION_BOUND_RIGHT; 2459 input.end.type = SELECTION_BOUND_RIGHT;
2459 input.end.edge_top = gfx::Point(50, 10); 2460 input.end.edge_top = gfx::Point(50, 10);
2460 input.end.edge_bottom = gfx::Point(50, 30); 2461 input.end.edge_bottom = gfx::Point(50, 30);
2461 input.end.layer_id = grand_child_id; 2462 input.end.layer_id = grand_child_id;
2462 2463
2463 host_impl().active_tree()->RegisterSelection(input); 2464 host_impl().active_tree()->RegisterSelection(input);
2464 2465
2465 ViewportSelection output; 2466 Selection<gfx::SelectionBound> output;
2466 host_impl().active_tree()->GetViewportSelection(&output); 2467 host_impl().active_tree()->GetViewportSelection(&output);
2467 2468
2468 // edge_bottom and edge_top aren't allowed to have NaNs, so the selection 2469 // edge_bottom and edge_top aren't allowed to have NaNs, so the selection
2469 // should be empty. 2470 // should be empty.
2470 EXPECT_EQ(ViewportSelectionBound(), output.start); 2471 EXPECT_EQ(gfx::SelectionBound(), output.start);
2471 EXPECT_EQ(ViewportSelectionBound(), output.end); 2472 EXPECT_EQ(gfx::SelectionBound(), output.end);
2472 } 2473 }
2473 2474
2474 TEST_F(LayerTreeImplTest, NumLayersTestOne) { 2475 TEST_F(LayerTreeImplTest, NumLayersTestOne) {
2475 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers()); 2476 EXPECT_EQ(0u, host_impl().active_tree()->NumLayers());
2476 std::unique_ptr<LayerImpl> root = 2477 std::unique_ptr<LayerImpl> root =
2477 LayerImpl::Create(host_impl().active_tree(), 1); 2478 LayerImpl::Create(host_impl().active_tree(), 1);
2478 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers()); 2479 EXPECT_EQ(1u, host_impl().active_tree()->NumLayers());
2479 } 2480 }
2480 2481
2481 TEST_F(LayerTreeImplTest, NumLayersSmallTree) { 2482 TEST_F(LayerTreeImplTest, NumLayersSmallTree) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 gfx::PointF test_point = gfx::PointF(1.f, 1.f); 2544 gfx::PointF test_point = gfx::PointF(1.f, 1.f);
2544 LayerImpl* result_layer = 2545 LayerImpl* result_layer =
2545 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point); 2546 host_impl().active_tree()->FindLayerThatIsHitByPoint(test_point);
2546 2547
2547 CHECK(result_layer); 2548 CHECK(result_layer);
2548 EXPECT_EQ(2, result_layer->id()); 2549 EXPECT_EQ(2, result_layer->id());
2549 } 2550 }
2550 2551
2551 } // namespace 2552 } // namespace
2552 } // namespace cc 2553 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698