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

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2626013005: Change CaptureSynchronizer and PointerWatcherEventRouter to support multiple CaptureClients. (Closed)
Patch Set: fix leak in test 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 | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/test/aura_test_helper.cc » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/aura/mus/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "mojo/public/cpp/bindings/map.h" 14 #include "mojo/public/cpp/bindings/map.h"
15 #include "services/ui/public/cpp/property_type_converters.h" 15 #include "services/ui/public/cpp/property_type_converters.h"
16 #include "services/ui/public/interfaces/window_manager.mojom.h" 16 #include "services/ui/public/interfaces/window_manager.mojom.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/aura/client/aura_constants.h" 18 #include "ui/aura/client/aura_constants.h"
19 #include "ui/aura/client/capture_client.h" 19 #include "ui/aura/client/capture_client.h"
20 #include "ui/aura/client/capture_client_observer.h" 20 #include "ui/aura/client/capture_client_observer.h"
21 #include "ui/aura/client/default_capture_client.h"
21 #include "ui/aura/client/focus_client.h" 22 #include "ui/aura/client/focus_client.h"
22 #include "ui/aura/client/transient_window_client.h" 23 #include "ui/aura/client/transient_window_client.h"
24 #include "ui/aura/mus/capture_synchronizer.h"
23 #include "ui/aura/mus/property_converter.h" 25 #include "ui/aura/mus/property_converter.h"
24 #include "ui/aura/mus/window_mus.h" 26 #include "ui/aura/mus/window_mus.h"
25 #include "ui/aura/mus/window_tree_client_delegate.h" 27 #include "ui/aura/mus/window_tree_client_delegate.h"
26 #include "ui/aura/mus/window_tree_client_observer.h" 28 #include "ui/aura/mus/window_tree_client_observer.h"
27 #include "ui/aura/mus/window_tree_host_mus.h" 29 #include "ui/aura/mus/window_tree_host_mus.h"
28 #include "ui/aura/test/aura_mus_test_base.h" 30 #include "ui/aura/test/aura_mus_test_base.h"
29 #include "ui/aura/test/mus/test_window_tree.h" 31 #include "ui/aura/test/mus/test_window_tree.h"
30 #include "ui/aura/test/mus/window_tree_client_private.h" 32 #include "ui/aura/test/mus/window_tree_client_private.h"
31 #include "ui/aura/test/test_window_delegate.h" 33 #include "ui/aura/test/test_window_delegate.h"
32 #include "ui/aura/window.h" 34 #include "ui/aura/window.h"
(...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 capture_recorder.reset_capture_captured_count(); 1359 capture_recorder.reset_capture_captured_count();
1358 1360
1359 // Changes originating from server should notify observers too. 1361 // Changes originating from server should notify observers too.
1360 window_tree_client()->OnCaptureChanged(server_id(&child2), 0); 1362 window_tree_client()->OnCaptureChanged(server_id(&child2), 0);
1361 EXPECT_EQ(1, capture_recorder.capture_changed_count()); 1363 EXPECT_EQ(1, capture_recorder.capture_changed_count());
1362 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id()); 1364 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id());
1363 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id()); 1365 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id());
1364 capture_recorder.reset_capture_captured_count(); 1366 capture_recorder.reset_capture_captured_count();
1365 } 1367 }
1366 1368
1369 TEST_F(WindowTreeClientClientTest, TwoWindowTreesRequestCapture) {
1370 // Creating a WindowTreeHost so we can have two root windows: top_level
1371 // and root_window().
1372 std::unique_ptr<WindowTreeHostMus> window_tree_host =
1373 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl());
1374 window_tree_host->InitHost();
1375 Window* top_level = window_tree_host->window();
1376 std::unique_ptr<client::DefaultCaptureClient> capture_client(
1377 base::MakeUnique<client::DefaultCaptureClient>());
1378 client::SetCaptureClient(top_level, capture_client.get());
1379 window_tree_client_impl()->capture_synchronizer()->AttachToCaptureClient(
1380 capture_client.get());
1381 EXPECT_NE(server_id(top_level), server_id(root_window()));
1382
1383 // Ack the request to the windowtree to create the new window.
1384 uint32_t change_id;
1385 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
1386 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
1387 EXPECT_EQ(window_tree()->window_id(), server_id(top_level));
1388
1389 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
1390 data->window_id = server_id(top_level);
1391 data->visible = true;
1392 const int64_t display_id = 1;
1393 window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
1394 display_id, true);
1395 EXPECT_EQ(
1396 0u, window_tree()->GetChangeCountForType(WindowTreeChangeType::VISIBLE));
1397 EXPECT_TRUE(top_level->TargetVisibility());
1398
1399 std::unique_ptr<CaptureRecorder> capture_recorder1(
1400 base::MakeUnique<CaptureRecorder>(root_window()));
1401 std::unique_ptr<CaptureRecorder> capture_recorder2(
1402 base::MakeUnique<CaptureRecorder>(top_level));
1403 EXPECT_NE(client::GetCaptureClient(root_window()),
1404 client::GetCaptureClient(top_level));
1405
1406 EXPECT_EQ(0, capture_recorder1->capture_changed_count());
1407 EXPECT_EQ(0, capture_recorder2->capture_changed_count());
1408 // Give capture to top_level and ensure everyone is notified correctly.
1409 top_level->SetCapture();
1410 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
1411 WindowTreeChangeType::CAPTURE, true));
1412 EXPECT_EQ(0, capture_recorder1->capture_changed_count());
1413 EXPECT_EQ(1, capture_recorder2->capture_changed_count());
1414 EXPECT_EQ(top_level->id(),
1415 capture_recorder2->last_gained_capture_window_id());
1416 EXPECT_EQ(0, capture_recorder2->last_lost_capture_window_id());
1417 top_level->ReleaseCapture();
1418 capture_recorder1->reset_capture_captured_count();
1419 capture_recorder2->reset_capture_captured_count();
1420
1421 // Release capture of top_level shouldn't affect the capture of root_window().
1422 top_level->SetCapture();
1423 root_window()->SetCapture();
1424 top_level->ReleaseCapture();
1425 EXPECT_EQ(1, capture_recorder1->capture_changed_count());
1426 EXPECT_EQ(2, capture_recorder2->capture_changed_count());
1427 EXPECT_EQ(root_window()->id(),
1428 capture_recorder1->last_gained_capture_window_id());
1429 EXPECT_EQ(0, capture_recorder1->last_lost_capture_window_id());
1430 EXPECT_EQ(0, capture_recorder2->last_gained_capture_window_id());
1431 EXPECT_EQ(top_level->id(), capture_recorder2->last_lost_capture_window_id());
1432
1433 capture_recorder1->reset_capture_captured_count();
1434 capture_recorder2->reset_capture_captured_count();
1435 capture_recorder1.reset();
1436 capture_recorder2.reset();
1437 window_tree_host.reset();
1438 capture_client.reset();
1439 }
1440
1367 TEST_F(WindowTreeClientClientTest, ModalFail) { 1441 TEST_F(WindowTreeClientClientTest, ModalFail) {
1368 Window window(nullptr); 1442 Window window(nullptr);
1369 window.Init(ui::LAYER_NOT_DRAWN); 1443 window.Init(ui::LAYER_NOT_DRAWN);
1370 window.SetProperty(client::kModalKey, ui::MODAL_TYPE_WINDOW); 1444 window.SetProperty(client::kModalKey, ui::MODAL_TYPE_WINDOW);
1371 // Make sure server was told about it, and have the server say it failed. 1445 // Make sure server was told about it, and have the server say it failed.
1372 ASSERT_TRUE( 1446 ASSERT_TRUE(
1373 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, false)); 1447 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, false));
1374 // Type should be back to MODAL_TYPE_NONE as the server didn't accept the 1448 // Type should be back to MODAL_TYPE_NONE as the server didn't accept the
1375 // change. 1449 // change.
1376 EXPECT_EQ(ui::MODAL_TYPE_NONE, window.GetProperty(client::kModalKey)); 1450 EXPECT_EQ(ui::MODAL_TYPE_NONE, window.GetProperty(client::kModalKey));
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 1569 window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
1496 display_id, true); 1570 display_id, true);
1497 1571
1498 // aura::Window should operate in DIP and aura::WindowTreeHost should operate 1572 // aura::Window should operate in DIP and aura::WindowTreeHost should operate
1499 // in pixels. 1573 // in pixels.
1500 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); 1574 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds());
1501 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); 1575 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels());
1502 } 1576 }
1503 1577
1504 } // namespace aura 1578 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_tree_client.cc ('k') | ui/aura/test/aura_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698