Skip to content

Commit

Permalink
Misc. cleanup for ui/
Browse files Browse the repository at this point in the history
Found while working on AshTestHelper.

Bug: none
Change-Id: Ib5baffa110d86fbd83e646268644330e169b0e98
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2125394
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754527}
  • Loading branch information
pkasting authored and Commit Bot committed Mar 30, 2020
1 parent 4e4a76b commit 017a115
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 56 deletions.
3 changes: 1 addition & 2 deletions ui/aura/demo/demo_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ int DemoMain() {
display::Screen::SetScreenInstance(test_screen.get());
std::unique_ptr<aura::WindowTreeHost> host(
test_screen->CreateHostForPrimaryDisplay());
std::unique_ptr<DemoWindowParentingClient> window_parenting_client(
new DemoWindowParentingClient(host->window()));
DemoWindowParentingClient window_parenting_client(host->window());
aura::test::TestFocusClient focus_client(host->window());

// Create a hierarchy of test windows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ class NativeWindowOcclusionTrackerTest : public test::AuraTestBase {
features::kCalculateNativeWinOcclusion);

AuraTestBase::SetUp();

display::Screen::SetScreenInstance(test_screen());

}

void SetNativeWindowBounds(HWND hwnd, const gfx::Rect& bounds) {
Expand Down
11 changes: 4 additions & 7 deletions ui/aura/test/aura_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
#include "ui/aura/test/aura_test_helper.h"

#include "base/bind.h"
#include "base/command_line.h"
#include "base/run_loop.h"
#include "build/build_config.h"
#include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env.h"
#include "ui/aura/input_state_lookup.h"
#include "ui/aura/test/env_test_helper.h"
Expand Down Expand Up @@ -112,7 +110,6 @@ void AuraTestHelper::SetUp() {
display::Screen* screen = display::Screen::GetScreen();
gfx::Size host_size(screen ? screen->GetPrimaryDisplay().GetSizeInPixel()
: gfx::Size(800, 600));

test_screen_.reset(TestScreen::Create(host_size));
// TODO(pkasting): Seems like we should either always set the screen instance,
// or not create the screen/host if the test already has one; it doesn't make
Expand Down Expand Up @@ -202,13 +199,13 @@ client::CaptureClient* AuraTestHelper::GetCaptureClient() {
}

Env* AuraTestHelper::GetEnv() {
return env_ ? env_.get() : Env::HasInstance() ? Env::GetInstance() : nullptr;
if (env_)
return env_.get();
return Env::HasInstance() ? Env::GetInstance() : nullptr;
}

ui::ContextFactory* AuraTestHelper::GetContextFactory() {
Env* env = GetEnv();
DCHECK(env);
return env->context_factory();
return GetEnv()->context_factory();
}

} // namespace test
Expand Down
1 change: 1 addition & 0 deletions ui/aura/test/aura_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DefaultCaptureClient;
class FocusClient;
class ScreenPositionClient;
}

namespace test {
class TestWindowParentingClient;

Expand Down
4 changes: 1 addition & 3 deletions ui/aura/test/test_focus_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace test {
// TestFocusClient, public:

TestFocusClient::TestFocusClient(Window* root_window)
: root_window_(root_window),
focused_window_(nullptr),
observer_manager_(this) {
: root_window_(root_window) {
DCHECK(root_window_);
client::SetFocusClient(root_window_, this);
}
Expand Down
4 changes: 2 additions & 2 deletions ui/aura/test/test_focus_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class TestFocusClient : public client::FocusClient,
void OnWindowDestroying(Window* window) override;

Window* root_window_;
Window* focused_window_;
ScopedObserver<Window, WindowObserver> observer_manager_;
Window* focused_window_ = nullptr;
ScopedObserver<Window, WindowObserver> observer_manager_{this};
base::ObserverList<aura::client::FocusChangeObserver>::Unchecked
focus_observers_;

Expand Down
8 changes: 0 additions & 8 deletions ui/views/controls/textfield/textfield_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/base/dragdrop/drag_drop_types.h"
#include "ui/base/emoji/emoji_panel_helper.h"
#include "ui/base/ime/constants.h"
Expand Down Expand Up @@ -413,13 +412,6 @@ class TextfieldTest : public ViewsTestBase, public TextfieldController {
ViewsTestBase::TearDown();
}

void SetUp() override {
// OS clipboard is a global resource, which causes flakiness when unit tests
// run in parallel. So, use a per-instance test clipboard.
ui::TestClipboard::CreateForCurrentThread();
ViewsTestBase::SetUp();
}

ui::ClipboardBuffer GetAndResetCopiedToClipboard() {
ui::ClipboardBuffer clipboard_buffer = copied_to_clipboard_;
copied_to_clipboard_ = ui::ClipboardBuffer::kMaxValue;
Expand Down
2 changes: 0 additions & 2 deletions ui/views/controls/webview/webview_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/views/controls/native/native_view_host.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/test/widget_test.h"

#if defined(USE_AURA)
Expand Down Expand Up @@ -146,7 +145,6 @@ class WebViewUnitTest : public views::test::WidgetTest {
scoped_web_contents_creator_ =
std::make_unique<views::WebView::ScopedWebContentsCreatorForTesting>(
creator);
set_views_delegate(base::WrapUnique(new views::TestViewsDelegate));
browser_context_ = std::make_unique<content::TestBrowserContext>();
WidgetTest::SetUp();
// Set the test content browser client to avoid pulling in needless
Expand Down
3 changes: 0 additions & 3 deletions ui/views/corewm/tooltip_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
#include "ui/accessibility/ax_node_data.h"
#include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/window_types.h"
#include "ui/aura/env.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
Expand Down Expand Up @@ -42,7 +40,6 @@

#if BUILDFLAG(ENABLE_DESKTOP_AURA)
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h"
#endif

using base::ASCIIToUTF16;
Expand Down
5 changes: 2 additions & 3 deletions ui/views/test/scoped_views_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "ui/base/clipboard/clipboard.h"
#include "ui/base/clipboard/test/test_clipboard.h"
#include "ui/base/ime/init/input_method_initializer.h"
#include "ui/views/test/test_views_delegate.h"

#if defined(USE_AURA)
Expand All @@ -27,13 +26,13 @@ ScopedViewsTestHelper::ScopedViewsTestHelper(
std::move(factory));
test_helper_->SetUp();

ui::InitializeInputMethodForTesting();
// OS clipboard is a global resource, which causes flakiness when unit tests
// run in parallel. So, use a per-instance test clipboard.
ui::TestClipboard::CreateForCurrentThread();
}

ScopedViewsTestHelper::~ScopedViewsTestHelper() {
ui::Clipboard::DestroyClipboardForCurrentThread();
ui::ShutdownInputMethodForTesting();
}

gfx::NativeWindow ScopedViewsTestHelper::GetContext() {
Expand Down
4 changes: 2 additions & 2 deletions ui/views/test/scoped_views_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ScopedViewsTestHelper {
std::unique_ptr<TestViewsDelegate> test_views_delegate = nullptr,
base::Optional<ViewsDelegate::NativeWidgetFactory> factory =
base::nullopt);
ScopedViewsTestHelper(const ScopedViewsTestHelper&) = delete;
ScopedViewsTestHelper& operator=(const ScopedViewsTestHelper&) = delete;
~ScopedViewsTestHelper();

// Returns the context for creating new windows. In Aura builds, this will be
Expand All @@ -45,8 +47,6 @@ class ScopedViewsTestHelper {
private:
std::unique_ptr<ViewsTestHelper> test_helper_ = ViewsTestHelper::Create();
std::unique_ptr<TestViewsDelegate> test_views_delegate_;

DISALLOW_COPY_AND_ASSIGN(ScopedViewsTestHelper);
};

} // namespace views
Expand Down
8 changes: 3 additions & 5 deletions ui/views/test/views_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class ViewsTestHelper {
// Create a platform specific instance.
static std::unique_ptr<ViewsTestHelper> Create();

ViewsTestHelper(const ViewsTestHelper&) = delete;
ViewsTestHelper& operator=(const ViewsTestHelper&) = delete;
virtual ~ViewsTestHelper() = default;

// Returns the delegate to use if the test/owner does not create one.
Expand All @@ -36,15 +38,11 @@ class ViewsTestHelper {
// Does any additional necessary setup of this object or its members.
virtual void SetUp();

// Returns a context view. In aura builds, this will be the RootWindow.
// Everywhere else, null.
// Returns a context window, e.g. the Aura root window.
virtual gfx::NativeWindow GetContext();

protected:
ViewsTestHelper() = default;

private:
DISALLOW_COPY_AND_ASSIGN(ViewsTestHelper);
};

} // namespace views
Expand Down
5 changes: 2 additions & 3 deletions ui/views/test/views_test_helper_aura.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <memory>

#include "base/callback_forward.h"
#include "base/macros.h"
#include "ui/aura/test/aura_test_helper.h"
#include "ui/views/test/views_test_helper.h"

Expand All @@ -20,6 +19,8 @@ class ViewsTestHelperAura : public ViewsTestHelper {
base::OnceCallback<std::unique_ptr<TestViewsDelegate>()>;

ViewsTestHelperAura();
ViewsTestHelperAura(const ViewsTestHelperAura&) = delete;
ViewsTestHelperAura& operator=(const ViewsTestHelperAura&) = delete;
~ViewsTestHelperAura() override;

// ViewsTestHelper:
Expand All @@ -36,8 +37,6 @@ class ViewsTestHelperAura : public ViewsTestHelper {
private:
std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_;
TestViewsDelegateFactory factory_;

DISALLOW_COPY_AND_ASSIGN(ViewsTestHelperAura);
};

} // namespace views
Expand Down
5 changes: 2 additions & 3 deletions ui/views/test/views_test_helper_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <memory>

#include "base/macros.h"
#include "ui/base/test/scoped_fake_full_keyboard_access.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/test/test_context_factories.h"
Expand All @@ -25,6 +24,8 @@ namespace views {
class ViewsTestHelperMac : public ViewsTestHelper {
public:
ViewsTestHelperMac();
ViewsTestHelperMac(const ViewsTestHelperMac&) = delete;
ViewsTestHelperMac& operator=(const ViewsTestHelperMac&) = delete;
~ViewsTestHelperMac() override;

// ViewsTestHelper:
Expand Down Expand Up @@ -57,8 +58,6 @@ class ViewsTestHelperMac : public ViewsTestHelper {
// more consistent with other platforms, where most views are focusable by
// default.
ui::test::ScopedFakeFullKeyboardAccess faked_full_keyboard_access_;

DISALLOW_COPY_AND_ASSIGN(ViewsTestHelperMac);
};

} // namespace views
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#include "base/macros.h"
#include "content/public/browser/context_factory.h"
#include "content/shell/browser/shell_browser_context.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/window.h"
#include "ui/display/screen.h"
#include "ui/views_content_client/views_content_client.h"
#include "ui/views_content_client/views_content_client_main_parts_aura.h"
#include "ui/wm/test/wm_test_helper.h"
Expand All @@ -30,7 +28,6 @@ class ViewsContentClientMainPartsChromeOS

private:
// Enable a minimal set of views::corewm to be initialized.
std::unique_ptr<display::Screen> test_screen_;
std::unique_ptr<::wm::WMTestHelper> wm_test_helper_;

DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsChromeOS);
Expand All @@ -45,11 +42,8 @@ ViewsContentClientMainPartsChromeOS::ViewsContentClientMainPartsChromeOS(
void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() {
ViewsContentClientMainPartsAura::PreMainMessageLoopRun();

gfx::Size host_size(800, 600);
test_screen_.reset(aura::TestScreen::Create(host_size));
display::Screen::SetScreenInstance(test_screen_.get());
// Set up basic pieces of views::corewm.
wm_test_helper_ = std::make_unique<wm::WMTestHelper>(host_size);
wm_test_helper_ = std::make_unique<wm::WMTestHelper>(gfx::Size(800, 600));
// Ensure the X window gets mapped.
wm_test_helper_->host()->Show();

Expand All @@ -61,7 +55,6 @@ void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() {

void ViewsContentClientMainPartsChromeOS::PostMainMessageLoopRun() {
wm_test_helper_.reset();
test_screen_.reset();

ViewsContentClientMainPartsAura::PostMainMessageLoopRun();
}
Expand Down
3 changes: 1 addition & 2 deletions ui/wm/core/shadow_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ class ShadowControllerTest : public aura::test::AuraTestBase {

void InstallShadowController(
std::unique_ptr<ShadowControllerDelegate> delegate) {
ActivationClient* activation_client = GetActivationClient(root_window());
shadow_controller_ = std::make_unique<ShadowController>(
activation_client, std::move(delegate));
GetActivationClient(root_window()), std::move(delegate));
}

private:
Expand Down

0 comments on commit 017a115

Please sign in to comment.