| OLD | NEW |
| 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" | |
| 22 #include "ui/aura/client/focus_client.h" | 21 #include "ui/aura/client/focus_client.h" |
| 23 #include "ui/aura/client/transient_window_client.h" | 22 #include "ui/aura/client/transient_window_client.h" |
| 24 #include "ui/aura/mus/capture_synchronizer.h" | |
| 25 #include "ui/aura/mus/property_converter.h" | 23 #include "ui/aura/mus/property_converter.h" |
| 26 #include "ui/aura/mus/window_mus.h" | 24 #include "ui/aura/mus/window_mus.h" |
| 27 #include "ui/aura/mus/window_tree_client_delegate.h" | 25 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 28 #include "ui/aura/mus/window_tree_client_observer.h" | 26 #include "ui/aura/mus/window_tree_client_observer.h" |
| 29 #include "ui/aura/mus/window_tree_host_mus.h" | 27 #include "ui/aura/mus/window_tree_host_mus.h" |
| 30 #include "ui/aura/test/aura_mus_test_base.h" | 28 #include "ui/aura/test/aura_mus_test_base.h" |
| 31 #include "ui/aura/test/mus/test_window_tree.h" | 29 #include "ui/aura/test/mus/test_window_tree.h" |
| 32 #include "ui/aura/test/mus/window_tree_client_private.h" | 30 #include "ui/aura/test/mus/window_tree_client_private.h" |
| 33 #include "ui/aura/test/test_window_delegate.h" | 31 #include "ui/aura/test/test_window_delegate.h" |
| 34 #include "ui/aura/window.h" | 32 #include "ui/aura/window.h" |
| (...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1359 capture_recorder.reset_capture_captured_count(); | 1357 capture_recorder.reset_capture_captured_count(); |
| 1360 | 1358 |
| 1361 // Changes originating from server should notify observers too. | 1359 // Changes originating from server should notify observers too. |
| 1362 window_tree_client()->OnCaptureChanged(server_id(&child2), 0); | 1360 window_tree_client()->OnCaptureChanged(server_id(&child2), 0); |
| 1363 EXPECT_EQ(1, capture_recorder.capture_changed_count()); | 1361 EXPECT_EQ(1, capture_recorder.capture_changed_count()); |
| 1364 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id()); | 1362 EXPECT_EQ(child2_id, capture_recorder.last_gained_capture_window_id()); |
| 1365 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id()); | 1363 EXPECT_EQ(0, capture_recorder.last_lost_capture_window_id()); |
| 1366 capture_recorder.reset_capture_captured_count(); | 1364 capture_recorder.reset_capture_captured_count(); |
| 1367 } | 1365 } |
| 1368 | 1366 |
| 1369 TEST_F(WindowTreeClientClientTest, TwoWindowTreesRequestCapture) { | |
| 1370 // Creating a WindowTreeHost so we can have two root windows: top_level | |
| 1371 // and root_window(). | |
| 1372 WindowTreeHostMus window_tree_host(window_tree_client_impl()); | |
| 1373 Window* top_level = window_tree_host.window(); | |
| 1374 window_tree_host.InitHost(); | |
| 1375 client::DefaultCaptureClient* capture_client( | |
| 1376 new client::DefaultCaptureClient()); | |
| 1377 client::SetCaptureClient(top_level, capture_client); | |
| 1378 window_tree_client_impl()->capture_synchronizer()->AttachToCaptureClient( | |
| 1379 capture_client); | |
| 1380 EXPECT_NE(server_id(top_level), server_id(root_window())); | |
| 1381 | |
| 1382 // Ack the request to the windowtree to create the new window. | |
| 1383 uint32_t change_id; | |
| 1384 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( | |
| 1385 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); | |
| 1386 EXPECT_EQ(window_tree()->window_id(), server_id(top_level)); | |
| 1387 | |
| 1388 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); | |
| 1389 data->window_id = server_id(top_level); | |
| 1390 data->visible = true; | |
| 1391 const int64_t display_id = 1; | |
| 1392 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | |
| 1393 display_id, true); | |
| 1394 EXPECT_EQ( | |
| 1395 0u, window_tree()->GetChangeCountForType(WindowTreeChangeType::VISIBLE)); | |
| 1396 EXPECT_TRUE(top_level->TargetVisibility()); | |
| 1397 | |
| 1398 CaptureRecorder capture_recorder1(root_window()); | |
| 1399 CaptureRecorder capture_recorder2(top_level); | |
| 1400 EXPECT_NE(client::GetCaptureClient(root_window()), | |
| 1401 client::GetCaptureClient(top_level)); | |
| 1402 | |
| 1403 EXPECT_EQ(0, capture_recorder1.capture_changed_count()); | |
| 1404 EXPECT_EQ(0, capture_recorder2.capture_changed_count()); | |
| 1405 // Give capture to top_level and ensure everyone is notified correctly. | |
| 1406 top_level->SetCapture(); | |
| 1407 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( | |
| 1408 WindowTreeChangeType::CAPTURE, true)); | |
| 1409 EXPECT_EQ(0, capture_recorder1.capture_changed_count()); | |
| 1410 EXPECT_EQ(1, capture_recorder2.capture_changed_count()); | |
| 1411 EXPECT_EQ(top_level->id(), capture_recorder2.last_gained_capture_window_id()); | |
| 1412 EXPECT_EQ(0, capture_recorder2.last_lost_capture_window_id()); | |
| 1413 top_level->ReleaseCapture(); | |
| 1414 capture_recorder1.reset_capture_captured_count(); | |
| 1415 capture_recorder2.reset_capture_captured_count(); | |
| 1416 | |
| 1417 // Release capture of top_level shouldn't affect the capture of root_window(). | |
| 1418 top_level->SetCapture(); | |
| 1419 root_window()->SetCapture(); | |
| 1420 top_level->ReleaseCapture(); | |
| 1421 EXPECT_EQ(1, capture_recorder1.capture_changed_count()); | |
| 1422 EXPECT_EQ(2, capture_recorder2.capture_changed_count()); | |
| 1423 EXPECT_EQ(root_window()->id(), | |
| 1424 capture_recorder1.last_gained_capture_window_id()); | |
| 1425 EXPECT_EQ(0, capture_recorder1.last_lost_capture_window_id()); | |
| 1426 EXPECT_EQ(0, capture_recorder2.last_gained_capture_window_id()); | |
| 1427 EXPECT_EQ(top_level->id(), capture_recorder2.last_lost_capture_window_id()); | |
| 1428 capture_recorder1.reset_capture_captured_count(); | |
| 1429 capture_recorder2.reset_capture_captured_count(); | |
| 1430 } | |
| 1431 | |
| 1432 TEST_F(WindowTreeClientClientTest, ModalFail) { | 1367 TEST_F(WindowTreeClientClientTest, ModalFail) { |
| 1433 Window window(nullptr); | 1368 Window window(nullptr); |
| 1434 window.Init(ui::LAYER_NOT_DRAWN); | 1369 window.Init(ui::LAYER_NOT_DRAWN); |
| 1435 window.SetProperty(client::kModalKey, ui::MODAL_TYPE_WINDOW); | 1370 window.SetProperty(client::kModalKey, ui::MODAL_TYPE_WINDOW); |
| 1436 // Make sure server was told about it, and have the server say it failed. | 1371 // Make sure server was told about it, and have the server say it failed. |
| 1437 ASSERT_TRUE( | 1372 ASSERT_TRUE( |
| 1438 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, false)); | 1373 window_tree()->AckSingleChangeOfType(WindowTreeChangeType::MODAL, false)); |
| 1439 // Type should be back to MODAL_TYPE_NONE as the server didn't accept the | 1374 // Type should be back to MODAL_TYPE_NONE as the server didn't accept the |
| 1440 // change. | 1375 // change. |
| 1441 EXPECT_EQ(ui::MODAL_TYPE_NONE, window.GetProperty(client::kModalKey)); | 1376 EXPECT_EQ(ui::MODAL_TYPE_NONE, window.GetProperty(client::kModalKey)); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1560 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), | 1495 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), |
| 1561 display_id, true); | 1496 display_id, true); |
| 1562 | 1497 |
| 1563 // aura::Window should operate in DIP and aura::WindowTreeHost should operate | 1498 // aura::Window should operate in DIP and aura::WindowTreeHost should operate |
| 1564 // in pixels. | 1499 // in pixels. |
| 1565 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); | 1500 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); |
| 1566 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); | 1501 EXPECT_EQ(gfx::Rect(2, 4, 6, 8), top_level->GetHost()->GetBoundsInPixels()); |
| 1567 } | 1502 } |
| 1568 | 1503 |
| 1569 } // namespace aura | 1504 } // namespace aura |
| OLD | NEW |