Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1164)

Unified Diff: ui/events/platform/platform_event_source_unittest.cc

Issue 2628393003: Remove ScopedVector from ui/events/. (Closed)
Patch Set: chromeos2 Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/events/platform/platform_event_source_unittest.cc
diff --git a/ui/events/platform/platform_event_source_unittest.cc b/ui/events/platform/platform_event_source_unittest.cc
index e2d87c067122711ae6050e999930ba4c8cb273da..9ef8bc5ee034b5d385c5d0c5a997ace7e6453583 100644
--- a/ui/events/platform/platform_event_source_unittest.cc
+++ b/ui/events/platform/platform_event_source_unittest.cc
@@ -9,10 +9,11 @@
#include <memory>
#include <utility>
+#include <vector>
#include "base/bind.h"
#include "base/macros.h"
-#include "base/memory/scoped_vector.h"
+#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
@@ -26,14 +27,11 @@ namespace ui {
namespace {
std::unique_ptr<PlatformEvent> CreatePlatformEvent() {
- std::unique_ptr<PlatformEvent> event(new PlatformEvent());
+ std::unique_ptr<PlatformEvent> event = base::MakeUnique<PlatformEvent>();
sadrul 2017/01/16 20:26:44 Is MakeUnique<> preferred over using new with the
Avi (use Gerrit) 2017/01/16 20:39:38 Yes. https://www.chromium.org/developers/coding-st
memset(event.get(), 0, sizeof(PlatformEvent));
return event;
}
-template <typename T>
-void DestroyScopedPtr(std::unique_ptr<T> object) {}
-
void RemoveDispatcher(PlatformEventDispatcher* dispatcher) {
PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(dispatcher);
}
@@ -61,7 +59,8 @@ class TestPlatformEventSource : public PlatformEventSource {
// Dispatches the stream of events, and returns the number of events that are
// dispatched before it is requested to stop.
- size_t DispatchEventStream(const ScopedVector<PlatformEvent>& events) {
+ size_t DispatchEventStream(
+ const std::vector<std::unique_ptr<PlatformEvent>>& events) {
stop_stream_ = false;
for (size_t count = 0; count < events.size(); ++count) {
DispatchEvent(*events[count]);
@@ -157,13 +156,13 @@ class PlatformEventTest : public testing::Test {
// Tests that a dispatcher receives an event.
TEST_F(PlatformEventTest, DispatcherBasic) {
std::vector<int> list_dispatcher;
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
EXPECT_EQ(0u, list_dispatcher.size());
{
TestPlatformEventDispatcher dispatcher(1, &list_dispatcher);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(1u, list_dispatcher.size());
EXPECT_EQ(1, list_dispatcher[0]);
@@ -179,12 +178,12 @@ TEST_F(PlatformEventTest, DispatcherBasic) {
TEST_F(PlatformEventTest, DispatcherOrder) {
std::vector<int> list_dispatcher;
int sequence[] = {21, 3, 6, 45};
- ScopedVector<TestPlatformEventDispatcher> dispatchers;
- for (size_t i = 0; i < arraysize(sequence); ++i) {
+ std::vector<std::unique_ptr<TestPlatformEventDispatcher>> dispatchers;
+ for (auto id : sequence) {
dispatchers.push_back(
- new TestPlatformEventDispatcher(sequence[i], &list_dispatcher));
+ base::MakeUnique<TestPlatformEventDispatcher>(id, &list_dispatcher));
}
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(arraysize(sequence), list_dispatcher.size());
EXPECT_EQ(std::vector<int>(sequence, sequence + arraysize(sequence)),
@@ -198,7 +197,7 @@ TEST_F(PlatformEventTest, DispatcherConsumesEventToStopDispatch) {
TestPlatformEventDispatcher first(12, &list_dispatcher);
TestPlatformEventDispatcher second(23, &list_dispatcher);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(2u, list_dispatcher.size());
EXPECT_EQ(12, list_dispatcher[0]);
@@ -215,13 +214,13 @@ TEST_F(PlatformEventTest, DispatcherConsumesEventToStopDispatch) {
// Tests that observers receive events.
TEST_F(PlatformEventTest, ObserverBasic) {
std::vector<int> list_observer;
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
EXPECT_EQ(0u, list_observer.size());
{
TestPlatformEventObserver observer(31, &list_observer);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(1u, list_observer.size());
EXPECT_EQ(31, list_observer[0]);
@@ -237,12 +236,12 @@ TEST_F(PlatformEventTest, ObserverBasic) {
TEST_F(PlatformEventTest, ObserverOrder) {
std::vector<int> list_observer;
const int sequence[] = {21, 3, 6, 45};
- ScopedVector<TestPlatformEventObserver> observers;
- for (size_t i = 0; i < arraysize(sequence); ++i) {
+ std::vector<std::unique_ptr<TestPlatformEventObserver>> observers;
+ for (auto id : sequence) {
observers.push_back(
- new TestPlatformEventObserver(sequence[i], &list_observer));
+ base::MakeUnique<TestPlatformEventObserver>(id, &list_observer));
}
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(arraysize(sequence), list_observer.size());
EXPECT_EQ(std::vector<int>(sequence, sequence + arraysize(sequence)),
@@ -256,7 +255,7 @@ TEST_F(PlatformEventTest, DispatcherAndObserverOrder) {
TestPlatformEventObserver first_o(10, &list);
TestPlatformEventDispatcher second_d(23, &list);
TestPlatformEventObserver second_o(20, &list);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
const int expected[] = {10, 20, 12, 23};
EXPECT_EQ(std::vector<int>(expected, expected + arraysize(expected)), list);
@@ -268,7 +267,7 @@ TEST_F(PlatformEventTest, OverriddenDispatcherBasic) {
std::vector<int> list;
TestPlatformEventDispatcher dispatcher(10, &list);
TestPlatformEventObserver observer(15, &list);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(2u, list.size());
EXPECT_EQ(15, list[0]);
@@ -297,7 +296,7 @@ TEST_F(PlatformEventTest, OverriddenDispatcherInvokeDefaultDispatcher) {
source()->OverrideDispatcher(&overriding_dispatcher);
overriding_dispatcher.set_post_dispatch_action(POST_DISPATCH_PERFORM_DEFAULT);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
// First the observer, then the overriding dispatcher, then the default
// dispatcher.
@@ -365,7 +364,7 @@ TEST_F(PlatformEventTest, DispatcherRemovesNextDispatcherDuringDispatch) {
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&third)));
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
// |second| removes |third| from the dispatcher list during dispatch. So the
// event should only reach |first|, |second|, and |fourth|.
@@ -385,7 +384,7 @@ TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatch) {
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second)));
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
// |second| removes itself from the dispatcher list during dispatch. So the
// event should reach all three dispatchers in the list.
@@ -405,7 +404,7 @@ TEST_F(PlatformEventTest, DispatcherRemovesSelfDuringDispatchLast) {
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&second)));
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
// |second| removes itself during dispatch. So both dispatchers will have
// received the event.
@@ -424,7 +423,7 @@ TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatcherDuringDispatch) {
second.set_callback(base::Bind(&RemoveDispatcher, base::Unretained(&first)));
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
// |second| removes |first| from the dispatcher list during dispatch. The
// event should reach all three dispatchers.
@@ -447,7 +446,7 @@ TEST_F(PlatformEventTest, DispatcherRemovesPrevDispatchersDuringDispatch) {
base::Unretained(&first),
base::Unretained(&second)));
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
// |third| removes |first| and |second| from the dispatcher list during
// dispatch. The event should reach all three dispatchers.
@@ -468,7 +467,7 @@ TEST_F(PlatformEventTest, DispatcherAddedDuringDispatchReceivesEvent) {
TestPlatformEventDispatcher fourth(30, &list);
RemoveDispatchers(&third, &fourth);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(2u, list.size());
EXPECT_EQ(10, list[0]);
@@ -539,7 +538,7 @@ class ScopedDispatcherRestoresAfterDestroy
std::unique_ptr<ScopedEventDispatcher> second_override_handle =
source()->OverrideDispatcher(&second_overriding);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(2u, list.size());
EXPECT_EQ(15, list[0]);
@@ -600,11 +599,9 @@ class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration
public:
void NestedTask(std::vector<int>* list,
TestPlatformEventDispatcher* dispatcher) {
- ScopedVector<PlatformEvent> events;
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
- events.push_back(std::move(event));
- event = CreatePlatformEvent();
- events.push_back(std::move(event));
+ std::vector<std::unique_ptr<PlatformEvent>> events;
+ events.push_back(CreatePlatformEvent());
+ events.push_back(CreatePlatformEvent());
// Attempt to dispatch a couple of events. Dispatching the first event will
// have terminated the ScopedEventDispatcher object, which will terminate
@@ -641,7 +638,7 @@ class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration
std::unique_ptr<ScopedEventDispatcher> override_handle =
source()->OverrideDispatcher(&overriding);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(2u, list.size());
EXPECT_EQ(15, list[0]);
@@ -682,7 +679,7 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration
public:
void NestedTask(std::unique_ptr<ScopedEventDispatcher> dispatch_handle,
std::vector<int>* list) {
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(2u, list->size());
EXPECT_EQ(15, (*list)[0]);
@@ -741,7 +738,7 @@ class ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration
std::unique_ptr<ScopedEventDispatcher> override_handle =
source()->OverrideDispatcher(&overriding);
- std::unique_ptr<PlatformEvent> event(CreatePlatformEvent());
+ std::unique_ptr<PlatformEvent> event = CreatePlatformEvent();
source()->Dispatch(*event);
ASSERT_EQ(2u, list.size());
EXPECT_EQ(15, list[0]);

Powered by Google App Engine
This is Rietveld 408576698