| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "components/mus/common/util.h" | 12 #include "components/mus/common/util.h" |
| 13 #include "components/mus/public/cpp/lib/window_private.h" | 13 #include "components/mus/public/cpp/lib/window_private.h" |
| 14 #include "components/mus/public/cpp/lib/window_tree_client_impl.h" | |
| 15 #include "components/mus/public/cpp/tests/window_server_test_base.h" | 14 #include "components/mus/public/cpp/tests/window_server_test_base.h" |
| 16 #include "components/mus/public/cpp/window_observer.h" | 15 #include "components/mus/public/cpp/window_observer.h" |
| 17 #include "components/mus/public/cpp/window_tree_connection.h" | 16 #include "components/mus/public/cpp/window_tree_client.h" |
| 18 #include "components/mus/public/cpp/window_tree_connection_observer.h" | 17 #include "components/mus/public/cpp/window_tree_client_delegate.h" |
| 19 #include "components/mus/public/cpp/window_tree_delegate.h" | 18 #include "components/mus/public/cpp/window_tree_client_observer.h" |
| 20 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" | 19 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" |
| 21 #include "ui/gfx/geometry/mojo/geometry_util.h" | 20 #include "ui/gfx/geometry/mojo/geometry_util.h" |
| 22 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
| 23 | 22 |
| 24 namespace mus { | 23 namespace mus { |
| 25 namespace ws { | 24 namespace ws { |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 Id server_id(mus::Window* window) { | 28 Id server_id(mus::Window* window) { |
| 30 return WindowPrivate(window).server_id(); | 29 return WindowPrivate(window).server_id(); |
| 31 } | 30 } |
| 32 | 31 |
| 33 mus::Window* GetChildWindowByServerId(WindowTreeConnection* connection, | 32 mus::Window* GetChildWindowByServerId(WindowTreeClient* client, |
| 34 uint32_t id) { | 33 uint32_t id) { |
| 35 return static_cast<WindowTreeClientImpl*>(connection) | 34 return client->GetWindowByServerId(id); |
| 36 ->GetWindowByServerId(id); | |
| 37 } | 35 } |
| 38 | 36 |
| 39 int ValidIndexOf(const Window::Children& windows, Window* window) { | 37 int ValidIndexOf(const Window::Children& windows, Window* window) { |
| 40 Window::Children::const_iterator it = | 38 Window::Children::const_iterator it = |
| 41 std::find(windows.begin(), windows.end(), window); | 39 std::find(windows.begin(), windows.end(), window); |
| 42 return (it != windows.end()) ? (it - windows.begin()) : -1; | 40 return (it != windows.end()) ? (it - windows.begin()) : -1; |
| 43 } | 41 } |
| 44 | 42 |
| 45 class TestWindowManagerDelegate : public WindowManagerDelegate { | 43 class TestWindowManagerDelegate : public WindowManagerDelegate { |
| 46 public: | 44 public: |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); | 183 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); |
| 186 } | 184 } |
| 187 | 185 |
| 188 Window* window_; | 186 Window* window_; |
| 189 | 187 |
| 190 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); | 188 DISALLOW_COPY_AND_ASSIGN(OrderChangeObserver); |
| 191 }; | 189 }; |
| 192 | 190 |
| 193 // Wait until |window|'s tree size matches |tree_size|; returns false on | 191 // Wait until |window|'s tree size matches |tree_size|; returns false on |
| 194 // timeout. | 192 // timeout. |
| 195 bool WaitForOrderChange(WindowTreeConnection* connection, Window* window) { | 193 bool WaitForOrderChange(WindowTreeClient* client, Window* window) { |
| 196 OrderChangeObserver observer(window); | 194 OrderChangeObserver observer(window); |
| 197 return WindowServerTestBase::DoRunLoopWithTimeout(); | 195 return WindowServerTestBase::DoRunLoopWithTimeout(); |
| 198 } | 196 } |
| 199 | 197 |
| 200 // Tracks a window's destruction. Query is_valid() for current state. | 198 // Tracks a window's destruction. Query is_valid() for current state. |
| 201 class WindowTracker : public WindowObserver { | 199 class WindowTracker : public WindowObserver { |
| 202 public: | 200 public: |
| 203 explicit WindowTracker(Window* window) : window_(window) { | 201 explicit WindowTracker(Window* window) : window_(window) { |
| 204 window_->AddObserver(this); | 202 window_->AddObserver(this); |
| 205 } | 203 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 221 | 219 |
| 222 DISALLOW_COPY_AND_ASSIGN(WindowTracker); | 220 DISALLOW_COPY_AND_ASSIGN(WindowTracker); |
| 223 }; | 221 }; |
| 224 | 222 |
| 225 } // namespace | 223 } // namespace |
| 226 | 224 |
| 227 // WindowServer | 225 // WindowServer |
| 228 // ----------------------------------------------------------------- | 226 // ----------------------------------------------------------------- |
| 229 | 227 |
| 230 struct EmbedResult { | 228 struct EmbedResult { |
| 231 EmbedResult(WindowTreeConnection* connection, ClientSpecificId id) | 229 EmbedResult(WindowTreeClient* client, ClientSpecificId id) |
| 232 : connection(connection), client_id(id) {} | 230 : client(client), client_id(id) {} |
| 233 EmbedResult() : connection(nullptr), client_id(0) {} | 231 EmbedResult() : client(nullptr), client_id(0) {} |
| 234 | 232 |
| 235 WindowTreeConnection* connection; | 233 WindowTreeClient* client; |
| 236 | 234 |
| 237 // The id supplied to the callback from OnEmbed(). Depending upon the | 235 // The id supplied to the callback from OnEmbed(). Depending upon the |
| 238 // access policy this may or may not match the client id of | 236 // access policy this may or may not match the client id of |
| 239 // |connection|. | 237 // |client|. |
| 240 ClientSpecificId client_id; | 238 ClientSpecificId client_id; |
| 241 }; | 239 }; |
| 242 | 240 |
| 243 Window* GetFirstRoot(WindowTreeConnection* connection) { | 241 Window* GetFirstRoot(WindowTreeClient* client) { |
| 244 return connection->GetRoots().empty() ? nullptr | 242 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin(); |
| 245 : *connection->GetRoots().begin(); | |
| 246 } | 243 } |
| 247 | 244 |
| 248 // These tests model synchronization of two peer connections to the window | 245 // These tests model synchronization of two peer clients of the window server, |
| 249 // manager | 246 // that are given access to some root window. |
| 250 // service, that are given access to some root window. | |
| 251 | 247 |
| 252 class WindowServerTest : public WindowServerTestBase { | 248 class WindowServerTest : public WindowServerTestBase { |
| 253 public: | 249 public: |
| 254 WindowServerTest() {} | 250 WindowServerTest() {} |
| 255 | 251 |
| 256 Window* GetFirstWMRoot() { return GetFirstRoot(window_manager()); } | 252 Window* GetFirstWMRoot() { return GetFirstRoot(window_manager()); } |
| 257 | 253 |
| 258 Window* NewVisibleWindow(Window* parent, WindowTreeConnection* connection) { | 254 Window* NewVisibleWindow(Window* parent, WindowTreeClient* client) { |
| 259 Window* window = connection->NewWindow(); | 255 Window* window = client->NewWindow(); |
| 260 window->SetVisible(true); | 256 window->SetVisible(true); |
| 261 parent->AddChild(window); | 257 parent->AddChild(window); |
| 262 return window; | 258 return window; |
| 263 } | 259 } |
| 264 | 260 |
| 265 // Embeds another version of the test app @ window. This runs a run loop until | 261 // Embeds another version of the test app @ window. This runs a run loop until |
| 266 // a response is received, or a timeout. On success the new WindowServer is | 262 // a response is received, or a timeout. On success the new WindowServer is |
| 267 // returned. | 263 // returned. |
| 268 EmbedResult Embed(Window* window) { | 264 EmbedResult Embed(Window* window) { |
| 269 DCHECK(!embed_details_); | 265 DCHECK(!embed_details_); |
| 270 embed_details_.reset(new EmbedDetails); | 266 embed_details_.reset(new EmbedDetails); |
| 271 window->Embed(ConnectAndGetWindowServerClient(), | 267 window->Embed(ConnectAndGetWindowServerClient(), |
| 272 base::Bind(&WindowServerTest::EmbedCallbackImpl, | 268 base::Bind(&WindowServerTest::EmbedCallbackImpl, |
| 273 base::Unretained(this))); | 269 base::Unretained(this))); |
| 274 embed_details_->waiting = true; | 270 embed_details_->waiting = true; |
| 275 if (!WindowServerTestBase::DoRunLoopWithTimeout()) | 271 if (!WindowServerTestBase::DoRunLoopWithTimeout()) |
| 276 return EmbedResult(); | 272 return EmbedResult(); |
| 277 const EmbedResult result(embed_details_->connection, | 273 const EmbedResult result(embed_details_->client, |
| 278 embed_details_->client_id); | 274 embed_details_->client_id); |
| 279 embed_details_.reset(); | 275 embed_details_.reset(); |
| 280 return result; | 276 return result; |
| 281 } | 277 } |
| 282 | 278 |
| 283 // Establishes a connection to this application and asks for a | 279 // Establishes a connection to this application and asks for a |
| 284 // WindowTreeClient. | 280 // WindowTreeClient. |
| 285 mus::mojom::WindowTreeClientPtr ConnectAndGetWindowServerClient() { | 281 mus::mojom::WindowTreeClientPtr ConnectAndGetWindowServerClient() { |
| 286 mus::mojom::WindowTreeClientPtr client; | 282 mus::mojom::WindowTreeClientPtr client; |
| 287 connector()->ConnectToInterface(test_name(), &client); | 283 connector()->ConnectToInterface(test_name(), &client); |
| 288 return client; | 284 return client; |
| 289 } | 285 } |
| 290 | 286 |
| 291 // WindowServerTestBase: | 287 // WindowServerTestBase: |
| 292 void OnEmbed(Window* root) override { | 288 void OnEmbed(Window* root) override { |
| 293 if (!embed_details_) { | 289 if (!embed_details_) { |
| 294 WindowServerTestBase::OnEmbed(root); | 290 WindowServerTestBase::OnEmbed(root); |
| 295 return; | 291 return; |
| 296 } | 292 } |
| 297 | 293 |
| 298 embed_details_->connection = root->connection(); | 294 embed_details_->client = root->window_tree(); |
| 299 if (embed_details_->callback_run) | 295 if (embed_details_->callback_run) |
| 300 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); | 296 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); |
| 301 } | 297 } |
| 302 | 298 |
| 303 private: | 299 private: |
| 304 // Used to track the state of a call to window->Embed(). | 300 // Used to track the state of a call to window->Embed(). |
| 305 struct EmbedDetails { | 301 struct EmbedDetails { |
| 306 EmbedDetails() | 302 EmbedDetails() |
| 307 : callback_run(false), | 303 : callback_run(false), |
| 308 result(false), | 304 result(false), |
| 309 waiting(false), | 305 waiting(false), |
| 310 connection(nullptr) {} | 306 client(nullptr) {} |
| 311 | 307 |
| 312 // The callback supplied to Embed() was received. | 308 // The callback supplied to Embed() was received. |
| 313 bool callback_run; | 309 bool callback_run; |
| 314 | 310 |
| 315 // The boolean supplied to the Embed() callback. | 311 // The boolean supplied to the Embed() callback. |
| 316 bool result; | 312 bool result; |
| 317 | 313 |
| 318 // Whether a MessageLoop is running. | 314 // Whether a MessageLoop is running. |
| 319 bool waiting; | 315 bool waiting; |
| 320 | 316 |
| 321 // Client id supplied to the Embed() callback. | 317 // Client id supplied to the Embed() callback. |
| 322 ClientSpecificId client_id; | 318 ClientSpecificId client_id; |
| 323 | 319 |
| 324 // The WindowTreeConnection that resulted from the Embed(). null if |result| | 320 // The WindowTreeClient that resulted from the Embed(). null if |result| is |
| 325 // is false. | 321 // false. |
| 326 WindowTreeConnection* connection; | 322 WindowTreeClient* client; |
| 327 }; | 323 }; |
| 328 | 324 |
| 329 void EmbedCallbackImpl(bool result) { | 325 void EmbedCallbackImpl(bool result) { |
| 330 embed_details_->callback_run = true; | 326 embed_details_->callback_run = true; |
| 331 embed_details_->result = result; | 327 embed_details_->result = result; |
| 332 if (embed_details_->waiting && (!result || embed_details_->connection)) | 328 if (embed_details_->waiting && (!result || embed_details_->client)) |
| 333 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); | 329 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); |
| 334 } | 330 } |
| 335 | 331 |
| 336 std::unique_ptr<EmbedDetails> embed_details_; | 332 std::unique_ptr<EmbedDetails> embed_details_; |
| 337 | 333 |
| 338 DISALLOW_COPY_AND_ASSIGN(WindowServerTest); | 334 DISALLOW_COPY_AND_ASSIGN(WindowServerTest); |
| 339 }; | 335 }; |
| 340 | 336 |
| 341 TEST_F(WindowServerTest, RootWindow) { | 337 TEST_F(WindowServerTest, RootWindow) { |
| 342 ASSERT_NE(nullptr, window_manager()); | 338 ASSERT_NE(nullptr, window_manager()); |
| 343 EXPECT_EQ(1u, window_manager()->GetRoots().size()); | 339 EXPECT_EQ(1u, window_manager()->GetRoots().size()); |
| 344 } | 340 } |
| 345 | 341 |
| 346 TEST_F(WindowServerTest, Embed) { | 342 TEST_F(WindowServerTest, Embed) { |
| 347 Window* window = window_manager()->NewWindow(); | 343 Window* window = window_manager()->NewWindow(); |
| 348 ASSERT_NE(nullptr, window); | 344 ASSERT_NE(nullptr, window); |
| 349 window->SetVisible(true); | 345 window->SetVisible(true); |
| 350 GetFirstWMRoot()->AddChild(window); | 346 GetFirstWMRoot()->AddChild(window); |
| 351 WindowTreeConnection* embedded = Embed(window).connection; | 347 WindowTreeClient* embedded = Embed(window).client; |
| 352 ASSERT_NE(nullptr, embedded); | 348 ASSERT_NE(nullptr, embedded); |
| 353 | 349 |
| 354 Window* window_in_embedded = GetFirstRoot(embedded); | 350 Window* window_in_embedded = GetFirstRoot(embedded); |
| 355 ASSERT_NE(nullptr, window_in_embedded); | 351 ASSERT_NE(nullptr, window_in_embedded); |
| 356 EXPECT_EQ(server_id(window), server_id(window_in_embedded)); | 352 EXPECT_EQ(server_id(window), server_id(window_in_embedded)); |
| 357 EXPECT_EQ(nullptr, window_in_embedded->parent()); | 353 EXPECT_EQ(nullptr, window_in_embedded->parent()); |
| 358 EXPECT_TRUE(window_in_embedded->children().empty()); | 354 EXPECT_TRUE(window_in_embedded->children().empty()); |
| 359 } | 355 } |
| 360 | 356 |
| 361 // Window manager has two windows, N1 and N11. Embeds A at N1. A should not see | 357 // Window manager has two windows, N1 and N11. Embeds A at N1. A should not see |
| 362 // N11. | 358 // N11. |
| 363 TEST_F(WindowServerTest, EmbeddedDoesntSeeChild) { | 359 TEST_F(WindowServerTest, EmbeddedDoesntSeeChild) { |
| 364 Window* window = window_manager()->NewWindow(); | 360 Window* window = window_manager()->NewWindow(); |
| 365 ASSERT_NE(nullptr, window); | 361 ASSERT_NE(nullptr, window); |
| 366 window->SetVisible(true); | 362 window->SetVisible(true); |
| 367 GetFirstWMRoot()->AddChild(window); | 363 GetFirstWMRoot()->AddChild(window); |
| 368 Window* nested = window_manager()->NewWindow(); | 364 Window* nested = window_manager()->NewWindow(); |
| 369 ASSERT_NE(nullptr, nested); | 365 ASSERT_NE(nullptr, nested); |
| 370 nested->SetVisible(true); | 366 nested->SetVisible(true); |
| 371 window->AddChild(nested); | 367 window->AddChild(nested); |
| 372 | 368 |
| 373 WindowTreeConnection* embedded = Embed(window).connection; | 369 WindowTreeClient* embedded = Embed(window).client; |
| 374 ASSERT_NE(nullptr, embedded); | 370 ASSERT_NE(nullptr, embedded); |
| 375 Window* window_in_embedded = GetFirstRoot(embedded); | 371 Window* window_in_embedded = GetFirstRoot(embedded); |
| 376 EXPECT_EQ(server_id(window), server_id(window_in_embedded)); | 372 EXPECT_EQ(server_id(window), server_id(window_in_embedded)); |
| 377 EXPECT_EQ(nullptr, window_in_embedded->parent()); | 373 EXPECT_EQ(nullptr, window_in_embedded->parent()); |
| 378 EXPECT_TRUE(window_in_embedded->children().empty()); | 374 EXPECT_TRUE(window_in_embedded->children().empty()); |
| 379 } | 375 } |
| 380 | 376 |
| 381 // TODO(beng): write a replacement test for the one that once existed here: | 377 // TODO(beng): write a replacement test for the one that once existed here: |
| 382 // This test validates the following scenario: | 378 // This test validates the following scenario: |
| 383 // - a window originating from one connection | 379 // - a window originating from one client |
| 384 // - a window originating from a second connection | 380 // - a window originating from a second client |
| 385 // + the connection originating the window is destroyed | 381 // + the client originating the window is destroyed |
| 386 // -> the window should still exist (since the second connection is live) but | 382 // -> the window should still exist (since the second client is live) but |
| 387 // should be disconnected from any windows. | 383 // should be disconnected from any windows. |
| 388 // http://crbug.com/396300 | 384 // http://crbug.com/396300 |
| 389 // | 385 // |
| 390 // TODO(beng): The new test should validate the scenario as described above | 386 // TODO(beng): The new test should validate the scenario as described above |
| 391 // except that the second connection still has a valid tree. | 387 // except that the second client still has a valid tree. |
| 392 | 388 |
| 393 // Verifies that bounds changes applied to a window hierarchy in one connection | 389 // Verifies that bounds changes applied to a window hierarchy in one client |
| 394 // are reflected to another. | 390 // are reflected to another. |
| 395 TEST_F(WindowServerTest, SetBounds) { | 391 TEST_F(WindowServerTest, SetBounds) { |
| 396 Window* window = window_manager()->NewWindow(); | 392 Window* window = window_manager()->NewWindow(); |
| 397 window->SetVisible(true); | 393 window->SetVisible(true); |
| 398 GetFirstWMRoot()->AddChild(window); | 394 GetFirstWMRoot()->AddChild(window); |
| 399 WindowTreeConnection* embedded = Embed(window).connection; | 395 WindowTreeClient* embedded = Embed(window).client; |
| 400 ASSERT_NE(nullptr, embedded); | 396 ASSERT_NE(nullptr, embedded); |
| 401 | 397 |
| 402 Window* window_in_embedded = | 398 Window* window_in_embedded = |
| 403 GetChildWindowByServerId(embedded, server_id(window)); | 399 GetChildWindowByServerId(embedded, server_id(window)); |
| 404 EXPECT_EQ(window->bounds(), window_in_embedded->bounds()); | 400 EXPECT_EQ(window->bounds(), window_in_embedded->bounds()); |
| 405 | 401 |
| 406 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 402 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 407 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); | 403 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); |
| 408 EXPECT_TRUE(window->bounds() == window_in_embedded->bounds()); | 404 EXPECT_TRUE(window->bounds() == window_in_embedded->bounds()); |
| 409 } | 405 } |
| 410 | 406 |
| 411 // Verifies that bounds changes applied to a window owned by a different | 407 // Verifies that bounds changes applied to a window owned by a different |
| 412 // connection can be refused. | 408 // client can be refused. |
| 413 TEST_F(WindowServerTest, SetBoundsSecurity) { | 409 TEST_F(WindowServerTest, SetBoundsSecurity) { |
| 414 TestWindowManagerDelegate wm_delegate; | 410 TestWindowManagerDelegate wm_delegate; |
| 415 set_window_manager_delegate(&wm_delegate); | 411 set_window_manager_delegate(&wm_delegate); |
| 416 | 412 |
| 417 Window* window = window_manager()->NewWindow(); | 413 Window* window = window_manager()->NewWindow(); |
| 418 window->SetVisible(true); | 414 window->SetVisible(true); |
| 419 GetFirstWMRoot()->AddChild(window); | 415 GetFirstWMRoot()->AddChild(window); |
| 420 WindowTreeConnection* embedded = Embed(window).connection; | 416 WindowTreeClient* embedded = Embed(window).client; |
| 421 ASSERT_NE(nullptr, embedded); | 417 ASSERT_NE(nullptr, embedded); |
| 422 | 418 |
| 423 Window* window_in_embedded = | 419 Window* window_in_embedded = |
| 424 GetChildWindowByServerId(embedded, server_id(window)); | 420 GetChildWindowByServerId(embedded, server_id(window)); |
| 425 window->SetBounds(gfx::Rect(0, 0, 800, 600)); | 421 window->SetBounds(gfx::Rect(0, 0, 800, 600)); |
| 426 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); | 422 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); |
| 427 | 423 |
| 428 window_in_embedded->SetBounds(gfx::Rect(0, 0, 1024, 768)); | 424 window_in_embedded->SetBounds(gfx::Rect(0, 0, 1024, 768)); |
| 429 // Bounds change is initially accepted, but the server declines the request. | 425 // Bounds change is initially accepted, but the server declines the request. |
| 430 EXPECT_FALSE(window->bounds() == window_in_embedded->bounds()); | 426 EXPECT_FALSE(window->bounds() == window_in_embedded->bounds()); |
| 431 | 427 |
| 432 // The client is notified when the requested is declined, and updates the | 428 // The client is notified when the requested is declined, and updates the |
| 433 // local bounds accordingly. | 429 // local bounds accordingly. |
| 434 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); | 430 ASSERT_TRUE(WaitForBoundsToChange(window_in_embedded)); |
| 435 EXPECT_TRUE(window->bounds() == window_in_embedded->bounds()); | 431 EXPECT_TRUE(window->bounds() == window_in_embedded->bounds()); |
| 436 set_window_manager_delegate(nullptr); | 432 set_window_manager_delegate(nullptr); |
| 437 } | 433 } |
| 438 | 434 |
| 439 // Verifies that a root window can always be destroyed. | 435 // Verifies that a root window can always be destroyed. |
| 440 TEST_F(WindowServerTest, DestroySecurity) { | 436 TEST_F(WindowServerTest, DestroySecurity) { |
| 441 Window* window = window_manager()->NewWindow(); | 437 Window* window = window_manager()->NewWindow(); |
| 442 window->SetVisible(true); | 438 window->SetVisible(true); |
| 443 GetFirstWMRoot()->AddChild(window); | 439 GetFirstWMRoot()->AddChild(window); |
| 444 | 440 |
| 445 WindowTreeConnection* embedded = Embed(window).connection; | 441 WindowTreeClient* embedded = Embed(window).client; |
| 446 ASSERT_NE(nullptr, embedded); | 442 ASSERT_NE(nullptr, embedded); |
| 447 | 443 |
| 448 // The root can be destroyed, even though it was not created by the | 444 // The root can be destroyed, even though it was not created by the client. |
| 449 // connection. | |
| 450 Window* embed_root = GetChildWindowByServerId(embedded, server_id(window)); | 445 Window* embed_root = GetChildWindowByServerId(embedded, server_id(window)); |
| 451 WindowTracker tracker1(window); | 446 WindowTracker tracker1(window); |
| 452 WindowTracker tracker2(embed_root); | 447 WindowTracker tracker2(embed_root); |
| 453 embed_root->Destroy(); | 448 embed_root->Destroy(); |
| 454 EXPECT_FALSE(tracker2.is_valid()); | 449 EXPECT_FALSE(tracker2.is_valid()); |
| 455 EXPECT_TRUE(tracker1.is_valid()); | 450 EXPECT_TRUE(tracker1.is_valid()); |
| 456 | 451 |
| 457 window->Destroy(); | 452 window->Destroy(); |
| 458 EXPECT_FALSE(tracker1.is_valid()); | 453 EXPECT_FALSE(tracker1.is_valid()); |
| 459 } | 454 } |
| 460 | 455 |
| 461 TEST_F(WindowServerTest, MultiRoots) { | 456 TEST_F(WindowServerTest, MultiRoots) { |
| 462 Window* window1 = window_manager()->NewWindow(); | 457 Window* window1 = window_manager()->NewWindow(); |
| 463 window1->SetVisible(true); | 458 window1->SetVisible(true); |
| 464 GetFirstWMRoot()->AddChild(window1); | 459 GetFirstWMRoot()->AddChild(window1); |
| 465 Window* window2 = window_manager()->NewWindow(); | 460 Window* window2 = window_manager()->NewWindow(); |
| 466 window2->SetVisible(true); | 461 window2->SetVisible(true); |
| 467 GetFirstWMRoot()->AddChild(window2); | 462 GetFirstWMRoot()->AddChild(window2); |
| 468 WindowTreeConnection* embedded1 = Embed(window1).connection; | 463 WindowTreeClient* embedded1 = Embed(window1).client; |
| 469 ASSERT_NE(nullptr, embedded1); | 464 ASSERT_NE(nullptr, embedded1); |
| 470 WindowTreeConnection* embedded2 = Embed(window2).connection; | 465 WindowTreeClient* embedded2 = Embed(window2).client; |
| 471 ASSERT_NE(nullptr, embedded2); | 466 ASSERT_NE(nullptr, embedded2); |
| 472 EXPECT_NE(embedded1, embedded2); | 467 EXPECT_NE(embedded1, embedded2); |
| 473 } | 468 } |
| 474 | 469 |
| 475 TEST_F(WindowServerTest, Reorder) { | 470 TEST_F(WindowServerTest, Reorder) { |
| 476 Window* window1 = window_manager()->NewWindow(); | 471 Window* window1 = window_manager()->NewWindow(); |
| 477 window1->SetVisible(true); | 472 window1->SetVisible(true); |
| 478 GetFirstWMRoot()->AddChild(window1); | 473 GetFirstWMRoot()->AddChild(window1); |
| 479 | 474 |
| 480 WindowTreeConnection* embedded = Embed(window1).connection; | 475 WindowTreeClient* embedded = Embed(window1).client; |
| 481 ASSERT_NE(nullptr, embedded); | 476 ASSERT_NE(nullptr, embedded); |
| 482 | 477 |
| 483 Window* window11 = embedded->NewWindow(); | 478 Window* window11 = embedded->NewWindow(); |
| 484 window11->SetVisible(true); | 479 window11->SetVisible(true); |
| 485 GetFirstRoot(embedded)->AddChild(window11); | 480 GetFirstRoot(embedded)->AddChild(window11); |
| 486 Window* window12 = embedded->NewWindow(); | 481 Window* window12 = embedded->NewWindow(); |
| 487 window12->SetVisible(true); | 482 window12->SetVisible(true); |
| 488 GetFirstRoot(embedded)->AddChild(window12); | 483 GetFirstRoot(embedded)->AddChild(window12); |
| 489 ASSERT_TRUE(WaitForTreeSizeToMatch(window1, 3u)); | 484 ASSERT_TRUE(WaitForTreeSizeToMatch(window1, 3u)); |
| 490 | 485 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 }; | 550 }; |
| 556 | 551 |
| 557 } // namespace | 552 } // namespace |
| 558 | 553 |
| 559 TEST_F(WindowServerTest, Visible) { | 554 TEST_F(WindowServerTest, Visible) { |
| 560 Window* window1 = window_manager()->NewWindow(); | 555 Window* window1 = window_manager()->NewWindow(); |
| 561 window1->SetVisible(true); | 556 window1->SetVisible(true); |
| 562 GetFirstWMRoot()->AddChild(window1); | 557 GetFirstWMRoot()->AddChild(window1); |
| 563 | 558 |
| 564 // Embed another app and verify initial state. | 559 // Embed another app and verify initial state. |
| 565 WindowTreeConnection* embedded = Embed(window1).connection; | 560 WindowTreeClient* embedded = Embed(window1).client; |
| 566 ASSERT_NE(nullptr, embedded); | 561 ASSERT_NE(nullptr, embedded); |
| 567 ASSERT_NE(nullptr, GetFirstRoot(embedded)); | 562 ASSERT_NE(nullptr, GetFirstRoot(embedded)); |
| 568 Window* embedded_root = GetFirstRoot(embedded); | 563 Window* embedded_root = GetFirstRoot(embedded); |
| 569 EXPECT_TRUE(embedded_root->visible()); | 564 EXPECT_TRUE(embedded_root->visible()); |
| 570 EXPECT_TRUE(embedded_root->IsDrawn()); | 565 EXPECT_TRUE(embedded_root->IsDrawn()); |
| 571 | 566 |
| 572 // Change the visible state from the first connection and verify its mirrored | 567 // Change the visible state from the first client and verify its mirrored |
| 573 // correctly to the embedded app. | 568 // correctly to the embedded app. |
| 574 { | 569 { |
| 575 VisibilityChangeObserver observer(embedded_root); | 570 VisibilityChangeObserver observer(embedded_root); |
| 576 window1->SetVisible(false); | 571 window1->SetVisible(false); |
| 577 ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout()); | 572 ASSERT_TRUE(WindowServerTestBase::DoRunLoopWithTimeout()); |
| 578 } | 573 } |
| 579 | 574 |
| 580 EXPECT_FALSE(window1->visible()); | 575 EXPECT_FALSE(window1->visible()); |
| 581 EXPECT_FALSE(window1->IsDrawn()); | 576 EXPECT_FALSE(window1->IsDrawn()); |
| 582 | 577 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 }; | 614 }; |
| 620 | 615 |
| 621 } // namespace | 616 } // namespace |
| 622 | 617 |
| 623 TEST_F(WindowServerTest, Drawn) { | 618 TEST_F(WindowServerTest, Drawn) { |
| 624 Window* window1 = window_manager()->NewWindow(); | 619 Window* window1 = window_manager()->NewWindow(); |
| 625 window1->SetVisible(true); | 620 window1->SetVisible(true); |
| 626 GetFirstWMRoot()->AddChild(window1); | 621 GetFirstWMRoot()->AddChild(window1); |
| 627 | 622 |
| 628 // Embed another app and verify initial state. | 623 // Embed another app and verify initial state. |
| 629 WindowTreeConnection* embedded = Embed(window1).connection; | 624 WindowTreeClient* embedded = Embed(window1).client; |
| 630 ASSERT_NE(nullptr, embedded); | 625 ASSERT_NE(nullptr, embedded); |
| 631 ASSERT_NE(nullptr, GetFirstRoot(embedded)); | 626 ASSERT_NE(nullptr, GetFirstRoot(embedded)); |
| 632 Window* embedded_root = GetFirstRoot(embedded); | 627 Window* embedded_root = GetFirstRoot(embedded); |
| 633 EXPECT_TRUE(embedded_root->visible()); | 628 EXPECT_TRUE(embedded_root->visible()); |
| 634 EXPECT_TRUE(embedded_root->IsDrawn()); | 629 EXPECT_TRUE(embedded_root->IsDrawn()); |
| 635 | 630 |
| 636 // Change the visibility of the root, this should propagate a drawn state | 631 // Change the visibility of the root, this should propagate a drawn state |
| 637 // change to |embedded|. | 632 // change to |embedded|. |
| 638 { | 633 { |
| 639 DrawnChangeObserver observer(embedded_root); | 634 DrawnChangeObserver observer(embedded_root); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 } | 677 } |
| 683 | 678 |
| 684 Window* window_; | 679 Window* window_; |
| 685 Window* last_gained_focus_; | 680 Window* last_gained_focus_; |
| 686 Window* last_lost_focus_; | 681 Window* last_lost_focus_; |
| 687 bool quit_on_change_; | 682 bool quit_on_change_; |
| 688 | 683 |
| 689 DISALLOW_COPY_AND_ASSIGN(FocusChangeObserver); | 684 DISALLOW_COPY_AND_ASSIGN(FocusChangeObserver); |
| 690 }; | 685 }; |
| 691 | 686 |
| 692 class NullFocusChangeObserver : public WindowTreeConnectionObserver { | 687 class NullFocusChangeObserver : public WindowTreeClientObserver { |
| 693 public: | 688 public: |
| 694 explicit NullFocusChangeObserver(WindowTreeConnection* connection) | 689 explicit NullFocusChangeObserver(WindowTreeClient* client) |
| 695 : connection_(connection) { | 690 : client_(client) { |
| 696 connection_->AddObserver(this); | 691 client_->AddObserver(this); |
| 697 } | 692 } |
| 698 ~NullFocusChangeObserver() override { connection_->RemoveObserver(this); } | 693 ~NullFocusChangeObserver() override { client_->RemoveObserver(this); } |
| 699 | 694 |
| 700 private: | 695 private: |
| 701 // Overridden from WindowTreeConnectionObserver. | 696 // Overridden from WindowTreeClientObserver. |
| 702 void OnWindowTreeFocusChanged(Window* gained_focus, | 697 void OnWindowTreeFocusChanged(Window* gained_focus, |
| 703 Window* lost_focus) override { | 698 Window* lost_focus) override { |
| 704 if (!gained_focus) | 699 if (!gained_focus) |
| 705 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); | 700 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); |
| 706 } | 701 } |
| 707 | 702 |
| 708 WindowTreeConnection* connection_; | 703 WindowTreeClient* client_; |
| 709 | 704 |
| 710 DISALLOW_COPY_AND_ASSIGN(NullFocusChangeObserver); | 705 DISALLOW_COPY_AND_ASSIGN(NullFocusChangeObserver); |
| 711 }; | 706 }; |
| 712 | 707 |
| 713 bool WaitForWindowToHaveFocus(Window* window) { | 708 bool WaitForWindowToHaveFocus(Window* window) { |
| 714 if (window->HasFocus()) | 709 if (window->HasFocus()) |
| 715 return true; | 710 return true; |
| 716 FocusChangeObserver observer(window); | 711 FocusChangeObserver observer(window); |
| 717 return WindowServerTestBase::DoRunLoopWithTimeout(); | 712 return WindowServerTestBase::DoRunLoopWithTimeout(); |
| 718 } | 713 } |
| 719 | 714 |
| 720 bool WaitForNoWindowToHaveFocus(WindowTreeConnection* connection) { | 715 bool WaitForNoWindowToHaveFocus(WindowTreeClient* client) { |
| 721 if (!connection->GetFocusedWindow()) | 716 if (!client->GetFocusedWindow()) |
| 722 return true; | 717 return true; |
| 723 NullFocusChangeObserver observer(connection); | 718 NullFocusChangeObserver observer(client); |
| 724 return WindowServerTestBase::DoRunLoopWithTimeout(); | 719 return WindowServerTestBase::DoRunLoopWithTimeout(); |
| 725 } | 720 } |
| 726 | 721 |
| 727 } // namespace | 722 } // namespace |
| 728 | 723 |
| 729 TEST_F(WindowServerTest, Focus) { | 724 TEST_F(WindowServerTest, Focus) { |
| 730 Window* window1 = window_manager()->NewWindow(); | 725 Window* window1 = window_manager()->NewWindow(); |
| 731 window1->SetVisible(true); | 726 window1->SetVisible(true); |
| 732 GetFirstWMRoot()->AddChild(window1); | 727 GetFirstWMRoot()->AddChild(window1); |
| 733 | 728 |
| 734 WindowTreeConnection* embedded = Embed(window1).connection; | 729 WindowTreeClient* embedded = Embed(window1).client; |
| 735 ASSERT_NE(nullptr, embedded); | 730 ASSERT_NE(nullptr, embedded); |
| 736 Window* window11 = embedded->NewWindow(); | 731 Window* window11 = embedded->NewWindow(); |
| 737 window11->SetVisible(true); | 732 window11->SetVisible(true); |
| 738 GetFirstRoot(embedded)->AddChild(window11); | 733 GetFirstRoot(embedded)->AddChild(window11); |
| 739 | 734 |
| 740 { | 735 { |
| 741 // Focus the embed root in |embedded|. | 736 // Focus the embed root in |embedded|. |
| 742 Window* embedded_root = GetFirstRoot(embedded); | 737 Window* embedded_root = GetFirstRoot(embedded); |
| 743 FocusChangeObserver observer(embedded_root); | 738 FocusChangeObserver observer(embedded_root); |
| 744 observer.set_quit_on_change(false); | 739 observer.set_quit_on_change(false); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 EXPECT_EQ(server_id(GetFirstRoot(embedded)), | 773 EXPECT_EQ(server_id(GetFirstRoot(embedded)), |
| 779 server_id(observer.last_gained_focus())); | 774 server_id(observer.last_gained_focus())); |
| 780 } | 775 } |
| 781 } | 776 } |
| 782 | 777 |
| 783 TEST_F(WindowServerTest, ClearFocus) { | 778 TEST_F(WindowServerTest, ClearFocus) { |
| 784 Window* window1 = window_manager()->NewWindow(); | 779 Window* window1 = window_manager()->NewWindow(); |
| 785 window1->SetVisible(true); | 780 window1->SetVisible(true); |
| 786 GetFirstWMRoot()->AddChild(window1); | 781 GetFirstWMRoot()->AddChild(window1); |
| 787 | 782 |
| 788 WindowTreeConnection* embedded = Embed(window1).connection; | 783 WindowTreeClient* embedded = Embed(window1).client; |
| 789 ASSERT_NE(nullptr, embedded); | 784 ASSERT_NE(nullptr, embedded); |
| 790 Window* window11 = embedded->NewWindow(); | 785 Window* window11 = embedded->NewWindow(); |
| 791 window11->SetVisible(true); | 786 window11->SetVisible(true); |
| 792 GetFirstRoot(embedded)->AddChild(window11); | 787 GetFirstRoot(embedded)->AddChild(window11); |
| 793 | 788 |
| 794 // Focus the embed root in |embedded|. | 789 // Focus the embed root in |embedded|. |
| 795 Window* embedded_root = GetFirstRoot(embedded); | 790 Window* embedded_root = GetFirstRoot(embedded); |
| 796 { | 791 { |
| 797 FocusChangeObserver observer(embedded_root); | 792 FocusChangeObserver observer(embedded_root); |
| 798 observer.set_quit_on_change(false); | 793 observer.set_quit_on_change(false); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 817 EXPECT_FALSE(window1->HasFocus()); | 812 EXPECT_FALSE(window1->HasFocus()); |
| 818 EXPECT_FALSE(window_manager()->GetFocusedWindow()); | 813 EXPECT_FALSE(window_manager()->GetFocusedWindow()); |
| 819 } | 814 } |
| 820 } | 815 } |
| 821 | 816 |
| 822 TEST_F(WindowServerTest, FocusNonFocusableWindow) { | 817 TEST_F(WindowServerTest, FocusNonFocusableWindow) { |
| 823 Window* window = window_manager()->NewWindow(); | 818 Window* window = window_manager()->NewWindow(); |
| 824 window->SetVisible(true); | 819 window->SetVisible(true); |
| 825 GetFirstWMRoot()->AddChild(window); | 820 GetFirstWMRoot()->AddChild(window); |
| 826 | 821 |
| 827 WindowTreeConnection* connection = Embed(window).connection; | 822 WindowTreeClient* client = Embed(window).client; |
| 828 ASSERT_NE(nullptr, connection); | 823 ASSERT_NE(nullptr, client); |
| 829 ASSERT_FALSE(connection->GetRoots().empty()); | 824 ASSERT_FALSE(client->GetRoots().empty()); |
| 830 Window* client_window = *connection->GetRoots().begin(); | 825 Window* client_window = *client->GetRoots().begin(); |
| 831 client_window->SetCanFocus(false); | 826 client_window->SetCanFocus(false); |
| 832 | 827 |
| 833 client_window->SetFocus(); | 828 client_window->SetFocus(); |
| 834 ASSERT_TRUE(client_window->HasFocus()); | 829 ASSERT_TRUE(client_window->HasFocus()); |
| 835 | 830 |
| 836 WaitForNoWindowToHaveFocus(connection); | 831 WaitForNoWindowToHaveFocus(client); |
| 837 ASSERT_FALSE(client_window->HasFocus()); | 832 ASSERT_FALSE(client_window->HasFocus()); |
| 838 } | 833 } |
| 839 | 834 |
| 840 TEST_F(WindowServerTest, Activation) { | 835 TEST_F(WindowServerTest, Activation) { |
| 841 Window* parent = NewVisibleWindow(GetFirstWMRoot(), window_manager()); | 836 Window* parent = NewVisibleWindow(GetFirstWMRoot(), window_manager()); |
| 842 | 837 |
| 843 // Allow the child windows to be activated. Do this before we wait, that way | 838 // Allow the child windows to be activated. Do this before we wait, that way |
| 844 // we're guaranteed that when we request focus from a separate client the | 839 // we're guaranteed that when we request focus from a separate client the |
| 845 // requests are processed in order. | 840 // requests are processed in order. |
| 846 window_manager_client()->AddActivationParent(parent); | 841 window_manager_client()->AddActivationParent(parent); |
| 847 | 842 |
| 848 Window* child1 = NewVisibleWindow(parent, window_manager()); | 843 Window* child1 = NewVisibleWindow(parent, window_manager()); |
| 849 Window* child2 = NewVisibleWindow(parent, window_manager()); | 844 Window* child2 = NewVisibleWindow(parent, window_manager()); |
| 850 Window* child3 = NewVisibleWindow(parent, window_manager()); | 845 Window* child3 = NewVisibleWindow(parent, window_manager()); |
| 851 | 846 |
| 852 child1->AddTransientWindow(child3); | 847 child1->AddTransientWindow(child3); |
| 853 | 848 |
| 854 WindowTreeConnection* embedded1 = Embed(child1).connection; | 849 WindowTreeClient* embedded1 = Embed(child1).client; |
| 855 ASSERT_NE(nullptr, embedded1); | 850 ASSERT_NE(nullptr, embedded1); |
| 856 WindowTreeConnection* embedded2 = Embed(child2).connection; | 851 WindowTreeClient* embedded2 = Embed(child2).client; |
| 857 ASSERT_NE(nullptr, embedded2); | 852 ASSERT_NE(nullptr, embedded2); |
| 858 | 853 |
| 859 Window* child11 = NewVisibleWindow(GetFirstRoot(embedded1), embedded1); | 854 Window* child11 = NewVisibleWindow(GetFirstRoot(embedded1), embedded1); |
| 860 Window* child21 = NewVisibleWindow(GetFirstRoot(embedded2), embedded2); | 855 Window* child21 = NewVisibleWindow(GetFirstRoot(embedded2), embedded2); |
| 861 | 856 |
| 862 WaitForTreeSizeToMatch(parent, 6); | 857 WaitForTreeSizeToMatch(parent, 6); |
| 863 | 858 |
| 864 // |child2| and |child3| are stacked about |child1|. | 859 // |child2| and |child3| are stacked about |child1|. |
| 865 EXPECT_GT(ValidIndexOf(parent->children(), child2), | 860 EXPECT_GT(ValidIndexOf(parent->children(), child2), |
| 866 ValidIndexOf(parent->children(), child1)); | 861 ValidIndexOf(parent->children(), child1)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 EXPECT_GT(ValidIndexOf(parent->children(), child3), | 894 EXPECT_GT(ValidIndexOf(parent->children(), child3), |
| 900 ValidIndexOf(parent->children(), child1)); | 895 ValidIndexOf(parent->children(), child1)); |
| 901 } | 896 } |
| 902 | 897 |
| 903 TEST_F(WindowServerTest, ActivationNext) { | 898 TEST_F(WindowServerTest, ActivationNext) { |
| 904 Window* parent = GetFirstWMRoot(); | 899 Window* parent = GetFirstWMRoot(); |
| 905 Window* child1 = NewVisibleWindow(parent, window_manager()); | 900 Window* child1 = NewVisibleWindow(parent, window_manager()); |
| 906 Window* child2 = NewVisibleWindow(parent, window_manager()); | 901 Window* child2 = NewVisibleWindow(parent, window_manager()); |
| 907 Window* child3 = NewVisibleWindow(parent, window_manager()); | 902 Window* child3 = NewVisibleWindow(parent, window_manager()); |
| 908 | 903 |
| 909 WindowTreeConnection* embedded1 = Embed(child1).connection; | 904 WindowTreeClient* embedded1 = Embed(child1).client; |
| 910 ASSERT_NE(nullptr, embedded1); | 905 ASSERT_NE(nullptr, embedded1); |
| 911 WindowTreeConnection* embedded2 = Embed(child2).connection; | 906 WindowTreeClient* embedded2 = Embed(child2).client; |
| 912 ASSERT_NE(nullptr, embedded2); | 907 ASSERT_NE(nullptr, embedded2); |
| 913 WindowTreeConnection* embedded3 = Embed(child3).connection; | 908 WindowTreeClient* embedded3 = Embed(child3).client; |
| 914 ASSERT_NE(nullptr, embedded3); | 909 ASSERT_NE(nullptr, embedded3); |
| 915 | 910 |
| 916 Window* child11 = NewVisibleWindow(GetFirstRoot(embedded1), embedded1); | 911 Window* child11 = NewVisibleWindow(GetFirstRoot(embedded1), embedded1); |
| 917 Window* child21 = NewVisibleWindow(GetFirstRoot(embedded2), embedded2); | 912 Window* child21 = NewVisibleWindow(GetFirstRoot(embedded2), embedded2); |
| 918 Window* child31 = NewVisibleWindow(GetFirstRoot(embedded3), embedded3); | 913 Window* child31 = NewVisibleWindow(GetFirstRoot(embedded3), embedded3); |
| 919 WaitForTreeSizeToMatch(parent, 7); | 914 WaitForTreeSizeToMatch(parent, 7); |
| 920 | 915 |
| 921 Window* expecteds[] = { child3, child2, child1, child3, nullptr }; | 916 Window* expecteds[] = { child3, child2, child1, child3, nullptr }; |
| 922 Window* focused[] = { child31, child21, child11, child31, nullptr }; | 917 Window* focused[] = { child31, child21, child11, child31, nullptr }; |
| 923 for (size_t index = 0; expecteds[index]; ++index) { | 918 for (size_t index = 0; expecteds[index]; ++index) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 944 } | 939 } |
| 945 | 940 |
| 946 private: | 941 private: |
| 947 // Overridden from WindowObserver: | 942 // Overridden from WindowObserver: |
| 948 void OnWindowDestroyed(Window* window) override { | 943 void OnWindowDestroyed(Window* window) override { |
| 949 EXPECT_EQ(window, window_); | 944 EXPECT_EQ(window, window_); |
| 950 window_->RemoveObserver(this); | 945 window_->RemoveObserver(this); |
| 951 *got_destroy_ = true; | 946 *got_destroy_ = true; |
| 952 window_ = nullptr; | 947 window_ = nullptr; |
| 953 | 948 |
| 954 // We should always get OnWindowDestroyed() before OnConnectionLost(). | 949 // We should always get OnWindowDestroyed() before |
| 955 EXPECT_FALSE(test_->window_tree_connection_destroyed()); | 950 // OnWindowTreeClientDestroyed(). |
| 951 EXPECT_FALSE(test_->window_tree_client_destroyed()); |
| 956 } | 952 } |
| 957 | 953 |
| 958 WindowServerTestBase* test_; | 954 WindowServerTestBase* test_; |
| 959 Window* window_; | 955 Window* window_; |
| 960 bool* got_destroy_; | 956 bool* got_destroy_; |
| 961 | 957 |
| 962 DISALLOW_COPY_AND_ASSIGN(DestroyedChangedObserver); | 958 DISALLOW_COPY_AND_ASSIGN(DestroyedChangedObserver); |
| 963 }; | 959 }; |
| 964 | 960 |
| 965 } // namespace | 961 } // namespace |
| 966 | 962 |
| 967 // Verifies deleting a WindowServer sends the right notifications. | 963 // Verifies deleting a WindowServer sends the right notifications. |
| 968 TEST_F(WindowServerTest, DeleteWindowServer) { | 964 TEST_F(WindowServerTest, DeleteWindowServer) { |
| 969 Window* window = window_manager()->NewWindow(); | 965 Window* window = window_manager()->NewWindow(); |
| 970 ASSERT_NE(nullptr, window); | 966 ASSERT_NE(nullptr, window); |
| 971 window->SetVisible(true); | 967 window->SetVisible(true); |
| 972 GetFirstWMRoot()->AddChild(window); | 968 GetFirstWMRoot()->AddChild(window); |
| 973 WindowTreeConnection* connection = Embed(window).connection; | 969 WindowTreeClient* client = Embed(window).client; |
| 974 ASSERT_TRUE(connection); | 970 ASSERT_TRUE(client); |
| 975 bool got_destroy = false; | 971 bool got_destroy = false; |
| 976 DestroyedChangedObserver observer(this, GetFirstRoot(connection), | 972 DestroyedChangedObserver observer(this, GetFirstRoot(client), |
| 977 &got_destroy); | 973 &got_destroy); |
| 978 delete connection; | 974 delete client; |
| 979 EXPECT_TRUE(window_tree_connection_destroyed()); | 975 EXPECT_TRUE(window_tree_client_destroyed()); |
| 980 EXPECT_TRUE(got_destroy); | 976 EXPECT_TRUE(got_destroy); |
| 981 } | 977 } |
| 982 | 978 |
| 983 // Verifies two Embed()s in the same window trigger deletion of the first | 979 // Verifies two Embed()s in the same window trigger deletion of the first |
| 984 // WindowServer. | 980 // WindowServer. |
| 985 TEST_F(WindowServerTest, DisconnectTriggersDelete) { | 981 TEST_F(WindowServerTest, DisconnectTriggersDelete) { |
| 986 Window* window = window_manager()->NewWindow(); | 982 Window* window = window_manager()->NewWindow(); |
| 987 ASSERT_NE(nullptr, window); | 983 ASSERT_NE(nullptr, window); |
| 988 window->SetVisible(true); | 984 window->SetVisible(true); |
| 989 GetFirstWMRoot()->AddChild(window); | 985 GetFirstWMRoot()->AddChild(window); |
| 990 WindowTreeConnection* connection = Embed(window).connection; | 986 WindowTreeClient* client = Embed(window).client; |
| 991 EXPECT_NE(connection, window_manager()); | 987 EXPECT_NE(client, window_manager()); |
| 992 Window* embedded_window = connection->NewWindow(); | 988 Window* embedded_window = client->NewWindow(); |
| 993 // Embed again, this should trigger disconnect and deletion of connection. | 989 // Embed again, this should trigger disconnect and deletion of client. |
| 994 bool got_destroy; | 990 bool got_destroy; |
| 995 DestroyedChangedObserver observer(this, embedded_window, &got_destroy); | 991 DestroyedChangedObserver observer(this, embedded_window, &got_destroy); |
| 996 EXPECT_FALSE(window_tree_connection_destroyed()); | 992 EXPECT_FALSE(window_tree_client_destroyed()); |
| 997 Embed(window); | 993 Embed(window); |
| 998 EXPECT_TRUE(window_tree_connection_destroyed()); | 994 EXPECT_TRUE(window_tree_client_destroyed()); |
| 999 } | 995 } |
| 1000 | 996 |
| 1001 class WindowRemovedFromParentObserver : public WindowObserver { | 997 class WindowRemovedFromParentObserver : public WindowObserver { |
| 1002 public: | 998 public: |
| 1003 explicit WindowRemovedFromParentObserver(Window* window) | 999 explicit WindowRemovedFromParentObserver(Window* window) |
| 1004 : window_(window), was_removed_(false) { | 1000 : window_(window), was_removed_(false) { |
| 1005 window_->AddObserver(this); | 1001 window_->AddObserver(this); |
| 1006 } | 1002 } |
| 1007 ~WindowRemovedFromParentObserver() override { window_->RemoveObserver(this); } | 1003 ~WindowRemovedFromParentObserver() override { window_->RemoveObserver(this); } |
| 1008 | 1004 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1037 // we may end up reconnecting to the test and rerunning the test, which is | 1033 // we may end up reconnecting to the test and rerunning the test, which is |
| 1038 // problematic since the other services don't shut down. | 1034 // problematic since the other services don't shut down. |
| 1039 ASSERT_TRUE(DoRunLoopWithTimeout()); | 1035 ASSERT_TRUE(DoRunLoopWithTimeout()); |
| 1040 } | 1036 } |
| 1041 | 1037 |
| 1042 namespace { | 1038 namespace { |
| 1043 | 1039 |
| 1044 class DestroyObserver : public WindowObserver { | 1040 class DestroyObserver : public WindowObserver { |
| 1045 public: | 1041 public: |
| 1046 DestroyObserver(WindowServerTestBase* test, | 1042 DestroyObserver(WindowServerTestBase* test, |
| 1047 WindowTreeConnection* connection, | 1043 WindowTreeClient* client, |
| 1048 bool* got_destroy) | 1044 bool* got_destroy) |
| 1049 : test_(test), got_destroy_(got_destroy) { | 1045 : test_(test), got_destroy_(got_destroy) { |
| 1050 GetFirstRoot(connection)->AddObserver(this); | 1046 GetFirstRoot(client)->AddObserver(this); |
| 1051 } | 1047 } |
| 1052 ~DestroyObserver() override {} | 1048 ~DestroyObserver() override {} |
| 1053 | 1049 |
| 1054 private: | 1050 private: |
| 1055 // Overridden from WindowObserver: | 1051 // Overridden from WindowObserver: |
| 1056 void OnWindowDestroyed(Window* window) override { | 1052 void OnWindowDestroyed(Window* window) override { |
| 1057 *got_destroy_ = true; | 1053 *got_destroy_ = true; |
| 1058 window->RemoveObserver(this); | 1054 window->RemoveObserver(this); |
| 1059 | 1055 |
| 1060 // We should always get OnWindowDestroyed() before | 1056 // We should always get OnWindowDestroyed() before |
| 1061 // OnWindowManagerDestroyed(). | 1057 // OnWindowManagerDestroyed(). |
| 1062 EXPECT_FALSE(test_->window_tree_connection_destroyed()); | 1058 EXPECT_FALSE(test_->window_tree_client_destroyed()); |
| 1063 | 1059 |
| 1064 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); | 1060 EXPECT_TRUE(WindowServerTestBase::QuitRunLoop()); |
| 1065 } | 1061 } |
| 1066 | 1062 |
| 1067 WindowServerTestBase* test_; | 1063 WindowServerTestBase* test_; |
| 1068 bool* got_destroy_; | 1064 bool* got_destroy_; |
| 1069 | 1065 |
| 1070 DISALLOW_COPY_AND_ASSIGN(DestroyObserver); | 1066 DISALLOW_COPY_AND_ASSIGN(DestroyObserver); |
| 1071 }; | 1067 }; |
| 1072 | 1068 |
| 1073 } // namespace | 1069 } // namespace |
| 1074 | 1070 |
| 1075 // Verifies deleting a Window that is the root of another connection notifies | 1071 // Verifies deleting a Window that is the root of another client notifies |
| 1076 // observers in the right order (OnWindowDestroyed() before | 1072 // observers in the right order (OnWindowDestroyed() before |
| 1077 // OnWindowManagerDestroyed()). | 1073 // OnWindowManagerDestroyed()). |
| 1078 TEST_F(WindowServerTest, WindowServerDestroyedAfterRootObserver) { | 1074 TEST_F(WindowServerTest, WindowServerDestroyedAfterRootObserver) { |
| 1079 Window* embed_window = window_manager()->NewWindow(); | 1075 Window* embed_window = window_manager()->NewWindow(); |
| 1080 GetFirstWMRoot()->AddChild(embed_window); | 1076 GetFirstWMRoot()->AddChild(embed_window); |
| 1081 | 1077 |
| 1082 WindowTreeConnection* embedded_connection = Embed(embed_window).connection; | 1078 WindowTreeClient* embedded_client = Embed(embed_window).client; |
| 1083 | 1079 |
| 1084 bool got_destroy = false; | 1080 bool got_destroy = false; |
| 1085 DestroyObserver observer(this, embedded_connection, &got_destroy); | 1081 DestroyObserver observer(this, embedded_client, &got_destroy); |
| 1086 // Delete the window |embedded_connection| is embedded in. This is async, | 1082 // Delete the window |embedded_client| is embedded in. This is async, |
| 1087 // but will eventually trigger deleting |embedded_connection|. | 1083 // but will eventually trigger deleting |embedded_client|. |
| 1088 embed_window->Destroy(); | 1084 embed_window->Destroy(); |
| 1089 EXPECT_TRUE(DoRunLoopWithTimeout()); | 1085 EXPECT_TRUE(DoRunLoopWithTimeout()); |
| 1090 EXPECT_TRUE(got_destroy); | 1086 EXPECT_TRUE(got_destroy); |
| 1091 } | 1087 } |
| 1092 | 1088 |
| 1093 TEST_F(WindowServerTest, ClientAreaChanged) { | 1089 TEST_F(WindowServerTest, ClientAreaChanged) { |
| 1094 Window* embed_window = window_manager()->NewWindow(); | 1090 Window* embed_window = window_manager()->NewWindow(); |
| 1095 GetFirstWMRoot()->AddChild(embed_window); | 1091 GetFirstWMRoot()->AddChild(embed_window); |
| 1096 | 1092 |
| 1097 WindowTreeConnection* embedded_connection = Embed(embed_window).connection; | 1093 WindowTreeClient* embedded_client = Embed(embed_window).client; |
| 1098 | 1094 |
| 1099 // Verify change from embedded makes it to parent. | 1095 // Verify change from embedded makes it to parent. |
| 1100 GetFirstRoot(embedded_connection)->SetClientArea(gfx::Insets(1, 2, 3, 4)); | 1096 GetFirstRoot(embedded_client)->SetClientArea(gfx::Insets(1, 2, 3, 4)); |
| 1101 ASSERT_TRUE(WaitForClientAreaToChange(embed_window)); | 1097 ASSERT_TRUE(WaitForClientAreaToChange(embed_window)); |
| 1102 EXPECT_TRUE(gfx::Insets(1, 2, 3, 4) == embed_window->client_area()); | 1098 EXPECT_TRUE(gfx::Insets(1, 2, 3, 4) == embed_window->client_area()); |
| 1103 | 1099 |
| 1104 // Changing bounds shouldn't effect client area. | 1100 // Changing bounds shouldn't effect client area. |
| 1105 embed_window->SetBounds(gfx::Rect(21, 22, 23, 24)); | 1101 embed_window->SetBounds(gfx::Rect(21, 22, 23, 24)); |
| 1106 WaitForBoundsToChange(GetFirstRoot(embedded_connection)); | 1102 WaitForBoundsToChange(GetFirstRoot(embedded_client)); |
| 1107 EXPECT_TRUE(gfx::Rect(21, 22, 23, 24) == | 1103 EXPECT_TRUE(gfx::Rect(21, 22, 23, 24) == |
| 1108 GetFirstRoot(embedded_connection)->bounds()); | 1104 GetFirstRoot(embedded_client)->bounds()); |
| 1109 EXPECT_TRUE(gfx::Insets(1, 2, 3, 4) == | 1105 EXPECT_TRUE(gfx::Insets(1, 2, 3, 4) == |
| 1110 GetFirstRoot(embedded_connection)->client_area()); | 1106 GetFirstRoot(embedded_client)->client_area()); |
| 1111 } | 1107 } |
| 1112 | 1108 |
| 1113 class EstablishConnectionViaFactoryDelegate : public TestWindowManagerDelegate { | 1109 class EstablishConnectionViaFactoryDelegate : public TestWindowManagerDelegate { |
| 1114 public: | 1110 public: |
| 1115 explicit EstablishConnectionViaFactoryDelegate( | 1111 explicit EstablishConnectionViaFactoryDelegate( |
| 1116 WindowTreeConnection* connection) | 1112 WindowTreeClient* client) |
| 1117 : connection_(connection), run_loop_(nullptr), created_window_(nullptr) {} | 1113 : client_(client), run_loop_(nullptr), created_window_(nullptr) {} |
| 1118 ~EstablishConnectionViaFactoryDelegate() override {} | 1114 ~EstablishConnectionViaFactoryDelegate() override {} |
| 1119 | 1115 |
| 1120 bool QuitOnCreate() { | 1116 bool QuitOnCreate() { |
| 1121 if (run_loop_) | 1117 if (run_loop_) |
| 1122 return false; | 1118 return false; |
| 1123 | 1119 |
| 1124 created_window_ = nullptr; | 1120 created_window_ = nullptr; |
| 1125 run_loop_.reset(new base::RunLoop); | 1121 run_loop_.reset(new base::RunLoop); |
| 1126 run_loop_->Run(); | 1122 run_loop_->Run(); |
| 1127 run_loop_.reset(); | 1123 run_loop_.reset(); |
| 1128 return created_window_ != nullptr; | 1124 return created_window_ != nullptr; |
| 1129 } | 1125 } |
| 1130 | 1126 |
| 1131 Window* created_window() { return created_window_; } | 1127 Window* created_window() { return created_window_; } |
| 1132 | 1128 |
| 1133 // WindowManagerDelegate: | 1129 // WindowManagerDelegate: |
| 1134 Window* OnWmCreateTopLevelWindow( | 1130 Window* OnWmCreateTopLevelWindow( |
| 1135 std::map<std::string, std::vector<uint8_t>>* properties) override { | 1131 std::map<std::string, std::vector<uint8_t>>* properties) override { |
| 1136 created_window_ = connection_->NewWindow(properties); | 1132 created_window_ = client_->NewWindow(properties); |
| 1137 (*connection_->GetRoots().begin())->AddChild(created_window_); | 1133 (*client_->GetRoots().begin())->AddChild(created_window_); |
| 1138 if (run_loop_) | 1134 if (run_loop_) |
| 1139 run_loop_->Quit(); | 1135 run_loop_->Quit(); |
| 1140 return created_window_; | 1136 return created_window_; |
| 1141 } | 1137 } |
| 1142 | 1138 |
| 1143 private: | 1139 private: |
| 1144 WindowTreeConnection* connection_; | 1140 WindowTreeClient* client_; |
| 1145 std::unique_ptr<base::RunLoop> run_loop_; | 1141 std::unique_ptr<base::RunLoop> run_loop_; |
| 1146 Window* created_window_; | 1142 Window* created_window_; |
| 1147 | 1143 |
| 1148 DISALLOW_COPY_AND_ASSIGN(EstablishConnectionViaFactoryDelegate); | 1144 DISALLOW_COPY_AND_ASSIGN(EstablishConnectionViaFactoryDelegate); |
| 1149 }; | 1145 }; |
| 1150 | 1146 |
| 1151 TEST_F(WindowServerTest, EstablishConnectionViaFactory) { | 1147 TEST_F(WindowServerTest, EstablishConnectionViaFactory) { |
| 1152 EstablishConnectionViaFactoryDelegate delegate(window_manager()); | 1148 EstablishConnectionViaFactoryDelegate delegate(window_manager()); |
| 1153 set_window_manager_delegate(&delegate); | 1149 set_window_manager_delegate(&delegate); |
| 1154 std::unique_ptr<WindowTreeConnection> second_connection( | 1150 std::unique_ptr<WindowTreeClient> second_client( |
| 1155 WindowTreeConnection::Create(this, connector())); | 1151 new WindowTreeClient(this, nullptr, nullptr)); |
| 1156 Window* window_in_second_connection = | 1152 second_client->ConnectViaWindowTreeFactory(connector()); |
| 1157 second_connection->NewTopLevelWindow(nullptr); | 1153 Window* window_in_second_client = |
| 1158 ASSERT_TRUE(window_in_second_connection); | 1154 second_client->NewTopLevelWindow(nullptr); |
| 1159 ASSERT_TRUE(second_connection->GetRoots().count(window_in_second_connection) > | 1155 ASSERT_TRUE(window_in_second_client); |
| 1156 ASSERT_TRUE(second_client->GetRoots().count(window_in_second_client) > |
| 1160 0); | 1157 0); |
| 1161 // Wait for the window to appear in the wm. | 1158 // Wait for the window to appear in the wm. |
| 1162 ASSERT_TRUE(delegate.QuitOnCreate()); | 1159 ASSERT_TRUE(delegate.QuitOnCreate()); |
| 1163 | 1160 |
| 1164 Window* window_in_wm = delegate.created_window(); | 1161 Window* window_in_wm = delegate.created_window(); |
| 1165 ASSERT_TRUE(window_in_wm); | 1162 ASSERT_TRUE(window_in_wm); |
| 1166 | 1163 |
| 1167 // Change the bounds in the wm, and make sure the child sees it. | 1164 // Change the bounds in the wm, and make sure the child sees it. |
| 1168 window_in_wm->SetBounds(gfx::Rect(1, 11, 12, 101)); | 1165 window_in_wm->SetBounds(gfx::Rect(1, 11, 12, 101)); |
| 1169 ASSERT_TRUE(WaitForBoundsToChange(window_in_second_connection)); | 1166 ASSERT_TRUE(WaitForBoundsToChange(window_in_second_client)); |
| 1170 EXPECT_EQ(gfx::Rect(1, 11, 12, 101), window_in_second_connection->bounds()); | 1167 EXPECT_EQ(gfx::Rect(1, 11, 12, 101), window_in_second_client->bounds()); |
| 1171 } | 1168 } |
| 1172 | 1169 |
| 1173 } // namespace ws | 1170 } // namespace ws |
| 1174 } // namespace mus | 1171 } // namespace mus |
| OLD | NEW |