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 {
VIEW_TEST(BookmarkBarViewTest3, Submenus)
// Observer that posts task upon the context menu creation.
// This is necessary for Linux as the context menu has to check
// the clipboard, which invokes the event loop.
// Observer that posts a task upon the context menu creation.
// This is necessary for Linux as the context menu has to check the clipboard,
// 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
: public content::NotificationObserver {
public:
explicit BookmarkContextMenuNotificationObserver(const base::Closure& task)
: task_(task) {
explicit BookmarkContextMenuNotificationObserver(base::OnceClosure task)
: task_(std::move(task)) {
registrar_.Add(this,
chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN,
content::NotificationService::AllSources());
......@@ -624,15 +626,13 @@ class BookmarkContextMenuNotificationObserver
void Observe(int type,
const content::NotificationSource& source,
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:
content::NotificationRegistrar registrar_;
base::Closure task_;
base::OnceClosure task_;
DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuNotificationObserver);
};
......@@ -668,8 +668,9 @@ class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase {
ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
......@@ -1246,8 +1247,9 @@ class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase {
ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
......@@ -1342,8 +1344,8 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase {
std::make_unique<DialogWaiter>(GetWidget()->GetNativeWindow()->env());
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
base::Bind(&BookmarkBarViewTest12::Step4, base::Unretained(this),
base::Passed(&dialog_waiter)));
base::BindOnce(&BookmarkBarViewTest12::Step4, base::Unretained(this),
std::move(dialog_waiter)));
}
void Step4(std::unique_ptr<DialogWaiter> waiter) {
......@@ -1408,8 +1410,9 @@ class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase {
ASSERT_TRUE(child_menu != NULL);
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
......@@ -1475,8 +1478,9 @@ class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase {
// Move the mouse to the first folder on the bookmark bar and press the
// right mouse button.
views::LabelButton* button = GetBookmarkButton(0);
ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
ui_test_utils::MoveMouseToCenterAndPress(
button, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step2 will be invoked by BookmarkContextMenuNotificationObserver.
}
......@@ -1533,8 +1537,9 @@ class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase {
deleted_menu_id_ = child_menu->GetCommand();
// Right click on the second child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
......@@ -1618,8 +1623,8 @@ VIEW_TEST(BookmarkBarViewTest16, DeleteMenu)
class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
public:
BookmarkBarViewTest17()
: observer_(CreateEventTask(this, &BookmarkBarViewTest17::Step3)) {
}
: observer_(std::make_unique<BookmarkContextMenuNotificationObserver>(
CreateEventTask(this, &BookmarkBarViewTest17::Step3))) {}
protected:
void DoTestOnMessageLoop() override {
......@@ -1641,8 +1646,9 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
// Right click on the second item to show its context menu.
views::MenuItemView* child_menu = menu->GetSubmenu()->GetMenuItemAt(2);
ASSERT_TRUE(child_menu != NULL);
ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
ui_test_utils::MoveMouseToCenterAndPress(
child_menu, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
......@@ -1668,7 +1674,8 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
gfx::Rect clickable_rect =
gfx::SubtractRects(child_menu_rect, context_rect);
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,
ui_controls::DOWN | ui_controls::UP, base::Closure());
// Step4 will be invoked by BookmarkContextMenuNotificationObserver.
......@@ -1689,7 +1696,7 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase {
Done();
}
BookmarkContextMenuNotificationObserver observer_;
std::unique_ptr<BookmarkContextMenuNotificationObserver> observer_;
};
// Flaky. See http://crbug.com/820435.
......@@ -1961,8 +1968,9 @@ class BookmarkBarViewTest21 : public BookmarkBarViewEventTestBase {
EXPECT_EQ(views::MenuItemView::kEmptyMenuItemViewID, view->id());
// Right click on the first child to get its context menu.
ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::RIGHT,
ui_controls::DOWN | ui_controls::UP, base::Closure());
ui_test_utils::MoveMouseToCenterAndPress(
view, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP,
base::OnceClosure());
// Step3 will be invoked by BookmarkContextMenuNotificationObserver.
}
......
......@@ -256,12 +256,10 @@ class MenuModelAdapterTest : public ViewEventTestBase,
private:
// 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(
view,
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
next);
view, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
std::move(next));
}
views::MenuButton* button_;
......
......@@ -24,12 +24,10 @@ MenuTestBase::MenuTestBase()
MenuTestBase::~MenuTestBase() {
}
void MenuTestBase::Click(views::View* view, const base::Closure& next) {
ui_test_utils::MoveMouseToCenterAndPress(
view,
ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
next);
void MenuTestBase::Click(views::View* view, base::OnceClosure next) {
ui_test_utils::MoveMouseToCenterAndPress(view, ui_controls::LEFT,
ui_controls::DOWN | ui_controls::UP,
std::move(next));
views::test::WaitForMenuClosureAnimation();
}
......
......@@ -42,7 +42,7 @@ class MenuTestBase : public ViewEventTestBase,
~MenuTestBase() override;
// 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.
void KeyPress(ui::KeyboardCode keycode, base::OnceClosure next);
......
......@@ -190,7 +190,7 @@ void MoveMouseToCenterAndPress(
views::View* view,
ui_controls::MouseButton button,
int button_state,
const base::RepeatingClosure& task,
base::OnceClosure task,
int accelerator_state = ui_controls::kNoAccelerator);
// Returns the center of |view| in screen coordinates.
......
......@@ -17,7 +17,7 @@ namespace ui_test_utils {
void MoveMouseToCenterAndPress(views::View* view,
ui_controls::MouseButton button,
int button_state,
const base::RepeatingClosure& closure,
base::OnceClosure closure,
int accelerator_state) {
DCHECK(view);
DCHECK(view->GetWidget());
......@@ -34,8 +34,8 @@ void MoveMouseToCenterAndPress(views::View* view,
gfx::Point view_center = GetCenterInScreenCoordinates(view);
ui_controls::SendMouseMoveNotifyWhenDone(
view_center.x(), view_center.y(),
base::BindOnce(&internal::ClickTask, button, button_state, closure,
accelerator_state));
base::BindOnce(&internal::ClickTask, button, button_state,
std::move(closure), accelerator_state));
}
gfx::Point GetCenterInScreenCoordinates(const views::View* view) {
......
......@@ -112,7 +112,7 @@ void ViewEventTestBase::SetUp() {
void ViewEventTestBase::TearDown() {
if (window_) {
window_->Close();
content::RunAllPendingInMessageLoop();
base::RunLoop().RunUntilIdle();
window_ = NULL;
}
......@@ -160,7 +160,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() {
ui_test_utils::ShowAndFocusNativeWindow(window_->GetNativeWindow()));
// 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
// run the message loop.
......@@ -168,7 +168,7 @@ void ViewEventTestBase::StartMessageLoopAndRunTest() {
FROM_HERE, base::BindOnce(&ViewEventTestBase::DoTestOnMessageLoop,
base::Unretained(this)));
content::RunThisRunLoop(&run_loop_);
run_loop_.Run();
}
void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) {
......@@ -185,10 +185,10 @@ void ViewEventTestBase::StopBackgroundThread() {
dnd_thread_.reset();
}
void ViewEventTestBase::RunTestMethod(const base::Closure& task) {
void ViewEventTestBase::RunTestMethod(base::OnceClosure task) {
StopBackgroundThread();
task.Run();
std::move(task).Run();
if (HasFatalFailure())
Done();
}
......@@ -118,9 +118,10 @@ class ViewEventTestBase : public views::WidgetDelegate,
// method is called in such a way that if there are any test failures
// Done is invoked.
template <class T, class Method>
base::Closure CreateEventTask(T* target, Method method) {
return base::Bind(&ViewEventTestBase::RunTestMethod, base::Unretained(this),
base::Bind(method, base::Unretained(target)));
base::OnceClosure CreateEventTask(T* target, Method method) {
return base::BindOnce(&ViewEventTestBase::RunTestMethod,
base::Unretained(this),
base::BindOnce(method, base::Unretained(target)));
}
// Spawns a new thread posts a MouseMove in the background.
......@@ -134,7 +135,7 @@ class ViewEventTestBase : public views::WidgetDelegate,
// Callback from CreateEventTask. Stops the background thread, runs the
// 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.
views::View* content_view_;
......
......@@ -5,6 +5,7 @@
#include <memory>
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/test/base/view_event_test_platform_part.h"
#include "ui/aura/env.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