| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "remote_desktop_browsertest.h" | 5 #include "remote_desktop_browsertest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "chrome/common/extensions/extension_file_util.h" | 11 #include "chrome/common/extensions/extension_file_util.h" |
| 12 #include "content/public/browser/native_web_keyboard_event.h" | 12 #include "content/public/browser/native_web_keyboard_event.h" |
| 13 #include "content/public/browser/render_view_host.h" | 13 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
| 15 | 15 |
| 16 using extensions::Extension; | 16 using extensions::Extension; |
| 17 | 17 |
| 18 namespace remoting { | 18 namespace remoting { |
| 19 | 19 |
| 20 // BuildSimpleWebKeyEvent and SimulateKeyPress below are adapted from |
| 21 // content/public/test/browser_test_utils.cc. |
| 22 // TODO: Move this to browser_test_utils.cc after the support is added for |
| 23 // the UIEvent key |code|. |
| 24 void BuildSimpleWebKeyEvent(WebKit::WebInputEvent::Type type, |
| 25 ui::KeyboardCode key, |
| 26 int nativeKeyCode, |
| 27 bool control, |
| 28 bool shift, |
| 29 bool alt, |
| 30 bool command, |
| 31 content::NativeWebKeyboardEvent* event) { |
| 32 event->nativeKeyCode = nativeKeyCode; |
| 33 event->windowsKeyCode = key; |
| 34 event->setKeyIdentifierFromWindowsKeyCode(); |
| 35 event->type = type; |
| 36 event->modifiers = 0; |
| 37 event->isSystemKey = false; |
| 38 event->timeStampSeconds = base::Time::Now().ToDoubleT(); |
| 39 event->skip_in_browser = true; |
| 40 |
| 41 if (type == WebKit::WebInputEvent::Char || |
| 42 type == WebKit::WebInputEvent::RawKeyDown) { |
| 43 event->text[0] = key; |
| 44 event->unmodifiedText[0] = key; |
| 45 } |
| 46 |
| 47 if (control) |
| 48 event->modifiers |= WebKit::WebInputEvent::ControlKey; |
| 49 |
| 50 if (shift) |
| 51 event->modifiers |= WebKit::WebInputEvent::ShiftKey; |
| 52 |
| 53 if (alt) |
| 54 event->modifiers |= WebKit::WebInputEvent::AltKey; |
| 55 |
| 56 if (command) |
| 57 event->modifiers |= WebKit::WebInputEvent::MetaKey; |
| 58 } |
| 59 |
| 60 void SimulateKeyPress(content::WebContents* web_contents, |
| 61 ui::KeyboardCode key, |
| 62 int nativeKeyCode, |
| 63 bool control, |
| 64 bool shift, |
| 65 bool alt, |
| 66 bool command) { |
| 67 content::NativeWebKeyboardEvent event_down; |
| 68 BuildSimpleWebKeyEvent( |
| 69 WebKit::WebInputEvent::RawKeyDown, |
| 70 key, nativeKeyCode, |
| 71 control, |
| 72 shift, |
| 73 alt, |
| 74 command, |
| 75 &event_down); |
| 76 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_down); |
| 77 |
| 78 content::NativeWebKeyboardEvent char_event; |
| 79 BuildSimpleWebKeyEvent( |
| 80 WebKit::WebInputEvent::Char, |
| 81 key, nativeKeyCode, |
| 82 control, |
| 83 shift, |
| 84 alt, |
| 85 command, |
| 86 &char_event); |
| 87 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(char_event); |
| 88 |
| 89 content::NativeWebKeyboardEvent event_up; |
| 90 BuildSimpleWebKeyEvent( |
| 91 WebKit::WebInputEvent::KeyUp, |
| 92 key, |
| 93 nativeKeyCode, |
| 94 control, |
| 95 shift, |
| 96 alt, |
| 97 command, |
| 98 &event_up); |
| 99 web_contents->GetRenderViewHost()->ForwardKeyboardEvent(event_up); |
| 100 } |
| 101 |
| 20 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() {} | 102 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() {} |
| 21 | 103 |
| 22 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} | 104 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} |
| 23 | 105 |
| 24 void RemoteDesktopBrowserTest::SetUp() { | 106 void RemoteDesktopBrowserTest::SetUp() { |
| 25 ParseCommandLine(); | 107 ParseCommandLine(); |
| 26 ExtensionBrowserTest::SetUp(); | 108 ExtensionBrowserTest::SetUp(); |
| 27 } | 109 } |
| 28 | 110 |
| 29 // Change behavior of the default host resolver to avoid DNS lookup errors, | 111 // Change behavior of the default host resolver to avoid DNS lookup errors, |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // The Me2Me "Get Start" button should be visible. | 275 // The Me2Me "Get Start" button should be visible. |
| 194 ASSERT_TRUE(HtmlElementVisible("get-started-me2me")); | 276 ASSERT_TRUE(HtmlElementVisible("get-started-me2me")); |
| 195 | 277 |
| 196 // Starting Me2Me. | 278 // Starting Me2Me. |
| 197 ExecuteScript("remoting.showMe2MeUiAndSave();"); | 279 ExecuteScript("remoting.showMe2MeUiAndSave();"); |
| 198 | 280 |
| 199 EXPECT_TRUE(HtmlElementVisible("me2me-content")); | 281 EXPECT_TRUE(HtmlElementVisible("me2me-content")); |
| 200 EXPECT_FALSE(HtmlElementVisible("me2me-first-run")); | 282 EXPECT_FALSE(HtmlElementVisible("me2me-first-run")); |
| 201 } | 283 } |
| 202 | 284 |
| 203 void RemoteDesktopBrowserTest::SimulateKeyPressWithCode( | 285 void RemoteDesktopBrowserTest::SimulateKeyPress( |
| 204 ui::KeyboardCode keyCode, | 286 ui::KeyboardCode key, |
| 205 const char* code) { | 287 int nativeKeyCode) { |
| 206 SimulateKeyPressWithCode(keyCode, code, false, false, false, false); | 288 SimulateKeyPress(key, nativeKeyCode, false, false, false, false); |
| 207 } | 289 } |
| 208 | 290 |
| 209 void RemoteDesktopBrowserTest::SimulateKeyPressWithCode( | 291 void RemoteDesktopBrowserTest::SimulateKeyPress( |
| 210 ui::KeyboardCode keyCode, | 292 ui::KeyboardCode key, |
| 211 const char* code, | 293 int nativeKeyCode, |
| 212 bool control, | 294 bool control, |
| 213 bool shift, | 295 bool shift, |
| 214 bool alt, | 296 bool alt, |
| 215 bool command) { | 297 bool command) { |
| 216 content::SimulateKeyPressWithCode( | 298 // TODO: Switch to content::SimulateKeyPress when an overload of it is |
| 299 // added to take the UIEvent key |code| string. |
| 300 remoting::SimulateKeyPress( |
| 217 browser()->tab_strip_model()->GetActiveWebContents(), | 301 browser()->tab_strip_model()->GetActiveWebContents(), |
| 218 keyCode, | 302 key, |
| 219 code, | 303 nativeKeyCode, |
| 220 control, | 304 control, |
| 221 shift, | 305 shift, |
| 222 alt, | 306 alt, |
| 223 command); | 307 command); |
| 224 } | 308 } |
| 225 | 309 |
| 226 void RemoteDesktopBrowserTest::Install() { | 310 void RemoteDesktopBrowserTest::Install() { |
| 227 // TODO: add support for installing unpacked extension (the v2 app needs it). | 311 // TODO: add support for installing unpacked extension (the v2 app needs it). |
| 228 if (!NoInstall()) { | 312 if (!NoInstall()) { |
| 229 VerifyChromotingLoaded(false); | 313 VerifyChromotingLoaded(false); |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 // Wait until the client has connected to the server. | 526 // Wait until the client has connected to the server. |
| 443 // This can take a while. | 527 // This can take a while. |
| 444 // TODO: Instead of polling, can we register a callback to | 528 // TODO: Instead of polling, can we register a callback to |
| 445 // remoting.clientSession.onStageChange_? | 529 // remoting.clientSession.onStageChange_? |
| 446 while (ExecuteScriptAndExtractBool( | 530 while (ExecuteScriptAndExtractBool( |
| 447 "remoting.clientSession == null")) { | 531 "remoting.clientSession == null")) { |
| 448 } | 532 } |
| 449 } | 533 } |
| 450 | 534 |
| 451 } // namespace remoting | 535 } // namespace remoting |
| OLD | NEW |