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

Side by Side Diff: components/exo/shell_surface_unittest.cc

Issue 2360533002: exo: Implement minimal support for version 6 of XDG shell. (Closed)
Patch Set: fix bad rebase and unit tests 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 | « components/exo/shell_surface.cc ('k') | components/exo/wayland/server.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 "ash/common/accessibility_delegate.h" 5 #include "ash/common/accessibility_delegate.h"
6 #include "ash/common/wm/window_state.h" 6 #include "ash/common/wm/window_state.h"
7 #include "ash/common/wm/wm_event.h" 7 #include "ash/common/wm/wm_event.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "ash/common/wm_window.h" 9 #include "ash/common/wm_window.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 TEST_F(ShellSurfaceTest, SetTitle) { 204 TEST_F(ShellSurfaceTest, SetTitle) {
205 std::unique_ptr<Surface> surface(new Surface); 205 std::unique_ptr<Surface> surface(new Surface);
206 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 206 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
207 207
208 shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test"))); 208 shell_surface->SetTitle(base::string16(base::ASCIIToUTF16("test")));
209 surface->Commit(); 209 surface->Commit();
210 } 210 }
211 211
212 TEST_F(ShellSurfaceTest, SetApplicationId) { 212 TEST_F(ShellSurfaceTest, SetApplicationId) {
213 gfx::Size buffer_size(64, 64);
214 std::unique_ptr<Buffer> buffer(
215 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
213 std::unique_ptr<Surface> surface(new Surface); 216 std::unique_ptr<Surface> surface(new Surface);
214 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 217 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
215 218
216 EXPECT_EQ(nullptr, shell_surface->GetWidget()); 219 EXPECT_EQ(nullptr, shell_surface->GetWidget());
217 shell_surface->SetApplicationId("pre-widget-id"); 220 shell_surface->SetApplicationId("pre-widget-id");
218 221
222 surface->Attach(buffer.get());
219 surface->Commit(); 223 surface->Commit();
220 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); 224 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
221 EXPECT_EQ("pre-widget-id", ShellSurface::GetApplicationId(window)); 225 EXPECT_EQ("pre-widget-id", ShellSurface::GetApplicationId(window));
222 shell_surface->SetApplicationId("test"); 226 shell_surface->SetApplicationId("test");
223 EXPECT_EQ("test", ShellSurface::GetApplicationId(window)); 227 EXPECT_EQ("test", ShellSurface::GetApplicationId(window));
224 } 228 }
225 229
226 TEST_F(ShellSurfaceTest, Move) { 230 TEST_F(ShellSurfaceTest, Move) {
227 std::unique_ptr<Surface> surface(new Surface); 231 std::unique_ptr<Surface> surface(new Surface);
228 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 232 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 shell_surface->SetTopInset(top_inset_height); 309 shell_surface->SetTopInset(top_inset_height);
306 surface->Commit(); 310 surface->Commit();
307 EXPECT_EQ(top_inset_height, window->GetProperty(aura::client::kTopViewInset)); 311 EXPECT_EQ(top_inset_height, window->GetProperty(aura::client::kTopViewInset));
308 } 312 }
309 313
310 void Close(int* close_call_count) { 314 void Close(int* close_call_count) {
311 (*close_call_count)++; 315 (*close_call_count)++;
312 } 316 }
313 317
314 TEST_F(ShellSurfaceTest, CloseCallback) { 318 TEST_F(ShellSurfaceTest, CloseCallback) {
319 gfx::Size buffer_size(64, 64);
320 std::unique_ptr<Buffer> buffer(
321 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
315 std::unique_ptr<Surface> surface(new Surface); 322 std::unique_ptr<Surface> surface(new Surface);
316 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get())); 323 std::unique_ptr<ShellSurface> shell_surface(new ShellSurface(surface.get()));
317 324
318 int close_call_count = 0; 325 int close_call_count = 0;
319 shell_surface->set_close_callback( 326 shell_surface->set_close_callback(
320 base::Bind(&Close, base::Unretained(&close_call_count))); 327 base::Bind(&Close, base::Unretained(&close_call_count)));
321 328
329 surface->Attach(buffer.get());
322 surface->Commit(); 330 surface->Commit();
323 331
324 EXPECT_EQ(0, close_call_count); 332 EXPECT_EQ(0, close_call_count);
325 shell_surface->GetWidget()->Close(); 333 shell_surface->GetWidget()->Close();
326 EXPECT_EQ(1, close_call_count); 334 EXPECT_EQ(1, close_call_count);
327 335
328 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN); 336 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_W, ui::EF_CONTROL_DOWN);
329 shell_surface->GetWidget()->OnKeyEvent(&event); 337 shell_surface->GetWidget()->OnKeyEvent(&event);
330 EXPECT_EQ(2, close_call_count); 338 EXPECT_EQ(2, close_call_count);
331 } 339 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 498
491 // Popup position is fixed, and geometry is relative to it. 499 // Popup position is fixed, and geometry is relative to it.
492 EXPECT_EQ(gfx::Rect(parent_bounds.origin() + 500 EXPECT_EQ(gfx::Rect(parent_bounds.origin() +
493 popup_bounds.OffsetFromOrigin() + 501 popup_bounds.OffsetFromOrigin() +
494 geometry.OffsetFromOrigin(), 502 geometry.OffsetFromOrigin(),
495 geometry.size()), 503 geometry.size()),
496 popup->GetWidget()->GetWindowBoundsInScreen()); 504 popup->GetWidget()->GetWindowBoundsInScreen());
497 } 505 }
498 506
499 TEST_F(ShellSurfaceTest, Shadow) { 507 TEST_F(ShellSurfaceTest, Shadow) {
508 gfx::Size buffer_size(128, 128);
509 std::unique_ptr<Buffer> buffer(
510 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
500 std::unique_ptr<Surface> surface(new Surface); 511 std::unique_ptr<Surface> surface(new Surface);
501 std::unique_ptr<ShellSurface> shell_surface( 512 std::unique_ptr<ShellSurface> shell_surface(
502 new ShellSurface(surface.get(), nullptr, gfx::Rect(), true, false, 513 new ShellSurface(surface.get(), nullptr, gfx::Rect(), true, false,
503 ash::kShellWindowId_DefaultContainer)); 514 ash::kShellWindowId_DefaultContainer));
515 surface->Attach(buffer.get());
504 surface->Commit(); 516 surface->Commit();
505 517
506 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); 518 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
507 519
508 // 1) Initial state, no shadow. 520 // 1) Initial state, no shadow.
509 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 521 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
510 ASSERT_TRUE(shadow); 522 ASSERT_TRUE(shadow);
511 EXPECT_FALSE(shadow->layer()->visible()); 523 EXPECT_FALSE(shadow->layer()->visible());
512 524
513 std::unique_ptr<Display> display(new Display); 525 std::unique_ptr<Display> display(new Display);
514 526
515 // 2) Just creating a sub surface won't create a shadow. 527 // 2) Just creating a sub surface won't create a shadow.
516 std::unique_ptr<Surface> child = display->CreateSurface(); 528 std::unique_ptr<Surface> child = display->CreateSurface();
517 gfx::Size buffer_size(128, 128);
518 std::unique_ptr<Buffer> child_buffer( 529 std::unique_ptr<Buffer> child_buffer(
519 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); 530 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
520 child->Attach(child_buffer.get()); 531 child->Attach(child_buffer.get());
521 std::unique_ptr<SubSurface> sub_surface( 532 std::unique_ptr<SubSurface> sub_surface(
522 display->CreateSubSurface(child.get(), surface.get())); 533 display->CreateSubSurface(child.get(), surface.get()));
523 surface->Commit(); 534 surface->Commit();
524 535
525 EXPECT_FALSE(shadow->layer()->visible()); 536 EXPECT_FALSE(shadow->layer()->visible());
526 537
527 // 3) Create a shadow. 538 // 3) Create a shadow.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 // Shadow overlay should be stacked just above the shadow underlay. 574 // Shadow overlay should be stacked just above the shadow underlay.
564 auto underlay_it = 575 auto underlay_it =
565 std::find(window->children().begin(), window->children().end(), 576 std::find(window->children().begin(), window->children().end(),
566 shell_surface->shadow_underlay()); 577 shell_surface->shadow_underlay());
567 ASSERT_NE(underlay_it, window->children().end()); 578 ASSERT_NE(underlay_it, window->children().end());
568 ASSERT_NE(std::next(underlay_it), window->children().end()); 579 ASSERT_NE(std::next(underlay_it), window->children().end());
569 EXPECT_EQ(*std::next(underlay_it), shell_surface->shadow_overlay()); 580 EXPECT_EQ(*std::next(underlay_it), shell_surface->shadow_overlay());
570 } 581 }
571 582
572 TEST_F(ShellSurfaceTest, ShadowWithStateChange) { 583 TEST_F(ShellSurfaceTest, ShadowWithStateChange) {
584 gfx::Size buffer_size(64, 64);
585 std::unique_ptr<Buffer> buffer(
586 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
573 std::unique_ptr<Surface> surface(new Surface); 587 std::unique_ptr<Surface> surface(new Surface);
574 // Set the bounds to disable auto managed mode. 588 // Set the bounds to disable auto managed mode.
575 std::unique_ptr<ShellSurface> shell_surface( 589 std::unique_ptr<ShellSurface> shell_surface(
576 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false, 590 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 480), true, false,
577 ash::kShellWindowId_DefaultContainer)); 591 ash::kShellWindowId_DefaultContainer));
578 592
579 // Postion the widget at 10,10 so that we get non zero offset. 593 // Postion the widget at 10,10 so that we get non zero offset.
580 const gfx::Size content_size(100, 100); 594 const gfx::Size content_size(100, 100);
581 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size); 595 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
582 shell_surface->SetGeometry(original_bounds); 596 shell_surface->SetGeometry(original_bounds);
597 surface->Attach(buffer.get());
583 surface->Commit(); 598 surface->Commit();
584 599
585 // Placing a shadow at screen origin will make the shadow's origin (-10, -10). 600 // Placing a shadow at screen origin will make the shadow's origin (-10, -10).
586 const gfx::Rect shadow_bounds(content_size); 601 const gfx::Rect shadow_bounds(content_size);
587 602
588 // Expected shadow position/bounds in parent coordinates. 603 // Expected shadow position/bounds in parent coordinates.
589 const gfx::Point expected_shadow_origin(-10, -10); 604 const gfx::Point expected_shadow_origin(-10, -10);
590 const gfx::Rect expected_shadow_bounds(expected_shadow_origin, content_size); 605 const gfx::Rect expected_shadow_bounds(expected_shadow_origin, content_size);
591 606
592 views::Widget* widget = shell_surface->GetWidget(); 607 views::Widget* widget = shell_surface->GetWidget();
(...skipping 29 matching lines...) Expand all
622 const gfx::Rect shadow_in_maximized(expected_shadow_origin, work_area.size()); 637 const gfx::Rect shadow_in_maximized(expected_shadow_origin, work_area.size());
623 EXPECT_EQ(shadow_in_maximized, shadow->layer()->parent()->bounds()); 638 EXPECT_EQ(shadow_in_maximized, shadow->layer()->parent()->bounds());
624 639
625 // The bounds is updated. 640 // The bounds is updated.
626 shell_surface->SetRectangularShadowContentBounds(shadow_bounds); 641 shell_surface->SetRectangularShadowContentBounds(shadow_bounds);
627 surface->Commit(); 642 surface->Commit();
628 EXPECT_EQ(expected_shadow_bounds, shadow->layer()->parent()->bounds()); 643 EXPECT_EQ(expected_shadow_bounds, shadow->layer()->parent()->bounds());
629 } 644 }
630 645
631 TEST_F(ShellSurfaceTest, ShadowWithTransform) { 646 TEST_F(ShellSurfaceTest, ShadowWithTransform) {
647 gfx::Size buffer_size(64, 64);
648 std::unique_ptr<Buffer> buffer(
649 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size)));
632 std::unique_ptr<Surface> surface(new Surface); 650 std::unique_ptr<Surface> surface(new Surface);
633 // Set the bounds to disable auto managed mode. 651 // Set the bounds to disable auto managed mode.
634 std::unique_ptr<ShellSurface> shell_surface( 652 std::unique_ptr<ShellSurface> shell_surface(
635 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 400), true, false, 653 new ShellSurface(surface.get(), nullptr, gfx::Rect(640, 400), true, false,
636 ash::kShellWindowId_DefaultContainer)); 654 ash::kShellWindowId_DefaultContainer));
637 655
638 // Postion the widget at 10,10 so that we get non zero offset. 656 // Postion the widget at 10,10 so that we get non zero offset.
639 const gfx::Size content_size(100, 100); 657 const gfx::Size content_size(100, 100);
640 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size); 658 const gfx::Rect original_bounds(gfx::Point(10, 10), content_size);
641 shell_surface->SetGeometry(original_bounds); 659 shell_surface->SetGeometry(original_bounds);
660 surface->Attach(buffer.get());
642 surface->Commit(); 661 surface->Commit();
643 662
644 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow(); 663 aura::Window* window = shell_surface->GetWidget()->GetNativeWindow();
645 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 664 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
646 665
647 // Placing a shadow at screen origin will make the shadow's origin (-10, -10). 666 // Placing a shadow at screen origin will make the shadow's origin (-10, -10).
648 const gfx::Rect shadow_bounds(content_size); 667 const gfx::Rect shadow_bounds(content_size);
649 668
650 // Shadow bounds relative to its parent should not be affected by a transform. 669 // Shadow bounds relative to its parent should not be affected by a transform.
651 gfx::Transform transform; 670 gfx::Transform transform;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 shell_surface.OnAccessibilityModeChanged(); 851 shell_surface.OnAccessibilityModeChanged();
833 shell_surface2.OnAccessibilityModeChanged(); 852 shell_surface2.OnAccessibilityModeChanged();
834 853
835 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible()); 854 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible());
836 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds()); 855 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
837 EXPECT_EQ(shadow_bounds, shell_surface2.shadow_underlay()->bounds()); 856 EXPECT_EQ(shadow_bounds, shell_surface2.shadow_underlay()->bounds());
838 } 857 }
839 858
840 } // namespace 859 } // namespace
841 } // namespace exo 860 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.cc ('k') | components/exo/wayland/server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698