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

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: Rebased changes 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/bind.h" 6 #include "base/bind.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "content/browser/browser_thread_impl.h" 10 #include "content/browser/browser_thread_impl.h"
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 private: 598 private:
599 MockRenderWidgetHost* host_; 599 MockRenderWidgetHost* host_;
600 int tag_; 600 int tag_;
601 gfx::Size size_; 601 gfx::Size size_;
602 }; 602 };
603 603
604 // RenderWidgetHostTest -------------------------------------------------------- 604 // RenderWidgetHostTest --------------------------------------------------------
605 605
606 class RenderWidgetHostTest : public testing::Test { 606 class RenderWidgetHostTest : public testing::Test {
607 public: 607 public:
608 RenderWidgetHostTest() : process_(NULL), handle_key_press_event_(false) { 608 RenderWidgetHostTest()
609 : process_(NULL),
610 handle_key_press_event_(false),
611 handle_mouse_event_(false) {
609 } 612 }
610 virtual ~RenderWidgetHostTest() { 613 virtual ~RenderWidgetHostTest() {
611 } 614 }
612 615
613 bool KeyPressEventCallback(const NativeWebKeyboardEvent& event) { 616 bool KeyPressEventCallback(const NativeWebKeyboardEvent& /* event */) {
614 return handle_key_press_event_; 617 return handle_key_press_event_;
615 } 618 }
619 bool MouseEventCallback(const WebKit::WebMouseEvent& /* event */) {
620 return handle_mouse_event_;
621 }
616 622
617 protected: 623 protected:
618 // testing::Test 624 // testing::Test
619 virtual void SetUp() { 625 virtual void SetUp() {
620 browser_context_.reset(new TestBrowserContext()); 626 browser_context_.reset(new TestBrowserContext());
621 delegate_.reset(new MockRenderWidgetHostDelegate()); 627 delegate_.reset(new MockRenderWidgetHostDelegate());
622 process_ = new RenderWidgetHostProcess(browser_context_.get()); 628 process_ = new RenderWidgetHostProcess(browser_context_.get());
623 #if defined(USE_AURA) 629 #if defined(USE_AURA)
624 screen_.reset(aura::TestScreen::Create()); 630 screen_.reset(aura::TestScreen::Create());
625 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); 631 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 816
811 base::MessageLoopForUI message_loop_; 817 base::MessageLoopForUI message_loop_;
812 818
813 scoped_ptr<TestBrowserContext> browser_context_; 819 scoped_ptr<TestBrowserContext> browser_context_;
814 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. 820 RenderWidgetHostProcess* process_; // Deleted automatically by the widget.
815 scoped_ptr<MockRenderWidgetHostDelegate> delegate_; 821 scoped_ptr<MockRenderWidgetHostDelegate> delegate_;
816 scoped_ptr<MockRenderWidgetHost> host_; 822 scoped_ptr<MockRenderWidgetHost> host_;
817 scoped_ptr<TestView> view_; 823 scoped_ptr<TestView> view_;
818 scoped_ptr<gfx::Screen> screen_; 824 scoped_ptr<gfx::Screen> screen_;
819 bool handle_key_press_event_; 825 bool handle_key_press_event_;
826 bool handle_mouse_event_;
820 827
821 private: 828 private:
822 WebTouchEvent touch_event_; 829 WebTouchEvent touch_event_;
823 830
824 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); 831 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest);
825 }; 832 };
826 833
827 #if GTEST_HAS_PARAM_TEST 834 #if GTEST_HAS_PARAM_TEST
828 // RenderWidgetHostWithSourceTest ---------------------------------------------- 835 // RenderWidgetHostWithSourceTest ----------------------------------------------
829 836
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after
2511 2518
2512 // Sending RawKeyDown event should stop suppression 2519 // Sending RawKeyDown event should stop suppression
2513 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); 2520 SimulateKeyboardEvent(WebInputEvent::RawKeyDown);
2514 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_); 2521 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2515 2522
2516 host_->mock_input_router()->sent_keyboard_event_ = false; 2523 host_->mock_input_router()->sent_keyboard_event_ = false;
2517 SimulateKeyboardEvent(WebInputEvent::Char); 2524 SimulateKeyboardEvent(WebInputEvent::Char);
2518 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_); 2525 EXPECT_TRUE(host_->mock_input_router()->sent_keyboard_event_);
2519 } 2526 }
2520 2527
2528 TEST_F(RenderWidgetHostTest, MouseEventCallbackCanHandleEvent) {
2529 host_->SetupForInputRouterTest();
2530
2531 host_->AddMouseEventCallback(
2532 base::Bind(&RenderWidgetHostTest::MouseEventCallback,
2533 base::Unretained(this)));
2534
2535 handle_mouse_event_ = true;
2536 SimulateMouseEvent(WebInputEvent::MouseDown);
2537
2538 EXPECT_FALSE(host_->mock_input_router()->sent_mouse_event_);
2539
2540 handle_mouse_event_ = false;
2541 SimulateMouseEvent(WebInputEvent::MouseDown);
2542
2543 EXPECT_TRUE(host_->mock_input_router()->sent_mouse_event_);
2544 }
2545
2521 TEST_F(RenderWidgetHostTest, InputRouterReceivesHandleInputEvent_ACK) { 2546 TEST_F(RenderWidgetHostTest, InputRouterReceivesHandleInputEvent_ACK) {
2522 host_->SetupForInputRouterTest(); 2547 host_->SetupForInputRouterTest();
2523 2548
2524 SendInputEventACK(WebInputEvent::RawKeyDown, 2549 SendInputEventACK(WebInputEvent::RawKeyDown,
2525 INPUT_EVENT_ACK_STATE_CONSUMED); 2550 INPUT_EVENT_ACK_STATE_CONSUMED);
2526 2551
2527 EXPECT_TRUE(host_->mock_input_router()->message_received_); 2552 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2528 } 2553 }
2529 2554
2530 TEST_F(RenderWidgetHostTest, InputRouterReceivesMoveCaret_ACK) { 2555 TEST_F(RenderWidgetHostTest, InputRouterReceivesMoveCaret_ACK) {
(...skipping 14 matching lines...) Expand all
2545 2570
2546 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) { 2571 TEST_F(RenderWidgetHostTest, InputRouterReceivesHasTouchEventHandlers) {
2547 host_->SetupForInputRouterTest(); 2572 host_->SetupForInputRouterTest();
2548 2573
2549 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); 2574 host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
2550 2575
2551 EXPECT_TRUE(host_->mock_input_router()->message_received_); 2576 EXPECT_TRUE(host_->mock_input_router()->message_received_);
2552 } 2577 }
2553 2578
2554 } // namespace content 2579 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | content/public/browser/render_widget_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698