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

Unified Diff: ash/wm/workspace/workspace_layout_manager_unittest.cc

Issue 2884623002: Refactor backdrop (Closed)
Patch Set: Generalize Backdrop Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ash/wm/workspace/workspace_layout_manager_unittest.cc
diff --git a/ash/wm/workspace/workspace_layout_manager_unittest.cc b/ash/wm/workspace/workspace_layout_manager_unittest.cc
index 5ef8fe99d7b78012986b67cb051f4a26b1ca65db..5ea0aeb96ac694c06b60482ea259ebf445bce3aa 100644
--- a/ash/wm/workspace/workspace_layout_manager_unittest.cc
+++ b/ash/wm/workspace/workspace_layout_manager_unittest.cc
@@ -7,6 +7,7 @@
#include <string>
#include <utility>
+#include "ash/accessibility_delegate.h"
#include "ash/public/cpp/config.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
@@ -18,22 +19,31 @@
#include "ash/shell.h"
#include "ash/shell_observer.h"
#include "ash/shell_port.h"
+#include "ash/system/tray/system_tray_notifier.h"
#include "ash/test/ash_test_base.h"
+#include "ash/test/shell_test_api.h"
+#include "ash/test/test_accessibility_delegate.h"
#include "ash/test/test_session_controller_client.h"
#include "ash/test/wm_window_test_api.h"
+#include "ash/test/workspace_controller_test_api.h"
#include "ash/wm/fullscreen_window_finder.h"
-#include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
+#include "ash/wm/maximize_mode/maximize_mode_backdrop_delegate_impl.h"
+#include "ash/wm/overview/window_selector_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_aura.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
+#include "ash/wm/workspace/backdrop_delegate.h"
#include "ash/wm/workspace/workspace_window_resizer.h"
#include "ash/wm_window.h"
#include "base/command_line.h"
#include "base/run_loop.h"
+#include "chromeos/audio/chromeos_sounds.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/focus_client.h"
+#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
+#include "ui/aura/window_targeter.h"
#include "ui/base/ui_base_switches.h"
#include "ui/base/ui_base_types.h"
#include "ui/compositor/layer_type.h"
@@ -42,6 +52,8 @@
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
#include "ui/display/test/display_manager_test_api.h"
+#include "ui/events/base_event_utils.h"
+#include "ui/events/test/event_generator.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
@@ -948,13 +960,12 @@ class WorkspaceLayoutManagerBackdropTest : public test::AshTestBase {
// Turn the top window back drop on / off.
void ShowTopWindowBackdrop(bool show) {
- std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> backdrop;
+ std::unique_ptr<BackdropDelegate> backdrop;
if (show) {
- backdrop.reset(
- new WorkspaceBackdropDelegate(WmWindow::Get(default_container_)));
+ backdrop = base::MakeUnique<MaximizeModeBackdropDelegateImpl>();
}
GetWorkspaceLayoutManager(default_container_)
- ->SetMaximizeBackdropDelegate(std::move(backdrop));
+ ->SetBackdropDelegate(std::move(backdrop));
// Closing and / or opening can be a delayed operation.
base::RunLoop().RunUntilIdle();
}
@@ -1006,12 +1017,9 @@ TEST_F(WorkspaceLayoutManagerBackdropTest, BackdropCrashTest) {
// Verify basic assumptions about the backdrop.
TEST_F(WorkspaceLayoutManagerBackdropTest, BasicBackdropTests) {
- // Create a backdrop and see that there is one window (the backdrop) and
- // that the size is the same as the default container as well as that it is
- // not visible.
+ // THe background widget will be created when there is a window.
James Cook 2017/05/15 21:57:39 nit: THe -> The
oshima 2017/05/16 08:22:09 Done.
ShowTopWindowBackdrop(true);
- ASSERT_EQ(1U, default_container()->children().size());
- EXPECT_FALSE(default_container()->children()[0]->IsVisible());
+ ASSERT_EQ(0U, default_container()->children().size());
James Cook 2017/05/15 21:57:39 super-nit: 0u
oshima 2017/05/16 08:22:09 Done.
{
// Add a window and make sure that the backdrop is the second child.
@@ -1098,7 +1106,11 @@ TEST_F(WorkspaceLayoutManagerBackdropTest,
const gfx::Size fullscreen_size =
display::Screen::GetScreen()->GetPrimaryDisplay().size();
+ std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4)));
+ window->Show();
+
ASSERT_EQ(SHELF_VISIBLE, shelf_layout_manager->visibility_state());
+
EXPECT_EQ(fullscreen_size,
default_container()->children()[0]->bounds().size());
shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
@@ -1273,4 +1285,190 @@ TEST_F(WorkspaceLayoutManagerKeyboardTest, IgnoreKeyboardBoundsChange) {
EXPECT_EQ(keyboard_bounds(), window->bounds());
}
+TEST_F(WorkspaceLayoutManagerKeyboardTest, BackdropTest) {
James Cook 2017/05/15 21:57:39 Can you either move the backdrop tests to someplac
oshima 2017/05/16 08:22:09 This test already have tests for backdrop, and I'm
+ WorkspaceController* wc =
+ test::ShellTestApi(Shell::Get()).workspace_controller();
+ test::WorkspaceControllerTestApi test_helper(wc);
+
+ std::unique_ptr<aura::Window> window1(
+ CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
+ window1->SetName("1");
+ window1->Show();
+ std::unique_ptr<aura::Window> window2(
+ CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
+ window2->SetName("2");
+ window2->Show();
+ std::unique_ptr<aura::Window> window3(
+ CreateTestWindow(gfx::Rect(0, 0, 100, 100)));
+ window3->SetName("3");
+ window3->Show();
+ EXPECT_FALSE(test_helper.GetBackdropWindow());
+
+ window2->SetProperty(aura::client::kHasBackdrop, true);
+ aura::Window* backdrop = test_helper.GetBackdropWindow();
+ EXPECT_TRUE(test_helper.GetBackdropWindow());
James Cook 2017/05/15 21:57:39 EXPECT_TRUE(backdrop)
oshima 2017/05/16 08:22:09 Done.
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], window1.get());
+ EXPECT_EQ(children[1], backdrop);
+ EXPECT_EQ(children[2], window2.get());
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ // Setting the property to the one below the backdrop window shouldn't change
+ // the state.
+ window1->SetProperty(aura::client::kHasBackdrop, true);
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], window1.get());
+ EXPECT_EQ(children[1], backdrop);
+ EXPECT_EQ(children[2], window2.get());
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ // Setting the property to the top will move the backdrop up.
+ window3->SetProperty(aura::client::kHasBackdrop, true);
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], window1.get());
+ EXPECT_EQ(children[1], window2.get());
+ EXPECT_EQ(children[2], backdrop);
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ // Claring the property in the middle will not change the backdrop position.
James Cook 2017/05/15 21:57:39 Clearing
oshima 2017/05/16 08:22:09 Done.
+ window2->ClearProperty(aura::client::kHasBackdrop);
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], window1.get());
+ EXPECT_EQ(children[1], window2.get());
+ EXPECT_EQ(children[2], backdrop);
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ // Claring the property on tpo will move the backdrop to bottom.
James Cook 2017/05/15 21:57:40 ditto, and tpo -> top
oshima 2017/05/16 08:22:09 Done.
+ window3->ClearProperty(aura::client::kHasBackdrop);
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], backdrop);
+ EXPECT_EQ(children[1], window1.get());
+ EXPECT_EQ(children[2], window2.get());
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ // Toggle overview
James Cook 2017/05/15 21:57:39 super nit: end with .
oshima 2017/05/16 08:22:09 Done.
+ Shell::Get()->window_selector_controller()->ToggleOverview();
+ RunAllPendingInMessageLoop();
+ EXPECT_FALSE(test_helper.GetBackdropWindow());
+
+ Shell::Get()->window_selector_controller()->ToggleOverview();
+ RunAllPendingInMessageLoop();
+ backdrop = test_helper.GetBackdropWindow();
+ EXPECT_TRUE(backdrop);
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], backdrop);
+ EXPECT_EQ(children[1], window1.get());
+ EXPECT_EQ(children[2], window2.get());
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ wc->SetBackdropDelegate(base::MakeUnique<MaximizeModeBackdropDelegateImpl>());
James Cook 2017/05/15 21:57:39 nit: Comment what you're testing here.
oshima 2017/05/16 08:22:09 Done.
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], window1.get());
+ EXPECT_EQ(children[1], window2.get());
+ EXPECT_EQ(children[2], backdrop);
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ // Toggle overview with the delegate
James Cook 2017/05/15 21:57:39 super nit: end with .
oshima 2017/05/16 08:22:09 Done.
+ Shell::Get()->window_selector_controller()->ToggleOverview();
+ RunAllPendingInMessageLoop();
+ EXPECT_FALSE(test_helper.GetBackdropWindow());
+ Shell::Get()->window_selector_controller()->ToggleOverview();
+ RunAllPendingInMessageLoop();
+ backdrop = test_helper.GetBackdropWindow();
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], window1.get());
+ EXPECT_EQ(children[1], window2.get());
+ EXPECT_EQ(children[2], backdrop);
+ EXPECT_EQ(children[3], window3.get());
+ }
+
+ // Removing the delegate will move the backdrop back to window1.
+ std::unique_ptr<BackdropDelegate> no_delegate;
+ wc->SetBackdropDelegate(std::move(no_delegate));
+ {
+ aura::Window::Windows children = window1->parent()->children();
+ EXPECT_EQ(children[0], backdrop);
+ EXPECT_EQ(children[1], window1.get());
+ EXPECT_EQ(children[2], window2.get());
+ EXPECT_EQ(children[3], window3.get());
+ }
+}
+
+TEST_F(WorkspaceLayoutManagerKeyboardTest, SpokenFeedbackFullscreenBackground) {
+ constexpr int kNoSoundKey = -1;
+
+ WorkspaceController* wc =
+ test::ShellTestApi(Shell::Get()).workspace_controller();
+ test::WorkspaceControllerTestApi test_helper(wc);
+ test::TestAccessibilityDelegate* accessibility_delegate =
+ static_cast<test::TestAccessibilityDelegate*>(
+ Shell::Get()->accessibility_delegate());
+
+ aura::test::TestWindowDelegate delegate;
+ std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
+ &delegate, 0, gfx::Rect(0, 0, 100, 100)));
+ window->Show();
+
+ window->SetProperty(aura::client::kHasBackdrop, true);
+ EXPECT_TRUE(test_helper.GetBackdropWindow());
+
+ ui::test::EventGenerator& generator = GetEventGenerator();
+
+ generator.MoveMouseTo(300, 300);
+ generator.ClickLeftButton();
+ EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
+
+ generator.MoveMouseRelativeTo(window.get(), 10, 10);
+ generator.ClickLeftButton();
+ EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
+
+ // Enable spoken feedback.
+ Shell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
+ ash::A11Y_NOTIFICATION_NONE);
+ Shell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged(
+ ash::A11Y_NOTIFICATION_NONE);
+ EXPECT_TRUE(
+ Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled());
+
+ generator.MoveMouseTo(300, 300);
+ generator.ClickLeftButton();
+ EXPECT_EQ(chromeos::SOUND_VOLUME_ADJUST,
+ accessibility_delegate->GetPlayedEarconAndReset());
+
+ generator.MoveMouseRelativeTo(window.get(), 10, 10);
+ generator.ClickLeftButton();
+ EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
+
+ // Disable spoken feedback. Shadow underlay is restored.
+ Shell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
+ A11Y_NOTIFICATION_NONE);
+ Shell::Get()->system_tray_notifier()->NotifyAccessibilityModeChanged(
+ A11Y_NOTIFICATION_NONE);
+ EXPECT_FALSE(
+ Shell::Get()->accessibility_delegate()->IsSpokenFeedbackEnabled());
+
+ generator.MoveMouseTo(300, 300);
+ generator.ClickLeftButton();
+ EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
+
+ generator.MoveMouseTo(70, 70);
+ generator.ClickLeftButton();
+ EXPECT_EQ(kNoSoundKey, accessibility_delegate->GetPlayedEarconAndReset());
+}
James Cook 2017/05/15 21:57:39 Thanks for adding the test coverage!
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698