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

Side by Side Diff: chrome/browser/automation/automation_tab_helper_browsertest.cc

Issue 10384023: Determine the element location and click synchronously on the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 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 | Annotate | Revision Log
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 <string> 5 #include <string>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/automation/automation_tab_helper.h" 12 #include "chrome/browser/automation/automation_tab_helper.h"
13 #include "chrome/browser/automation/mock_tab_event_observer.h" 13 #include "chrome/browser/automation/mock_tab_event_observer.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/common/automation_events.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/in_process_browser_test.h" 20 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h" 21 #include "chrome/test/base/ui_test_utils.h"
21 #include "content/public/browser/notification_details.h" 22 #include "content/public/browser/notification_details.h"
22 #include "content/public/browser/notification_observer.h" 23 #include "content/public/browser/notification_observer.h"
23 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
26 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "net/base/net_util.h" 29 #include "net/base/net_util.h"
29 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
32 #include "ui/gfx/point.h"
31 33
32 using testing::_; 34 using testing::_;
33 35
34 class MockNotificationObserver : public content::NotificationObserver { 36 class MockNotificationObserver : public content::NotificationObserver {
35 public: 37 public:
36 MockNotificationObserver() { } 38 MockNotificationObserver() { }
37 virtual ~MockNotificationObserver() { } 39 virtual ~MockNotificationObserver() { }
38 40
39 MOCK_METHOD3(Observe, void(int type, 41 MOCK_METHOD3(Observe, void(int type,
40 const content::NotificationSource& source, 42 const content::NotificationSource& source,
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, 209 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest,
208 CrashedTabStopsLoading) { 210 CrashedTabStopsLoading) {
209 MockTabEventObserver mock_tab_observer(tab_helper()); 211 MockTabEventObserver mock_tab_observer(tab_helper());
210 212
211 testing::InSequence expect_in_sequence; 213 testing::InSequence expect_in_sequence;
212 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_)); 214 EXPECT_CALL(mock_tab_observer, OnFirstPendingLoad(_));
213 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_)); 215 EXPECT_CALL(mock_tab_observer, OnNoMorePendingLoads(_));
214 216
215 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL)); 217 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUICrashURL));
216 } 218 }
219
220 IN_PROC_BROWSER_TEST_F(AutomationTabHelperBrowserTest, ProcessMouseEvent) {
221 MockTabEventObserver mock_tab_observer(tab_helper());
222
223 EXPECT_CALL(mock_tab_observer,
224 OnWillProcessMouseEventAt(
225 testing::AllOf(
226 testing::Property(&gfx::Point::x, testing::Eq(5)),
227 testing::Property(&gfx::Point::y, testing::Eq(10)))))
228 .Times(2);
229 EXPECT_CALL(mock_tab_observer, OnProcessMouseEventACK(true, _))
230 .Times(2);
231
232 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
233 browser()->GetSelectedWebContents()->GetRenderViewHost(),
234 L"",
235 L"window.didClick = false;"
236 L"document.body.innerHTML ="
237 L" '<a style=\\'position:absolute; left:0; top:0\\'>link</a>';"
238 L"document.querySelector('a').addEventListener('click', function() {"
239 L" window.didClick = true;"
240 L"}, true);"));
241 AutomationMouseEvent automation_event;
242 automation_event.location_script_chain.push_back(
243 ScriptEvaluationRequest("{'x': 5, 'y': 10}", ""));
244 WebKit::WebMouseEvent& mouse_event = automation_event.mouse_event;
245 mouse_event.type = WebKit::WebInputEvent::MouseDown;
246 mouse_event.button = WebKit::WebMouseEvent::ButtonLeft;
247 mouse_event.clickCount = 1;
248 tab_helper()->ProcessMouseEvent(automation_event);
249 mouse_event.type = WebKit::WebInputEvent::MouseUp;
250 tab_helper()->ProcessMouseEvent(automation_event);
251
252 bool did_click = false;
253 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
254 browser()->GetSelectedWebContents()->GetRenderViewHost(),
255 L"",
256 L"window.domAutomationController.send(window.didClick);",
257 &did_click));
258 EXPECT_TRUE(did_click);
259 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698