Commit 41b5497b authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: gets more ash_unittests working with single-process mash

The OverviewButtonTrayTests need to set the keyboard devices *after*
AshTestBase::SetUp() is called. This is is important in single-process mash
as Ash is the one creating the Env that the keyboard devices us. In
non-single-process-mash AshTestSuite is creating the Env these tests use.

The case ShellTest2.DontCrashWhenWindowDeleted is exercising is different
enough for single-process mash that I created a separate test.

Adding NOPRESUBMIT=true as this bot passed the trybots, and we're ok with
this test including Env::GetInstance().

NOPRESUBMIT=true

BUG=847992
TEST=test only changes

Change-Id: I0543db96ca9aa910340360d8da3e6aafcda34d7f
Reviewed-on: https://chromium-review.googlesource.com/1174978
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583161}
parent ad99c323
......@@ -34,9 +34,12 @@
#include "components/prefs/testing_pref_service.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/test/mus/test_window_tree_client_delegate.h"
#include "ui/aura/test/mus/test_window_tree_client_setup.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/models/simple_menu_model.h"
#include "ui/base/ui_base_features.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/test/events_test_utils.h"
#include "ui/events/test/test_event_handler.h"
......@@ -586,6 +589,59 @@ class ShellTest2 : public AshTestBase {
};
TEST_F(ShellTest2, DontCrashWhenWindowDeleted) {
// DontCrashWhenWindowDeletedSingleProcess covers the SingleProcessMash case.
if (::features::IsSingleProcessMash())
return;
window_ = std::make_unique<aura::Window>(nullptr,
aura::client::WINDOW_TYPE_UNKNOWN);
window_->Init(ui::LAYER_NOT_DRAWN);
}
// This verifies WindowObservers are removed when a window is destroyed after
// the Shell is destroyed. This scenario (aura::Windows being deleted after the
// Shell) occurs if someone is holding a reference to an unparented Window, as
// is the case with a RenderWidgetHostViewAura that isn't on screen. As long as
// everything is ok, we won't crash. If there is a bug, window's destructor will
// notify some deleted object (say VideoDetector or ActivationController) and
// this will crash.
class ShellTest3 : public AshTestBase {
public:
ShellTest3() = default;
~ShellTest3() override = default;
void SetUp() override {
AshTestBase::SetUp();
if (!::features::IsSingleProcessMash())
return;
window_service_setup_ = std::make_unique<aura::TestWindowTreeClientSetup>();
window_service_setup_->InitWithoutEmbed(&test_window_tree_client_delegate_);
aura::Env::GetInstance()->SetWindowTreeClient(
window_service_setup_->window_tree_client());
}
void TearDown() override {
AshTestBase::TearDown();
if (!::features::IsSingleProcessMash())
return;
window_.reset();
window_service_setup_.reset();
aura::Env::GetInstance()->SetWindowTreeClient(nullptr);
}
protected:
std::unique_ptr<aura::Window> window_;
private:
aura::TestWindowTreeClientDelegate test_window_tree_client_delegate_;
std::unique_ptr<aura::TestWindowTreeClientSetup> window_service_setup_;
DISALLOW_COPY_AND_ASSIGN(ShellTest3);
};
TEST_F(ShellTest3, DontCrashWhenWindowDeletedSingleProcess) {
if (!::features::IsSingleProcessMash())
return;
// This test explicitly uses aura::Env::GetInstance() rather than
// Shell->aura_env() as the Window outlives the Shell. In order for a Window
// to outlive Shell the Window must be created outside of Ash, which uses
......
......@@ -77,11 +77,11 @@ class OverviewButtonTrayTest : public AshTestBase {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
::switches::kUseFirstDisplayAsInternal);
AshTestBase::SetUp();
ui::InputDeviceClientTestApi().SetKeyboardDevices({ui::InputDevice(
3, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "keyboard")});
base::RunLoop().RunUntilIdle();
AshTestBase::SetUp();
}
// Enters or exits tablet mode. Use these instead of
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment