Commit 6894750f authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Fix presubmit warnings about deprecated function usage.

Bug: 714018
Change-Id: I8d9c183af32ce111afafdc4e3fa94af468b375bd
Reviewed-on: https://chromium-review.googlesource.com/c/1480445
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634770}
parent 2747d53c
...@@ -608,14 +608,16 @@ class BookmarkBarViewTest3 : public BookmarkBarViewEventTestBase { ...@@ -608,14 +608,16 @@ class BookmarkBarViewTest3 : public BookmarkBarViewEventTestBase {
VIEW_TEST(BookmarkBarViewTest3, Submenus) VIEW_TEST(BookmarkBarViewTest3, Submenus)
// Observer that posts task upon the context menu creation. // Observer that posts a task upon the context menu creation.
// This is necessary for Linux as the context menu has to check // This is necessary for Linux as the context menu has to check the clipboard,
// the clipboard, which invokes the event loop. // which invokes the event loop.
// Because |task| is a OnceClosure, callers should use a separate observer
// instance for each successive context menu creation they wish to observe.
class BookmarkContextMenuNotificationObserver class BookmarkContextMenuNotificationObserver
: public content::NotificationObserver { : public content::NotificationObserver {
public: public:
explicit BookmarkContextMenuNotificationObserver(const base::Closure& task) explicit BookmarkContextMenuNotificationObserver(base::OnceClosure task)
: task_(task) { : task_(std::move(task)) {
registrar_.Add(this, registrar_.Add(this,
chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN,
content::NotificationService::AllSources()); content::NotificationService::AllSources());
...@@ -624,15 +626,13 @@ class BookmarkContextMenuNotificationObserver ...@@ -624,15 +626,13 @@ class BookmarkContextMenuNotificationObserver
void Observe(int type, void Observe(int type,
const content::NotificationSource& source, const content::NotificationSource& source,
const content::NotificationDetails& details) override { const content::NotificationDetails& details) override {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task_); DCHECK(!task_.is_null());
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, std::move(task_));
} }
// Sets the task that is posted when the context menu is shown.
void set_task(const base::Closure& task) { task_ = task; }
private: private:
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
base::Closure task_; base::OnceClosure task_;
DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuNotificationObserver); DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuNotificationObserver);
}; };
...@@ -668,8 +668,9 @@ class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase { ...@@ -668,8 +668,9 @@ class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase {
ASSERT_TRUE(child_menu != NULL); ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu. // Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, ui_test_utils::MoveMouseToCenterAndPress(
ui_controls::DOWN | ui_controls::UP, base::Closure()); child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver. // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
} }
...@@ -1246,8 +1247,9 @@ class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase { ...@@ -1246,8 +1247,9 @@ class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase {
ASSERT_TRUE(child_menu != NULL); ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu. // Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, ui_test_utils::MoveMouseToCenterAndPress(
ui_controls::DOWN | ui_controls::UP, base::Closure()); child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver. // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
} }
...@@ -1342,8 +1344,8 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase { ...@@ -1342,8 +1344,8 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase {
std::make_unique<DialogWaiter>(GetWidget()->GetNativeWindow()->env()); std::make_unique<DialogWaiter>(GetWidget()->GetNativeWindow()->env());
ui_test_utils::MoveMouseToCenterAndPress( ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, child_menu, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
base::Bind(&BookmarkBarViewTest12::Step4, base::Unretained(this), base::BindOnce(&BookmarkBarViewTest12::Step4, base::Unretained(this),
base::Passed(&dialog_waiter))); std::move(dialog_waiter)));
} }
void Step4(std::unique_ptr<DialogWaiter> waiter) { void Step4(std::unique_ptr<DialogWaiter> waiter) {
...@@ -1408,8 +1410,9 @@ class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase { ...@@ -1408,8 +1410,9 @@ class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase {
ASSERT_TRUE(child_menu != NULL); ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu. // Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, ui_test_utils::MoveMouseToCenterAndPress(
ui_controls::DOWN | ui_controls::UP, base::Closure()); child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver. // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
} }
...@@ -1475,8 +1478,9 @@ class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase { ...@@ -1475,8 +1478,9 @@ class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase {
// Move the mouse to the first folder on the bookmark bar and press the // Move the mouse to the first folder on the bookmark bar and press the
// right mouse button. // right mouse button.
views::LabelButton* button = GetBookmarkButton(0); views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::RIGHT, ui_test_utils::MoveMouseToCenterAndPress(
ui_controls::DOWN | ui_controls::UP, base::Closure()); button, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step2 will be invoked by BookmarkContextMenuNotificationObserver. // Step2 will be invoked by BookmarkContextMenuNotificationObserver.
} }
...@@ -1533,8 +1537,9 @@ class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase { ...@@ -1533,8 +1537,9 @@ class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase {
deleted_menu_id_ = child_menu->GetCommand(); deleted_menu_id_ = child_menu->GetCommand();
// Right click on the second child to get its context menu. // Right click on the second child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, ui_test_utils::MoveMouseToCenterAndPress(
ui_controls::DOWN | ui_controls::UP, base::Closure()); child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver. // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
} }
...@@ -1618,8 +1623,8 @@ VIEW_TEST(BookmarkBarViewTest16, DeleteMenu) ...@@ -1618,8 +1623,8 @@ VIEW_TEST(BookmarkBarViewTest16, DeleteMenu)
class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase { class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
public: public:
BookmarkBarViewTest17() BookmarkBarViewTest17()
: observer_(CreateEventTask(this, &BookmarkBarViewTest17::Step3)) { : observer_(std::make_unique<BookmarkContextMenuNotificationObserver>(
} CreateEventTask(this, &BookmarkBarViewTest17::Step3))) {}
protected: protected:
void DoTestOnMessageLoop() override { void DoTestOnMessageLoop() override {
...@@ -1641,8 +1646,9 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase { ...@@ -1641,8 +1646,9 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
// Right click on the second item to show its context menu. // Right click on the second item to show its context menu.
views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(2); views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(2);
ASSERT_TRUE(child_menu != NULL); ASSERT_TRUE(child_menu != NULL);
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT, ui_test_utils::MoveMouseToCenterAndPress(
ui_controls::DOWN | ui_controls::UP, base::Closure()); child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver. // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
} }
...@@ -1668,7 +1674,8 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase { ...@@ -1668,7 +1674,8 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
gfx::Rect clickable_rect = gfx::Rect clickable_rect =
gfx::SubtractRects(child_menu_rect, context_rect); gfx::SubtractRects(child_menu_rect, context_rect);
ASSERT_FALSE(clickable_rect.IsEmpty()); ASSERT_FALSE(clickable_rect.IsEmpty());
observer_.set_task(CreateEventTask(this, &BookmarkBarViewTest17::Step4)); observer_ = std::make_unique<BookmarkContextMenuNotificationObserver>(
CreateEventTask(this, &BookmarkBarViewTest17::Step4));
MoveMouseAndPress(clickable_rect.CenterPoint(), ui_controls::RIGHT, MoveMouseAndPress(clickable_rect.CenterPoint(), ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure()); ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step4 will be invoked by BookmarkContextMenuNotificationObserver. // Step4 will be invoked by BookmarkContextMenuNotificationObserver.
...@@ -1689,7 +1696,7 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase { ...@@ -1689,7 +1696,7 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
Done(); Done();
} }
BookmarkContextMenuNotificationObserver observer_; std::unique_ptr<BookmarkContextMenuNotificationObserver> observer_;
}; };
// Flaky. See http://crbug.com/820435. // Flaky. See http://crbug.com/820435.
...@@ -1961,8 +1968,9 @@ class BookmarkBarViewTest21 : public BookmarkBarViewEventTestBase { ...@@ -1961,8 +1968,9 @@ class BookmarkBarViewTest21 : public BookmarkBarViewEventTestBase {
EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id()); EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id());
// Right click on the first child to get its context menu. // Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::RIGHT, ui_test_utils::MoveMouseToCenterAndPress(
ui_controls::DOWN | ui_controls::UP, base::Closure()); view, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver. // Step3 will be invoked by BookmarkContextMenuNotificationObserver.
} }
......
...@@ -256,12 +256,10 @@ class MenuModelAdapterTest : public ViewEventTestBase, ...@@ -256,12 +256,10 @@ class MenuModelAdapterTest : public ViewEventTestBase,
private: private:
// Generate a mouse click on the specified view and post a new task. // Generate a mouse click on the specified view and post a new task.
virtual void Click(views::View* view, const base::Closure& next) { virtual void Click(views::View* view, base::OnceClosure next) {
ui_test_utils::MoveMouseToCenterAndPress( ui_test_utils::MoveMouseToCenterAndPress(
view, view, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
ui_controls::LEFT, std::move(next));
ui_controls::DOWN | ui_controls::UP,
next);
} }
views::MenuButton* button_; views::MenuButton* button_;
......
...@@ -24,12 +24,10 @@ MenuTestBase::MenuTestBase() ...@@ -24,12 +24,10 @@ MenuTestBase::MenuTestBase()
MenuTestBase::~MenuTestBase() { MenuTestBase::~MenuTestBase() {
} }
void MenuTestBase::Click(views::View* view, const base::Closure& next) { void MenuTestBase::Click(views::View* view, base::OnceClosure next) {
ui_test_utils::MoveMouseToCenterAndPress( ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::LEFT,
view, ui_controls::DOWN | ui_controls::UP,
ui_controls::LEFT, std::move(next));
ui_controls::DOWN | ui_controls::UP,
next);
views::test::WaitForMenuClosureAnimation(); views::test::WaitForMenuClosureAnimation();
} }
......
...@@ -42,7 +42,7 @@ class MenuTestBase : public ViewEventTestBase, ...@@ -42,7 +42,7 @@ class MenuTestBase : public ViewEventTestBase,
~MenuTestBase() override; ~MenuTestBase() override;
// Generate a mouse click and run |next| once the event has been processed. // Generate a mouse click and run |next| once the event has been processed.
virtual void Click(views::View* view, const base::Closure& next); virtual void Click(views::View* view, base::OnceClosure next);
// Generate a keypress and run |next| once the event has been processed. // Generate a keypress and run |next| once the event has been processed.
void KeyPress(ui::KeyboardCode keycode, base::OnceClosure next); void KeyPress(ui::KeyboardCode keycode, base::OnceClosure next);
......
...@@ -190,7 +190,7 @@ void MoveMouseToCenterAndPress( ...@@ -190,7 +190,7 @@ void MoveMouseToCenterAndPress(
views::View* view, views::View* view,
ui_controls::MouseButton button, ui_controls::MouseButton button,
int button_state, int button_state,
const base::RepeatingClosure& task, base::OnceClosure task,
int accelerator_state = ui_controls::kNoAccelerator); int accelerator_state = ui_controls::kNoAccelerator);
// Returns the center of |view| in screen coordinates. // Returns the center of |view| in screen coordinates.
......
...@@ -17,7 +17,7 @@ namespace ui_test_utils { ...@@ -17,7 +17,7 @@ namespace ui_test_utils {
void MoveMouseToCenterAndPress(views::View* view, void MoveMouseToCenterAndPress(views::View* view,
ui_controls::MouseButton button, ui_controls::MouseButton button,
int button_state, int button_state,
const base::RepeatingClosure& closure, base::OnceClosure closure,
int accelerator_state) { int accelerator_state) {
DCHECK(view); DCHECK(view);
DCHECK(view->GetWidget()); DCHECK(view->GetWidget());
...@@ -34,8 +34,8 @@ void MoveMouseToCenterAndPress(views::View* view, ...@@ -34,8 +34,8 @@ void MoveMouseToCenterAndPress(views::View* view,
gfx::Point view_center = GetCenterInScreenCoordinates(view); gfx::Point view_center = GetCenterInScreenCoordinates(view);
ui_controls::SendMouseMoveNotifyWhenDone( ui_controls::SendMouseMoveNotifyWhenDone(
view_center.x(), view_center.y(), view_center.x(), view_center.y(),
base::BindOnce(&internal::ClickTask, button, button_state, closure, base::BindOnce(&internal::ClickTask, button, button_state,
accelerator_state)); std::move(closure), accelerator_state));
} }
gfx::Point GetCenterInScreenCoordinates(const views::View* view) { gfx::Point GetCenterInScreenCoordinates(const views::View* view) {
......
...@@ -112,7 +112,7 @@ void ViewEventTestBase::SetUp() { ...@@ -112,7 +112,7 @@ void ViewEventTestBase::SetUp() {
void ViewEventTestBase::TearDown() { void ViewEventTestBase::TearDown() {
if (window_) { if (window_) {
window_->Close(); window_->Close();
content::RunAllPendingInMessageLoop(); base::RunLoop().RunUntilIdle();
window_ = NULL; window_ = NULL;
} }
...@@ -160,7 +160,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() { ...@@ -160,7 +160,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() {
ui_test_utils::ShowAndFocusNativeWindow(window_->GetNativeWindow())); ui_test_utils::ShowAndFocusNativeWindow(window_->GetNativeWindow()));
// Flush any pending events to make sure we start with a clean slate. // Flush any pending events to make sure we start with a clean slate.
content::RunAllPendingInMessageLoop(); base::RunLoop().RunUntilIdle();
// Schedule a task that starts the test. Need to do this as we're going to // Schedule a task that starts the test. Need to do this as we're going to
// run the message loop. // run the message loop.
...@@ -168,7 +168,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() { ...@@ -168,7 +168,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() {
FROM_HERE, base::BindOnce(&ViewEventTestBase::DoTestOnMessageLoop, FROM_HERE, base::BindOnce(&ViewEventTestBase::DoTestOnMessageLoop,
base::Unretained(this))); base::Unretained(this)));
content::RunThisRunLoop(&run_loop_); run_loop_.Run();
} }
void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) {
...@@ -185,10 +185,10 @@ void ViewEventTestBase::StopBackgroundThread() { ...@@ -185,10 +185,10 @@ void ViewEventTestBase::StopBackgroundThread() {
dnd_thread_.reset(); dnd_thread_.reset();
} }
void ViewEventTestBase::RunTestMethod(const base::Closure& task) { void ViewEventTestBase::RunTestMethod(base::OnceClosure task) {
StopBackgroundThread(); StopBackgroundThread();
task.Run(); std::move(task).Run();
if (HasFatalFailure()) if (HasFatalFailure())
Done(); Done();
} }
...@@ -118,9 +118,10 @@ class ViewEventTestBase : public views::WidgetDelegate, ...@@ -118,9 +118,10 @@ class ViewEventTestBase : public views::WidgetDelegate,
// method is called in such a way that if there are any test failures // method is called in such a way that if there are any test failures
// Done is invoked. // Done is invoked.
template <class T, class Method> template <class T, class Method>
base::Closure CreateEventTask(T* target, Method method) { base::OnceClosure CreateEventTask(T* target, Method method) {
return base::Bind(&ViewEventTestBase::RunTestMethod, base::Unretained(this), return base::BindOnce(&ViewEventTestBase::RunTestMethod,
base::Bind(method, base::Unretained(target))); base::Unretained(this),
base::BindOnce(method, base::Unretained(target)));
} }
// Spawns a new thread posts a MouseMove in the background. // Spawns a new thread posts a MouseMove in the background.
...@@ -134,7 +135,7 @@ class ViewEventTestBase : public views::WidgetDelegate, ...@@ -134,7 +135,7 @@ class ViewEventTestBase : public views::WidgetDelegate,
// Callback from CreateEventTask. Stops the background thread, runs the // Callback from CreateEventTask. Stops the background thread, runs the
// supplied task and if there are failures invokes Done. // supplied task and if there are failures invokes Done.
void RunTestMethod(const base::Closure& task); void RunTestMethod(base::OnceClosure task);
// The content of the Window. // The content of the Window.
views::View* content_view_; views::View* content_view_;
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h"
#include "chrome/test/base/view_event_test_platform_part.h" #include "chrome/test/base/view_event_test_platform_part.h"
#include "ui/aura/env.h" #include "ui/aura/env.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
......
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