OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
| 9 #include "chrome/browser/automation/automation_provider_observers.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 12 #include "chrome/common/automation_constants.h" |
| 13 #include "chrome/common/automation_events.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/browser/render_view_host.h" |
| 17 #include "content/public/browser/web_contents.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 21 #include "ui/gfx/point.h" |
| 22 |
| 23 class AutomationMiscBrowserTest : public InProcessBrowserTest { |
| 24 public: |
| 25 AutomationMiscBrowserTest() { |
| 26 EnableDOMAutomation(); |
| 27 } |
| 28 |
| 29 virtual ~AutomationMiscBrowserTest() { } |
| 30 }; |
| 31 |
| 32 class MockMouseEventCallback { |
| 33 public: |
| 34 typedef AutomationMouseEventProcessor::CompletionCallback CompletionCallback; |
| 35 typedef AutomationMouseEventProcessor::ErrorCallback ErrorCallback; |
| 36 |
| 37 MockMouseEventCallback() { |
| 38 completion_callback_ = base::Bind( |
| 39 &MockMouseEventCallback::OnSuccess, |
| 40 base::Unretained(this)); |
| 41 error_callback_ = base::Bind( |
| 42 &MockMouseEventCallback::OnError, |
| 43 base::Unretained(this)); |
| 44 } |
| 45 virtual ~MockMouseEventCallback() { } |
| 46 |
| 47 MOCK_METHOD1(OnSuccess, void(const gfx::Point& point)); |
| 48 MOCK_METHOD1(OnError, void(const automation::Error&)); |
| 49 |
| 50 const CompletionCallback& completion_callback() { |
| 51 return completion_callback_; |
| 52 } |
| 53 |
| 54 const ErrorCallback& error_callback() { |
| 55 return error_callback_; |
| 56 } |
| 57 |
| 58 private: |
| 59 CompletionCallback completion_callback_; |
| 60 ErrorCallback error_callback_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(MockMouseEventCallback); |
| 63 }; |
| 64 |
| 65 // Tests that automation mouse events are processed correctly by the renderer. |
| 66 IN_PROC_BROWSER_TEST_F(AutomationMiscBrowserTest, ProcessMouseEvent) { |
| 67 MockMouseEventCallback mock; |
| 68 EXPECT_CALL(mock, |
| 69 OnSuccess( |
| 70 testing::AllOf( |
| 71 testing::Property(&gfx::Point::x, testing::Eq(5)), |
| 72 testing::Property(&gfx::Point::y, testing::Eq(10))))) |
| 73 .Times(2); |
| 74 |
| 75 content::RenderViewHost* view = |
| 76 browser()->GetSelectedWebContents()->GetRenderViewHost(); |
| 77 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( |
| 78 view, |
| 79 L"", |
| 80 L"window.didClick = false;" |
| 81 L"document.body.innerHTML =" |
| 82 L" '<a style=\\'position:absolute; left:0; top:0\\'>link</a>';" |
| 83 L"document.querySelector('a').addEventListener('click', function() {" |
| 84 L" window.didClick = true;" |
| 85 L"}, true);")); |
| 86 AutomationMouseEvent automation_event; |
| 87 automation_event.location_script_chain.push_back( |
| 88 ScriptEvaluationRequest("{'x': 5, 'y': 10}", "")); |
| 89 WebKit::WebMouseEvent& mouse_event = automation_event.mouse_event; |
| 90 mouse_event.type = WebKit::WebInputEvent::MouseDown; |
| 91 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft; |
| 92 mouse_event.clickCount = 1; |
| 93 new AutomationMouseEventProcessor( |
| 94 view, automation_event, mock.completion_callback(), |
| 95 mock.error_callback()); |
| 96 mouse_event.type = WebKit::WebInputEvent::MouseUp; |
| 97 new AutomationMouseEventProcessor( |
| 98 view, automation_event, mock.completion_callback(), |
| 99 mock.error_callback()); |
| 100 |
| 101 bool did_click = false; |
| 102 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
| 103 view, |
| 104 L"", |
| 105 L"window.domAutomationController.send(window.didClick);", |
| 106 &did_click)); |
| 107 EXPECT_TRUE(did_click); |
| 108 } |
OLD | NEW |