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

Side by Side Diff: chrome/browser/browser_keyevents_browsertest.cc

Issue 157713002: Switch DomAutomationController to be a RenderFrameObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | chrome/test/base/javascript_test_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
17 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/interactive_test_utils.h" 18 #include "chrome/test/base/interactive_test_utils.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/dom_operation_notification_details.h" 20 #include "content/public/browser/dom_operation_notification_details.h"
21 #include "content/public/browser/notification_registrar.h" 21 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/render_view_host.h"
24 #include "content/public/browser/render_widget_host_view.h" 23 #include "content/public/browser/render_widget_host_view.h"
25 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
26 #include "content/public/browser/web_contents_view.h" 25 #include "content/public/browser/web_contents_view.h"
27 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
28 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
29 #include "ui/events/keycodes/keyboard_codes.h" 28 #include "ui/events/keycodes/keyboard_codes.h"
30 29
31 // TODO(kbr): remove: http://crbug.com/222296 30 // TODO(kbr): remove: http://crbug.com/222296
32 #if defined(OS_MACOSX) 31 #if defined(OS_MACOSX)
33 #import "base/mac/mac_util.h" 32 #import "base/mac/mac_util.h"
34 #endif 33 #endif
35 34
36 using content::DomOperationNotificationDetails; 35 using content::DomOperationNotificationDetails;
37 using content::NavigationController; 36 using content::NavigationController;
38 using content::RenderViewHost;
39 37
40 namespace { 38 namespace {
41 39
42 const char kTestingPage[] = "/keyevents_test.html"; 40 const char kTestingPage[] = "/keyevents_test.html";
43 const char kSuppressEventJS[] = 41 const char kSuppressEventJS[] =
44 "window.domAutomationController.send(setDefaultAction('%ls', %ls));"; 42 "window.domAutomationController.send(setDefaultAction('%ls', %ls));";
45 const char kGetResultJS[] = 43 const char kGetResultJS[] =
46 "window.domAutomationController.send(keyEventResult[%d]);"; 44 "window.domAutomationController.send(keyEventResult[%d]);";
47 const char kGetResultLengthJS[] = 45 const char kGetResultLengthJS[] =
48 "window.domAutomationController.send(keyEventResult.length);"; 46 "window.domAutomationController.send(keyEventResult.length);";
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 const char* const result[kMaxResultLength]; 87 const char* const result[kMaxResultLength];
90 }; 88 };
91 89
92 const wchar_t* GetBoolString(bool value) { 90 const wchar_t* GetBoolString(bool value) {
93 return value ? L"true" : L"false"; 91 return value ? L"true" : L"false";
94 } 92 }
95 93
96 // A class to help wait for the finish of a key event test. 94 // A class to help wait for the finish of a key event test.
97 class TestFinishObserver : public content::NotificationObserver { 95 class TestFinishObserver : public content::NotificationObserver {
98 public: 96 public:
99 explicit TestFinishObserver(RenderViewHost* render_view_host) 97 explicit TestFinishObserver(content::WebContents* web_contents)
100 : finished_(false), waiting_(false) { 98 : finished_(false), waiting_(false) {
101 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, 99 registrar_.Add(this,
102 content::Source<RenderViewHost>(render_view_host)); 100 content::NOTIFICATION_DOM_OPERATION_RESPONSE,
101 content::Source<content::WebContents>(web_contents));
103 } 102 }
104 103
105 bool WaitForFinish() { 104 bool WaitForFinish() {
106 if (!finished_) { 105 if (!finished_) {
107 waiting_ = true; 106 waiting_ = true;
108 content::RunMessageLoop(); 107 content::RunMessageLoop();
109 waiting_ = false; 108 waiting_ = false;
110 } 109 }
111 return finished_; 110 return finished_;
112 } 111 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // event. 262 // event.
264 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length)); 263 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length));
265 ASSERT_NO_FATAL_FAILURE(SuppressEvents( 264 ASSERT_NO_FATAL_FAILURE(SuppressEvents(
266 tab_index, test.suppress_keydown, test.suppress_keypress, 265 tab_index, test.suppress_keydown, test.suppress_keypress,
267 test.suppress_keyup, test.suppress_textinput)); 266 test.suppress_keyup, test.suppress_textinput));
268 267
269 // We need to create a finish observer before sending the key event, 268 // We need to create a finish observer before sending the key event,
270 // because the test finished message might be arrived before returning 269 // because the test finished message might be arrived before returning
271 // from the SendKeyPressSync() method. 270 // from the SendKeyPressSync() method.
272 TestFinishObserver finish_observer( 271 TestFinishObserver finish_observer(
273 browser()->tab_strip_model()->GetWebContentsAt(tab_index)-> 272 browser()->tab_strip_model()->GetWebContentsAt(tab_index));
274 GetRenderViewHost());
275 273
276 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 274 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
277 browser(), test.key, test.ctrl, test.shift, test.alt, test.command)); 275 browser(), test.key, test.ctrl, test.shift, test.alt, test.command));
278 ASSERT_TRUE(finish_observer.WaitForFinish()); 276 ASSERT_TRUE(finish_observer.WaitForFinish());
279 ASSERT_NO_FATAL_FAILURE(CheckResult( 277 ASSERT_NO_FATAL_FAILURE(CheckResult(
280 tab_index, test.result_length, test.result)); 278 tab_index, test.result_length, test.result));
281 } 279 }
282 280
283 std::string GetTestDataDescription(const KeyEventTestData& data) { 281 std::string GetTestDataDescription(const KeyEventTestData& data) {
284 std::string desc = base::StringPrintf( 282 std::string desc = base::StringPrintf(
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); 871 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress));
874 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); 872 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
875 873
876 // Ctrl+Alt should have no effect. 874 // Ctrl+Alt should have no effect.
877 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); 875 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey));
878 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); 876 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
879 } 877 }
880 #endif 878 #endif
881 879
882 } // namespace 880 } // namespace
OLDNEW
« no previous file with comments | « no previous file | chrome/test/base/javascript_test_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698