chromium/extensions/shell/browser/shell_desktop_controller_aura_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/shell/browser/shell_desktop_controller_aura.h"

#include <memory>

#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_client.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/app_window/native_app_window.h"
#include "extensions/browser/app_window/test_app_window_contents.h"
#include "extensions/common/extension_builder.h"
#include "extensions/shell/browser/shell_app_delegate.h"
#include "extensions/shell/test/shell_test_base_aura.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/dummy_text_input_client.h"
#include "ui/base/ime/init/input_method_factory.h"
#include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_minimal.h"
#include "ui/display/display.h"
#include "ui/display/screen_base.h"
#include "ui/events/event.h"
#include "ui/events/event_dispatcher.h"
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/rect.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/dbus/power/fake_power_manager_client.h"
#endif

#if BUILDFLAG(IS_OZONE)
#include "ui/events/ozone/events_ozone.h"
#endif

namespace extensions {

class ShellDesktopControllerAuraTest : public ShellTestBaseAura {};

#if BUILDFLAG(IS_CHROMEOS_ASH)
// Tests that a shutdown request is sent to the power manager when the power
// button is pressed.
TEST_F(ShellDesktopControllerAuraTest, PowerButton) {
  // Ignore button releases.
  auto* power_manager_client = chromeos::FakePowerManagerClient::Get();
  power_manager_client->SendPowerButtonEvent(false /* down */,
                                             base::TimeTicks());
  EXPECT_EQ(0, power_manager_client->num_request_shutdown_calls());

  // A button press should trigger a shutdown request.
  power_manager_client->SendPowerButtonEvent(true /* down */,
                                             base::TimeTicks());
  EXPECT_EQ(1, power_manager_client->num_request_shutdown_calls());
}
#endif

// Tests that basic input events are handled and forwarded to the host.
// TODO(michaelpg): Test other types of input.
// Flaky on Linux dbg.  http://crbug.com/1516907
#if BUILDFLAG(IS_LINUX) && !defined(NDEBUG)
#define MAYBE_InputEvents
#else
#define MAYBE_InputEvents
#endif
TEST_F(ShellDesktopControllerAuraTest, MAYBE_InputEvents) {}

// Tests closing all AppWindows.
TEST_F(ShellDesktopControllerAuraTest, CloseAppWindows) {}

// Tests that the AppWindows are removed when the desktop controller goes away.
TEST_F(ShellDesktopControllerAuraTest, OnAppWindowClose) {}

// Tests that multiple displays result in multiple root windows.
TEST_F(ShellDesktopControllerAuraTest, MultipleDisplays) {}

}  // namespace extensions