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

Side by Side Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 23416003: Add content::RenderWidgetHost::MouseEventCallback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a callback instead of a single-method interface Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/shared_memory.h" 7 #include "base/memory/shared_memory.h"
8 #include "base/timer/timer.h" 8 #include "base/timer/timer.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/renderer_host/backing_store.h" 10 #include "content/browser/renderer_host/backing_store.h"
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 private: 621 private:
622 MockRenderWidgetHost* host_; 622 MockRenderWidgetHost* host_;
623 int tag_; 623 int tag_;
624 gfx::Size size_; 624 gfx::Size size_;
625 }; 625 };
626 626
627 // RenderWidgetHostTest -------------------------------------------------------- 627 // RenderWidgetHostTest --------------------------------------------------------
628 628
629 class RenderWidgetHostTest : public testing::Test { 629 class RenderWidgetHostTest : public testing::Test {
630 public: 630 public:
631 RenderWidgetHostTest() : process_(NULL) { 631 RenderWidgetHostTest()
632 : process_(NULL),
633 handle_mouse_event_(false) {
632 } 634 }
633 virtual ~RenderWidgetHostTest() { 635 virtual ~RenderWidgetHostTest() {
634 } 636 }
635 637
638 bool MouseEventCallback(const WebKit::WebMouseEvent& /* event */) {
639 return handle_mouse_event_;
640 }
641
636 protected: 642 protected:
637 // testing::Test 643 // testing::Test
638 virtual void SetUp() { 644 virtual void SetUp() {
639 browser_context_.reset(new TestBrowserContext()); 645 browser_context_.reset(new TestBrowserContext());
640 delegate_.reset(new MockRenderWidgetHostDelegate()); 646 delegate_.reset(new MockRenderWidgetHostDelegate());
641 process_ = new RenderWidgetHostProcess(browser_context_.get()); 647 process_ = new RenderWidgetHostProcess(browser_context_.get());
642 #if defined(USE_AURA) 648 #if defined(USE_AURA)
643 screen_.reset(aura::TestScreen::Create()); 649 screen_.reset(aura::TestScreen::Create());
644 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); 650 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
645 #endif 651 #endif
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 } 834 }
829 835
830 base::MessageLoopForUI message_loop_; 836 base::MessageLoopForUI message_loop_;
831 837
832 scoped_ptr<TestBrowserContext> browser_context_; 838 scoped_ptr<TestBrowserContext> browser_context_;
833 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. 839 RenderWidgetHostProcess* process_; // Deleted automatically by the widget.
834 scoped_ptr<MockRenderWidgetHostDelegate> delegate_; 840 scoped_ptr<MockRenderWidgetHostDelegate> delegate_;
835 scoped_ptr<MockRenderWidgetHost> host_; 841 scoped_ptr<MockRenderWidgetHost> host_;
836 scoped_ptr<TestView> view_; 842 scoped_ptr<TestView> view_;
837 scoped_ptr<gfx::Screen> screen_; 843 scoped_ptr<gfx::Screen> screen_;
844 bool handle_mouse_event_;
838 845
839 private: 846 private:
840 WebTouchEvent touch_event_; 847 WebTouchEvent touch_event_;
841 848
842 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); 849 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
843 }; 850 };
844 851
845 #if GTEST_HAS_PARAM_TEST 852 #if GTEST_HAS_PARAM_TEST
846 // RenderWidgetHostWithSourceTest ---------------------------------------------- 853 // RenderWidgetHostWithSourceTest ----------------------------------------------
847 854
(...skipping 1685 matching lines...) Expand 10 before | Expand all | Expand 10 after
2533 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); 2540 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
2534 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_); 2541 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2535 2542
2536 host_->mock_input_router()->sent_keyboard_event_ = false; 2543 host_->mock_input_router()->sent_keyboard_event_ = false;
2537 SimulateKeyboardEvent(WebInputEvent::Char); 2544 SimulateKeyboardEvent(WebInputEvent::Char);
2538 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_); 2545 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2539 2546
2540 host_->RemoveKeyboardListener(keyboard_listener_.get()); 2547 host_->RemoveKeyboardListener(keyboard_listener_.get());
2541 } 2548 }
2542 2549
2550 TEST_F(RenderWidgetHostTest, MouseEventCallbackCanHandleEvent) {
2551 host_->SetupForInputRouterTest();
2552
2553 host_->AddMouseEventCallback(
2554 base::Bind(&RenderWidgetHostTest::MouseEventCallback,
2555 base::Unretained(this)));
2556
2557 handle_mouse_event_ = true;
2558 SimulateMouseEvent(WebInputEvent::MouseDown);
2559
2560 EXPECT_FALSE(host_->mock_input_router()->sent_mouse_event_);
2561
2562 handle_mouse_event_ = false;
2563 SimulateMouseEvent(WebInputEvent::MouseDown);
2564
2565 EXPECT_TRUE(host_->mock_input_router()->sent_mouse_event_);
2566 }
2567
2543 TEST_F(RenderWidgetHostTest, InputRouterReceivesHandleInputEvent_ACK) { 2568 TEST_F(RenderWidgetHostTest, InputRouterReceivesHandleInputEvent_ACK) {
2544 host_->SetupForInputRouterTest(); 2569 host_->SetupForInputRouterTest();
2545 2570
2546 SendInputEventACK(WebInputEvent::RawKeyDown, 2571 SendInputEventACK(WebInputEvent::RawKeyDown,
2547 INPUT_EVENT_ACK_STATE_CONSUMED); 2572 INPUT_EVENT_ACK_STATE_CONSUMED);
2548 2573
2549 EXPECT_TRUE(host_->mock_input_router()->message_received_); 2574 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2550 } 2575 }
2551 2576
2552 TEST_F(RenderWidgetHostTest, InputRouterReceivesMoveCaret_ACK) { 2577 TEST_F(RenderWidgetHostTest, InputRouterReceivesMoveCaret_ACK) {
(...skipping 14 matching lines...) Expand all
2567 2592
2568 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) { 2593 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) {
2569 host_->SetupForInputRouterTest(); 2594 host_->SetupForInputRouterTest();
2570 2595
2571 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 2596 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2572 2597
2573 EXPECT_TRUE(host_->mock_input_router()->message_received_); 2598 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2574 } 2599 }
2575 2600
2576 } // namespace content 2601 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698