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

Side by Side Diff: services/ui/ws/window_tree_unittest.cc

Issue 2667073002: mash: changes can_accept_events to an enum (Closed)
Patch Set: merge Created 3 years, 10 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
« no previous file with comments | « services/ui/ws/window_tree.cc ('k') | ui/aura/mus/window_port_mus.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 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 "services/ui/ws/window_tree.h" 5 #include "services/ui/ws/window_tree.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties())); 216 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
217 ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id); 217 ServerWindow* embed_window = wm_tree()->GetWindowByClientId(embed_window_id);
218 ASSERT_TRUE(embed_window); 218 ASSERT_TRUE(embed_window);
219 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true)); 219 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true));
220 ASSERT_TRUE(FirstRoot(wm_tree())); 220 ASSERT_TRUE(FirstRoot(wm_tree()));
221 const ClientWindowId wm_root_id = FirstRootId(wm_tree()); 221 const ClientWindowId wm_root_id = FirstRootId(wm_tree());
222 EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, embed_window_id)); 222 EXPECT_TRUE(wm_tree()->AddWindow(wm_root_id, embed_window_id));
223 ServerWindow* wm_root = FirstRoot(wm_tree()); 223 ServerWindow* wm_root = FirstRoot(wm_tree());
224 ASSERT_TRUE(wm_root); 224 ASSERT_TRUE(wm_root);
225 wm_root->SetBounds(gfx::Rect(0, 0, 100, 100)); 225 wm_root->SetBounds(gfx::Rect(0, 0, 100, 100));
226 EnableHitTest(wm_root); 226 // This tests expects |wm_root| to be a possible target.
227 wm_root->set_event_targeting_policy(
228 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
227 display()->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100)); 229 display()->root_window()->SetBounds(gfx::Rect(0, 0, 100, 100));
228 mojom::WindowTreeClientPtr client; 230 mojom::WindowTreeClientPtr client;
229 mojom::WindowTreeClientRequest client_request(&client); 231 mojom::WindowTreeClientRequest client_request(&client);
230 wm_client()->Bind(std::move(client_request)); 232 wm_client()->Bind(std::move(client_request));
231 const uint32_t embed_flags = 0; 233 const uint32_t embed_flags = 0;
232 wm_tree()->Embed(embed_window_id, std::move(client), embed_flags); 234 wm_tree()->Embed(embed_window_id, std::move(client), embed_flags);
233 WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window); 235 WindowTree* tree1 = window_server()->GetTreeWithRoot(embed_window);
234 ASSERT_TRUE(tree1 != nullptr); 236 ASSERT_TRUE(tree1 != nullptr);
235 ASSERT_NE(tree1, wm_tree()); 237 ASSERT_NE(tree1, wm_tree());
236 238
237 embed_window->SetBounds(gfx::Rect(0, 0, 50, 50)); 239 embed_window->SetBounds(gfx::Rect(0, 0, 50, 50));
238 240
239 const ClientWindowId child1_id(BuildClientWindowId(tree1, 1)); 241 const ClientWindowId child1_id(BuildClientWindowId(tree1, 1));
240 EXPECT_TRUE(tree1->NewWindow(child1_id, ServerWindow::Properties())); 242 EXPECT_TRUE(tree1->NewWindow(child1_id, ServerWindow::Properties()));
241 EXPECT_TRUE(tree1->AddWindow(ClientWindowIdForWindow(tree1, embed_window), 243 EXPECT_TRUE(tree1->AddWindow(ClientWindowIdForWindow(tree1, embed_window),
242 child1_id)); 244 child1_id));
243 ServerWindow* child1 = tree1->GetWindowByClientId(child1_id); 245 ServerWindow* child1 = tree1->GetWindowByClientId(child1_id);
244 ASSERT_TRUE(child1); 246 ASSERT_TRUE(child1);
245 child1->SetVisible(true); 247 child1->SetVisible(true);
246 child1->SetBounds(gfx::Rect(20, 20, 20, 20)); 248 child1->SetBounds(gfx::Rect(20, 20, 20, 20));
247 EnableHitTest(child1);
248 249
249 TestWindowTreeClient* tree1_client = last_window_tree_client(); 250 TestWindowTreeClient* tree1_client = last_window_tree_client();
250 tree1_client->tracker()->changes()->clear(); 251 tree1_client->tracker()->changes()->clear();
251 wm_client()->tracker()->changes()->clear(); 252 wm_client()->tracker()->changes()->clear();
252 253
253 // Focus should not go to |child1| yet, since the parent still doesn't allow 254 // Focus should not go to |child1| yet, since the parent still doesn't allow
254 // active children. 255 // active children.
255 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22)); 256 DispatchEventAndAckImmediately(CreatePointerDownEvent(21, 22));
256 Display* display1 = tree1->GetDisplay(embed_window); 257 Display* display1 = tree1->GetDisplay(embed_window);
257 EXPECT_EQ(nullptr, display1->GetFocusedWindow()); 258 EXPECT_EQ(nullptr, display1->GetFocusedWindow());
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 575
575 // Create a second window right over the first. 576 // Create a second window right over the first.
576 const ClientWindowId embed_window_id(FirstRootId(tree)); 577 const ClientWindowId embed_window_id(FirstRootId(tree));
577 const ClientWindowId child2_id(BuildClientWindowId(tree, 2)); 578 const ClientWindowId child2_id(BuildClientWindowId(tree, 2));
578 EXPECT_TRUE(tree->NewWindow(child2_id, ServerWindow::Properties())); 579 EXPECT_TRUE(tree->NewWindow(child2_id, ServerWindow::Properties()));
579 ServerWindow* child2 = tree->GetWindowByClientId(child2_id); 580 ServerWindow* child2 = tree->GetWindowByClientId(child2_id);
580 ASSERT_TRUE(child2); 581 ASSERT_TRUE(child2);
581 EXPECT_TRUE(tree->AddWindow(embed_window_id, child2_id)); 582 EXPECT_TRUE(tree->AddWindow(embed_window_id, child2_id));
582 child2->SetVisible(true); 583 child2->SetVisible(true);
583 child2->SetBounds(gfx::Rect(20, 20, 20, 20)); 584 child2->SetBounds(gfx::Rect(20, 20, 20, 20));
584 EnableHitTest(child2);
585 585
586 // Give each window a different cursor. 586 // Give each window a different cursor.
587 window1->SetPredefinedCursor(mojom::Cursor::IBEAM); 587 window1->SetPredefinedCursor(mojom::Cursor::IBEAM);
588 child2->SetPredefinedCursor(mojom::Cursor::HAND); 588 child2->SetPredefinedCursor(mojom::Cursor::HAND);
589 589
590 // We expect window2 to be over window1 now. 590 // We expect window2 to be over window1 now.
591 DispatchEventAndAckImmediately(CreateMouseMoveEvent(22, 22)); 591 DispatchEventAndAckImmediately(CreateMouseMoveEvent(22, 22));
592 EXPECT_EQ(mojom::Cursor::HAND, cursor_id()); 592 EXPECT_EQ(mojom::Cursor::HAND, cursor_id());
593 593
594 // But when we put window2 at the bottom, we should adapt window1's cursor. 594 // But when we put window2 at the bottom, we should adapt window1's cursor.
595 child2->parent()->StackChildAtBottom(child2); 595 child2->parent()->StackChildAtBottom(child2);
596 EXPECT_EQ(mojom::Cursor::IBEAM, cursor_id()); 596 EXPECT_EQ(mojom::Cursor::IBEAM, cursor_id());
597 } 597 }
598 598
599 TEST_F(WindowTreeTest, EventAck) { 599 TEST_F(WindowTreeTest, EventAck) {
600 const ClientWindowId embed_window_id = BuildClientWindowId(wm_tree(), 1); 600 const ClientWindowId embed_window_id = BuildClientWindowId(wm_tree(), 1);
601 EXPECT_TRUE( 601 EXPECT_TRUE(
602 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties())); 602 wm_tree()->NewWindow(embed_window_id, ServerWindow::Properties()));
603 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true)); 603 EXPECT_TRUE(wm_tree()->SetWindowVisibility(embed_window_id, true));
604 ASSERT_TRUE(FirstRoot(wm_tree())); 604 ASSERT_TRUE(FirstRoot(wm_tree()));
605 EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id)); 605 EXPECT_TRUE(wm_tree()->AddWindow(FirstRootId(wm_tree()), embed_window_id));
606 ASSERT_EQ(1u, display()->root_window()->children().size()); 606 ASSERT_EQ(1u, display()->root_window()->children().size());
607 ServerWindow* wm_root = FirstRoot(wm_tree()); 607 ServerWindow* wm_root = FirstRoot(wm_tree());
608 ASSERT_TRUE(wm_root); 608 ASSERT_TRUE(wm_root);
609 wm_root->SetBounds(gfx::Rect(0, 0, 100, 100)); 609 wm_root->SetBounds(gfx::Rect(0, 0, 100, 100));
610 EnableHitTest(wm_root); 610 // This tests expects |wm_root| to be a possible target.
611 wm_root->set_event_targeting_policy(
612 mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS);
611 613
612 wm_client()->tracker()->changes()->clear(); 614 wm_client()->tracker()->changes()->clear();
613 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); 615 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22));
614 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size()); 616 ASSERT_EQ(1u, wm_client()->tracker()->changes()->size());
615 EXPECT_EQ("InputEvent window=0,3 event_action=17", 617 EXPECT_EQ("InputEvent window=0,3 event_action=17",
616 ChangesToDescription1(*wm_client()->tracker()->changes())[0]); 618 ChangesToDescription1(*wm_client()->tracker()->changes())[0]);
617 wm_client()->tracker()->changes()->clear(); 619 wm_client()->tracker()->changes()->clear();
618 620
619 // Send another event. This event shouldn't reach the client. 621 // Send another event. This event shouldn't reach the client.
620 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22)); 622 DispatchEventWithoutAck(CreateMouseMoveEvent(21, 22));
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
1298 EXPECT_EQ("ChangeCompleted id=8 sucess=false", 1300 EXPECT_EQ("ChangeCompleted id=8 sucess=false",
1299 SingleChangeToDescription(*embed_client->tracker()->changes())); 1301 SingleChangeToDescription(*embed_client->tracker()->changes()));
1300 } 1302 }
1301 1303
1302 TEST_F(WindowTreeTest, SetCanAcceptEvents) { 1304 TEST_F(WindowTreeTest, SetCanAcceptEvents) {
1303 TestWindowTreeClient* embed_client = nullptr; 1305 TestWindowTreeClient* embed_client = nullptr;
1304 WindowTree* tree = nullptr; 1306 WindowTree* tree = nullptr;
1305 ServerWindow* window = nullptr; 1307 ServerWindow* window = nullptr;
1306 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window)); 1308 EXPECT_NO_FATAL_FAILURE(SetupEventTargeting(&embed_client, &tree, &window));
1307 1309
1308 EXPECT_TRUE(window->can_accept_events()); 1310 EXPECT_EQ(mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS,
1309 WindowTreeTestApi(tree).SetCanAcceptEvents( 1311 window->event_targeting_policy());
1310 ClientWindowIdForWindow(tree, window).id, false); 1312 WindowTreeTestApi(tree).SetEventTargetingPolicy(
1311 EXPECT_FALSE(window->can_accept_events()); 1313 ClientWindowIdForWindow(tree, window).id,
1314 mojom::EventTargetingPolicy::NONE);
1315 EXPECT_EQ(mojom::EventTargetingPolicy::NONE,
1316 window->event_targeting_policy());
1312 } 1317 }
1313 1318
1314 // Verifies wm observers capture changes in client. 1319 // Verifies wm observers capture changes in client.
1315 TEST_F(WindowTreeTest, CaptureNotifiesWm) { 1320 TEST_F(WindowTreeTest, CaptureNotifiesWm) {
1316 ServerWindow* window = window_event_targeting_helper_.CreatePrimaryTree( 1321 ServerWindow* window = window_event_targeting_helper_.CreatePrimaryTree(
1317 gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 50, 50)); 1322 gfx::Rect(0, 0, 100, 100), gfx::Rect(0, 0, 50, 50));
1318 TestWindowTreeClient* embed_client = last_window_tree_client(); 1323 TestWindowTreeClient* embed_client = last_window_tree_client();
1319 WindowTree* owning_tree = 1324 WindowTree* owning_tree =
1320 window_server()->GetTreeWithId(window->id().client_id); 1325 window_server()->GetTreeWithId(window->id().client_id);
1321 WindowTree* embed_tree = window_server()->GetTreeWithRoot(window); 1326 WindowTree* embed_tree = window_server()->GetTreeWithRoot(window);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 client->tracker()->changes()->clear(); 1387 client->tracker()->changes()->clear();
1383 } 1388 }
1384 1389
1385 // Client should not have got any messages after shutdown. 1390 // Client should not have got any messages after shutdown.
1386 EXPECT_TRUE(client->tracker()->changes()->empty()); 1391 EXPECT_TRUE(client->tracker()->changes()->empty());
1387 } 1392 }
1388 1393
1389 } // namespace test 1394 } // namespace test
1390 } // namespace ws 1395 } // namespace ws
1391 } // namespace ui 1396 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/ws/window_tree.cc ('k') | ui/aura/mus/window_port_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698