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

Side by Side Diff: ui/events/platform/platform_event_source_unittest.cc

Issue 1539583003: Convert Pass()→std::move() in ui/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
« no previous file with comments | « ui/events/latency_info.cc ('k') | ui/events/scoped_target_handler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/platform/platform_event_source.h" 5 #include "ui/events/platform/platform_event_source.h"
6 6
7 #include <utility>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
10 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 13 #include "base/run_loop.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/events/platform/platform_event_dispatcher.h" 15 #include "ui/events/platform/platform_event_dispatcher.h"
14 #include "ui/events/platform/platform_event_observer.h" 16 #include "ui/events/platform/platform_event_observer.h"
15 #include "ui/events/platform/scoped_event_dispatcher.h" 17 #include "ui/events/platform/scoped_event_dispatcher.h"
16 18
17 namespace ui { 19 namespace ui {
18 20
19 namespace { 21 namespace {
20 22
21 scoped_ptr<PlatformEvent> CreatePlatformEvent() { 23 scoped_ptr<PlatformEvent> CreatePlatformEvent() {
22 scoped_ptr<PlatformEvent> event(new PlatformEvent()); 24 scoped_ptr<PlatformEvent> event(new PlatformEvent());
23 memset(event.get(), 0, sizeof(PlatformEvent)); 25 memset(event.get(), 0, sizeof(PlatformEvent));
24 return event.Pass(); 26 return event;
25 } 27 }
26 28
27 template <typename T> 29 template <typename T>
28 void DestroyScopedPtr(scoped_ptr<T> object) {} 30 void DestroyScopedPtr(scoped_ptr<T> object) {}
29 31
30 void RemoveDispatcher(PlatformEventDispatcher* dispatcher) { 32 void RemoveDispatcher(PlatformEventDispatcher* dispatcher) {
31 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(dispatcher); 33 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(dispatcher);
32 } 34 }
33 35
34 void RemoveDispatchers(PlatformEventDispatcher* first, 36 void RemoveDispatchers(PlatformEventDispatcher* first,
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 559
558 // This dispatcher destroys the handle to the ScopedEventDispatcher when 560 // This dispatcher destroys the handle to the ScopedEventDispatcher when
559 // dispatching an event. 561 // dispatching an event.
560 class DestroyScopedHandleDispatcher : public TestPlatformEventDispatcher { 562 class DestroyScopedHandleDispatcher : public TestPlatformEventDispatcher {
561 public: 563 public:
562 DestroyScopedHandleDispatcher(int id, std::vector<int>* list) 564 DestroyScopedHandleDispatcher(int id, std::vector<int>* list)
563 : TestPlatformEventDispatcher(id, list) {} 565 : TestPlatformEventDispatcher(id, list) {}
564 ~DestroyScopedHandleDispatcher() override {} 566 ~DestroyScopedHandleDispatcher() override {}
565 567
566 void SetScopedHandle(scoped_ptr<ScopedEventDispatcher> handler) { 568 void SetScopedHandle(scoped_ptr<ScopedEventDispatcher> handler) {
567 handler_ = handler.Pass(); 569 handler_ = std::move(handler);
568 } 570 }
569 571
570 void set_callback(const base::Closure& callback) { 572 void set_callback(const base::Closure& callback) {
571 callback_ = callback; 573 callback_ = callback;
572 } 574 }
573 575
574 private: 576 private:
575 // PlatformEventDispatcher: 577 // PlatformEventDispatcher:
576 bool CanDispatchEvent(const PlatformEvent& event) override { return true; } 578 bool CanDispatchEvent(const PlatformEvent& event) override { return true; }
577 579
(...skipping 16 matching lines...) Expand all
594 // Tests that resetting an overridden dispatcher causes the nested message-loop 596 // Tests that resetting an overridden dispatcher causes the nested message-loop
595 // iteration to stop and the rest of the events are dispatched in the next 597 // iteration to stop and the rest of the events are dispatched in the next
596 // iteration. 598 // iteration.
597 class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration 599 class DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration
598 : public PlatformEventTestWithMessageLoop { 600 : public PlatformEventTestWithMessageLoop {
599 public: 601 public:
600 void NestedTask(std::vector<int>* list, 602 void NestedTask(std::vector<int>* list,
601 TestPlatformEventDispatcher* dispatcher) { 603 TestPlatformEventDispatcher* dispatcher) {
602 ScopedVector<PlatformEvent> events; 604 ScopedVector<PlatformEvent> events;
603 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); 605 scoped_ptr<PlatformEvent> event(CreatePlatformEvent());
604 events.push_back(event.Pass()); 606 events.push_back(std::move(event));
605 event = CreatePlatformEvent(); 607 event = CreatePlatformEvent();
606 events.push_back(event.Pass()); 608 events.push_back(std::move(event));
607 609
608 // Attempt to dispatch a couple of events. Dispatching the first event will 610 // Attempt to dispatch a couple of events. Dispatching the first event will
609 // have terminated the ScopedEventDispatcher object, which will terminate 611 // have terminated the ScopedEventDispatcher object, which will terminate
610 // the current iteration of the message-loop. 612 // the current iteration of the message-loop.
611 size_t count = source()->DispatchEventStream(events); 613 size_t count = source()->DispatchEventStream(events);
612 EXPECT_EQ(1u, count); 614 EXPECT_EQ(1u, count);
613 ASSERT_EQ(2u, list->size()); 615 ASSERT_EQ(2u, list->size());
614 EXPECT_EQ(15, (*list)[0]); 616 EXPECT_EQ(15, (*list)[0]);
615 EXPECT_EQ(20, (*list)[1]); 617 EXPECT_EQ(20, (*list)[1]);
616 list->clear(); 618 list->clear();
(...skipping 23 matching lines...) Expand all
640 scoped_ptr<ScopedEventDispatcher> override_handle = 642 scoped_ptr<ScopedEventDispatcher> override_handle =
641 source()->OverrideDispatcher(&overriding); 643 source()->OverrideDispatcher(&overriding);
642 644
643 scoped_ptr<PlatformEvent> event(CreatePlatformEvent()); 645 scoped_ptr<PlatformEvent> event(CreatePlatformEvent());
644 source()->Dispatch(*event); 646 source()->Dispatch(*event);
645 ASSERT_EQ(2u, list.size()); 647 ASSERT_EQ(2u, list.size());
646 EXPECT_EQ(15, list[0]); 648 EXPECT_EQ(15, list[0]);
647 EXPECT_EQ(20, list[1]); 649 EXPECT_EQ(20, list[1]);
648 list.clear(); 650 list.clear();
649 651
650 overriding.SetScopedHandle(override_handle.Pass()); 652 overriding.SetScopedHandle(std::move(override_handle));
651 base::RunLoop run_loop; 653 base::RunLoop run_loop;
652 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); 654 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
653 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); 655 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
654 loop->PostTask( 656 loop->PostTask(
655 FROM_HERE, 657 FROM_HERE,
656 base::Bind( 658 base::Bind(
657 &DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration:: 659 &DestroyedNestedOverriddenDispatcherQuitsNestedLoopIteration::
658 NestedTask, 660 NestedTask,
659 base::Unretained(this), 661 base::Unretained(this),
660 base::Unretained(&list), 662 base::Unretained(&list),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 source()->RemovePlatformEventDispatcher(&second_overriding); 703 source()->RemovePlatformEventDispatcher(&second_overriding);
702 scoped_ptr<ScopedEventDispatcher> second_override_handle = 704 scoped_ptr<ScopedEventDispatcher> second_override_handle =
703 source()->OverrideDispatcher(&second_overriding); 705 source()->OverrideDispatcher(&second_overriding);
704 706
705 source()->Dispatch(*event); 707 source()->Dispatch(*event);
706 ASSERT_EQ(2u, list->size()); 708 ASSERT_EQ(2u, list->size());
707 EXPECT_EQ(15, (*list)[0]); 709 EXPECT_EQ(15, (*list)[0]);
708 EXPECT_EQ(70, (*list)[1]); 710 EXPECT_EQ(70, (*list)[1]);
709 list->clear(); 711 list->clear();
710 712
711 second_overriding.SetScopedHandle(second_override_handle.Pass()); 713 second_overriding.SetScopedHandle(std::move(second_override_handle));
712 second_overriding.set_post_dispatch_action(POST_DISPATCH_NONE); 714 second_overriding.set_post_dispatch_action(POST_DISPATCH_NONE);
713 base::RunLoop run_loop; 715 base::RunLoop run_loop;
714 second_overriding.set_callback(run_loop.QuitClosure()); 716 second_overriding.set_callback(run_loop.QuitClosure());
715 base::MessageLoopForUI* loop = base::MessageLoopForUI::current(); 717 base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
716 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop); 718 base::MessageLoopForUI::ScopedNestableTaskAllower allow_nested(loop);
717 loop->PostTask( 719 loop->PostTask(
718 FROM_HERE, 720 FROM_HERE,
719 base::Bind(base::IgnoreResult(&TestPlatformEventSource::Dispatch), 721 base::Bind(base::IgnoreResult(&TestPlatformEventSource::Dispatch),
720 base::Unretained(source()), 722 base::Unretained(source()),
721 *event)); 723 *event));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 ASSERT_EQ(2u, list.size()); 770 ASSERT_EQ(2u, list.size());
769 EXPECT_EQ(15, list[0]); 771 EXPECT_EQ(15, list[0]);
770 EXPECT_EQ(10, list[1]); 772 EXPECT_EQ(10, list[1]);
771 } 773 }
772 }; 774 };
773 775
774 RUN_TEST_IN_MESSAGE_LOOP( 776 RUN_TEST_IN_MESSAGE_LOOP(
775 ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration) 777 ConsecutiveOverriddenDispatcherInTheSameMessageLoopIteration)
776 778
777 } // namespace ui 779 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/latency_info.cc ('k') | ui/events/scoped_target_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698