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