| OLD | NEW |
| 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 "content/browser/renderer_host/render_widget_host_view_aura.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "content/public/test/test_browser_context.h" | 32 #include "content/public/test/test_browser_context.h" |
| 33 #include "ipc/ipc_test_sink.h" | 33 #include "ipc/ipc_test_sink.h" |
| 34 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "ui/aura/client/aura_constants.h" | 36 #include "ui/aura/client/aura_constants.h" |
| 37 #include "ui/aura/client/screen_position_client.h" | 37 #include "ui/aura/client/screen_position_client.h" |
| 38 #include "ui/aura/client/window_tree_client.h" | 38 #include "ui/aura/client/window_tree_client.h" |
| 39 #include "ui/aura/env.h" | 39 #include "ui/aura/env.h" |
| 40 #include "ui/aura/layout_manager.h" | 40 #include "ui/aura/layout_manager.h" |
| 41 #include "ui/aura/test/aura_test_helper.h" | 41 #include "ui/aura/test/aura_test_helper.h" |
| 42 #include "ui/aura/test/aura_test_utils.h" |
| 42 #include "ui/aura/test/test_cursor_client.h" | 43 #include "ui/aura/test/test_cursor_client.h" |
| 43 #include "ui/aura/test/test_screen.h" | 44 #include "ui/aura/test/test_screen.h" |
| 44 #include "ui/aura/test/test_window_delegate.h" | 45 #include "ui/aura/test/test_window_delegate.h" |
| 45 #include "ui/aura/window.h" | 46 #include "ui/aura/window.h" |
| 46 #include "ui/aura/window_event_dispatcher.h" | 47 #include "ui/aura/window_event_dispatcher.h" |
| 47 #include "ui/aura/window_observer.h" | 48 #include "ui/aura/window_observer.h" |
| 48 #include "ui/base/ui_base_types.h" | 49 #include "ui/base/ui_base_types.h" |
| 49 #include "ui/compositor/compositor.h" | 50 #include "ui/compositor/compositor.h" |
| 50 #include "ui/compositor/test/draw_waiter_for_test.h" | 51 #include "ui/compositor/test/draw_waiter_for_test.h" |
| 51 #include "ui/events/event.h" | 52 #include "ui/events/event.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 base::TimeTicks timestamp, | 211 base::TimeTicks timestamp, |
| 211 bool success) { | 212 bool success) { |
| 212 callback.Run(success); | 213 callback.Run(success); |
| 213 } | 214 } |
| 214 | 215 |
| 215 private: | 216 private: |
| 216 gfx::Size size_; | 217 gfx::Size size_; |
| 217 base::Callback<void(bool)> callback_; | 218 base::Callback<void(bool)> callback_; |
| 218 }; | 219 }; |
| 219 | 220 |
| 221 class FakeWindowEventDispatcher : public aura::WindowEventDispatcher { |
| 222 public: |
| 223 FakeWindowEventDispatcher(aura::WindowTreeHost* host) |
| 224 : WindowEventDispatcher(host), |
| 225 processed_touch_event_count_(0) {} |
| 226 virtual void ProcessedTouchEvent(aura::Window* window, |
| 227 ui::EventResult result) OVERRIDE { |
| 228 WindowEventDispatcher::ProcessedTouchEvent(window, result); |
| 229 processed_touch_event_count_++; |
| 230 } |
| 231 |
| 232 size_t processed_touch_event_count() { |
| 233 return processed_touch_event_count_; |
| 234 } |
| 235 |
| 236 private: |
| 237 size_t processed_touch_event_count_; |
| 238 }; |
| 239 |
| 220 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { | 240 class FakeRenderWidgetHostViewAura : public RenderWidgetHostViewAura { |
| 221 public: | 241 public: |
| 222 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) | 242 FakeRenderWidgetHostViewAura(RenderWidgetHost* widget) |
| 223 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} | 243 : RenderWidgetHostViewAura(widget), has_resize_lock_(false) {} |
| 224 | 244 |
| 245 void UseFakeDispatcher() { |
| 246 dispatcher_ = new FakeWindowEventDispatcher(window()->GetHost()); |
| 247 aura::test::WindowTreeHostTestApi host(window()->GetHost()); |
| 248 host.set_dispatcher(dispatcher_); |
| 249 } |
| 250 |
| 225 virtual ~FakeRenderWidgetHostViewAura() {} | 251 virtual ~FakeRenderWidgetHostViewAura() {} |
| 226 | 252 |
| 227 virtual scoped_ptr<ResizeLock> CreateResizeLock( | 253 virtual scoped_ptr<ResizeLock> CreateResizeLock( |
| 228 bool defer_compositor_lock) OVERRIDE { | 254 bool defer_compositor_lock) OVERRIDE { |
| 229 gfx::Size desired_size = window()->bounds().size(); | 255 gfx::Size desired_size = window()->bounds().size(); |
| 230 return scoped_ptr<ResizeLock>( | 256 return scoped_ptr<ResizeLock>( |
| 231 new FakeResizeLock(desired_size, defer_compositor_lock)); | 257 new FakeResizeLock(desired_size, defer_compositor_lock)); |
| 232 } | 258 } |
| 233 | 259 |
| 234 void RunOnCompositingDidCommit() { | 260 void RunOnCompositingDidCommit() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 // time out. | 292 // time out. |
| 267 class FakeResizeLock : public ResizeLock { | 293 class FakeResizeLock : public ResizeLock { |
| 268 public: | 294 public: |
| 269 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) | 295 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) |
| 270 : ResizeLock(new_size, defer_compositor_lock) {} | 296 : ResizeLock(new_size, defer_compositor_lock) {} |
| 271 }; | 297 }; |
| 272 | 298 |
| 273 bool has_resize_lock_; | 299 bool has_resize_lock_; |
| 274 gfx::Size last_frame_size_; | 300 gfx::Size last_frame_size_; |
| 275 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; | 301 scoped_ptr<cc::CopyOutputRequest> last_copy_request_; |
| 302 FakeWindowEventDispatcher* dispatcher_; |
| 276 }; | 303 }; |
| 277 | 304 |
| 278 // A layout manager that always resizes a child to the root window size. | 305 // A layout manager that always resizes a child to the root window size. |
| 279 class FullscreenLayoutManager : public aura::LayoutManager { | 306 class FullscreenLayoutManager : public aura::LayoutManager { |
| 280 public: | 307 public: |
| 281 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {} | 308 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {} |
| 282 virtual ~FullscreenLayoutManager() {} | 309 virtual ~FullscreenLayoutManager() {} |
| 283 | 310 |
| 284 // Overridden from aura::LayoutManager: | 311 // Overridden from aura::LayoutManager: |
| 285 virtual void OnWindowResized() OVERRIDE { | 312 virtual void OnWindowResized() OVERRIDE { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 387 |
| 361 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 388 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
| 362 message_loop_.RunUntilIdle(); | 389 message_loop_.RunUntilIdle(); |
| 363 ImageTransportFactory::Terminate(); | 390 ImageTransportFactory::Terminate(); |
| 364 } | 391 } |
| 365 | 392 |
| 366 virtual void SetUp() { SetUpEnvironment(); } | 393 virtual void SetUp() { SetUpEnvironment(); } |
| 367 | 394 |
| 368 virtual void TearDown() { TearDownEnvironment(); } | 395 virtual void TearDown() { TearDownEnvironment(); } |
| 369 | 396 |
| 397 void SendInputEventACK(WebInputEvent::Type type, |
| 398 InputEventAckState ack_result) { |
| 399 InputHostMsg_HandleInputEvent_ACK_Params ack; |
| 400 ack.type = type; |
| 401 ack.state = ack_result; |
| 402 InputHostMsg_HandleInputEvent_ACK response(0, ack); |
| 403 widget_host_->OnMessageReceived(response); |
| 404 } |
| 405 |
| 370 protected: | 406 protected: |
| 371 base::MessageLoopForUI message_loop_; | 407 base::MessageLoopForUI message_loop_; |
| 372 BrowserThreadImpl browser_thread_for_ui_; | 408 BrowserThreadImpl browser_thread_for_ui_; |
| 373 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; | 409 scoped_ptr<aura::test::AuraTestHelper> aura_test_helper_; |
| 374 scoped_ptr<BrowserContext> browser_context_; | 410 scoped_ptr<BrowserContext> browser_context_; |
| 375 MockRenderWidgetHostDelegate delegate_; | 411 MockRenderWidgetHostDelegate delegate_; |
| 376 MockRenderProcessHost* process_host_; | 412 MockRenderProcessHost* process_host_; |
| 377 | 413 |
| 378 // Tests should set these to NULL if they've already triggered their | 414 // Tests should set these to NULL if they've already triggered their |
| 379 // destruction. | 415 // destruction. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 } | 549 } |
| 514 | 550 |
| 515 // Inject synthetic GestureFlingStart events. | 551 // Inject synthetic GestureFlingStart events. |
| 516 void SimulateGestureFlingStartEvent(float velocityX, | 552 void SimulateGestureFlingStartEvent(float velocityX, |
| 517 float velocityY, | 553 float velocityY, |
| 518 blink::WebGestureDevice sourceDevice) { | 554 blink::WebGestureDevice sourceDevice) { |
| 519 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( | 555 SimulateGestureEventCore(SyntheticWebGestureEventBuilder::BuildFling( |
| 520 velocityX, velocityY, sourceDevice)); | 556 velocityX, velocityY, sourceDevice)); |
| 521 } | 557 } |
| 522 | 558 |
| 523 void SendInputEventACK(WebInputEvent::Type type, | |
| 524 InputEventAckState ack_result) { | |
| 525 InputHostMsg_HandleInputEvent_ACK_Params ack; | |
| 526 ack.type = type; | |
| 527 ack.state = ack_result; | |
| 528 InputHostMsg_HandleInputEvent_ACK response(0, ack); | |
| 529 widget_host_->OnMessageReceived(response); | |
| 530 } | |
| 531 | |
| 532 bool ScrollStateIsContentScrolling() const { | 559 bool ScrollStateIsContentScrolling() const { |
| 533 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; | 560 return scroll_state() == OverscrollController::STATE_CONTENT_SCROLLING; |
| 534 } | 561 } |
| 535 | 562 |
| 536 bool ScrollStateIsOverscrolling() const { | 563 bool ScrollStateIsOverscrolling() const { |
| 537 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; | 564 return scroll_state() == OverscrollController::STATE_OVERSCROLLING; |
| 538 } | 565 } |
| 539 | 566 |
| 540 bool ScrollStateIsUnknown() const { | 567 bool ScrollStateIsUnknown() const { |
| 541 return scroll_state() == OverscrollController::STATE_UNKNOWN; | 568 return scroll_state() == OverscrollController::STATE_UNKNOWN; |
| (...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2746 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); | 2773 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->current_mode()); |
| 2747 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); | 2774 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->completed_mode()); |
| 2748 | 2775 |
| 2749 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | 2776 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, |
| 2750 blink::WebGestureDeviceTouchscreen); | 2777 blink::WebGestureDeviceTouchscreen); |
| 2751 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); | 2778 EXPECT_EQ(OVERSCROLL_NONE, overscroll_delegate()->current_mode()); |
| 2752 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); | 2779 EXPECT_EQ(OVERSCROLL_EAST, overscroll_delegate()->completed_mode()); |
| 2753 EXPECT_EQ(3U, sink_->message_count()); | 2780 EXPECT_EQ(3U, sink_->message_count()); |
| 2754 } | 2781 } |
| 2755 | 2782 |
| 2783 // Ensures that the mapping from ui::TouchEvent to blink::WebTouchEvent doesn't |
| 2784 // lose track of the number of acks required. |
| 2785 TEST_F(RenderWidgetHostViewAuraTest, CorrectNumberOfAcksAreDispatched) { |
| 2786 view_->InitAsFullscreen(parent_view_); |
| 2787 view_->Show(); |
| 2788 view_->UseFakeDispatcher(); |
| 2789 |
| 2790 ui::TouchEvent press1( |
| 2791 ui::ET_TOUCH_PRESSED, gfx::Point(30, 30), 0, ui::EventTimeForNow()); |
| 2792 |
| 2793 view_->OnTouchEvent(&press1); |
| 2794 SendInputEventACK(blink::WebInputEvent::TouchStart, |
| 2795 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2796 |
| 2797 ui::TouchEvent press2( |
| 2798 ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 1, ui::EventTimeForNow()); |
| 2799 view_->OnTouchEvent(&press2); |
| 2800 SendInputEventACK(blink::WebInputEvent::TouchStart, |
| 2801 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2802 |
| 2803 EXPECT_EQ(2U, view_->dispatcher_->processed_touch_event_count()); |
| 2804 } |
| 2805 |
| 2756 } // namespace content | 2806 } // namespace content |
| OLD | NEW |