| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/test/webdriver/automation.h" | 5 #include "chrome/test/webdriver/automation.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_writer.h" |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" |
| 10 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/test/automation/browser_proxy.h" | 13 #include "chrome/test/automation/browser_proxy.h" |
| 12 #include "chrome/test/automation/tab_proxy.h" | 14 #include "chrome/test/automation/tab_proxy.h" |
| 13 #include "chrome/test/test_launcher_utils.h" | 15 #include "chrome/test/test_launcher_utils.h" |
| 14 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 15 | 17 |
| 16 namespace webdriver { | 18 namespace webdriver { |
| 17 | 19 |
| 18 Automation::Automation() {} | 20 Automation::Automation() {} |
| 19 | 21 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 bool* success) { | 60 bool* success) { |
| 59 std::wstring wide_xpath = UTF8ToWide(frame_xpath); | 61 std::wstring wide_xpath = UTF8ToWide(frame_xpath); |
| 60 std::wstring wide_script = UTF8ToWide(script); | 62 std::wstring wide_script = UTF8ToWide(script); |
| 61 std::wstring wide_result; | 63 std::wstring wide_result; |
| 62 *success = tab_->ExecuteAndExtractString( | 64 *success = tab_->ExecuteAndExtractString( |
| 63 wide_xpath, wide_script, &wide_result); | 65 wide_xpath, wide_script, &wide_result); |
| 64 if (*success) | 66 if (*success) |
| 65 *result = WideToUTF8(wide_result); | 67 *result = WideToUTF8(wide_result); |
| 66 } | 68 } |
| 67 | 69 |
| 70 void Automation::SendWebKeyEvent(const WebKeyEvent& key_event, |
| 71 bool* success) { |
| 72 scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
| 73 dict->SetString("command", "SendKeyEventToActiveTab"); |
| 74 dict->SetInteger("type", key_event.type); |
| 75 dict->SetInteger("nativeKeyCode", key_event.key_code); |
| 76 dict->SetInteger("windowsKeyCode", key_event.key_code); |
| 77 dict->SetString("unmodifiedText", key_event.unmodified_text); |
| 78 dict->SetString("text", key_event.modified_text); |
| 79 dict->SetInteger("modifiers", key_event.modifiers); |
| 80 dict->SetBoolean("isSystemKey", false); |
| 81 std::string request; |
| 82 base::JSONWriter::Write(dict.get(), false, &request); |
| 83 std::string reply; |
| 84 *success = browser_->SendJSONRequest(request, &reply); |
| 85 if (!*success) { |
| 86 LOG(ERROR) << "Could not send web key event. Reply: " << reply; |
| 87 } |
| 88 } |
| 89 |
| 68 void Automation::NavigateToURL(const std::string& url, | 90 void Automation::NavigateToURL(const std::string& url, |
| 69 bool* success) { | 91 bool* success) { |
| 70 *success = tab_->NavigateToURL(GURL(url)); | 92 *success = tab_->NavigateToURL(GURL(url)); |
| 71 } | 93 } |
| 72 | 94 |
| 73 void Automation::GoForward(bool* success) { | 95 void Automation::GoForward(bool* success) { |
| 74 *success = tab_->GoForward(); | 96 *success = tab_->GoForward(); |
| 75 } | 97 } |
| 76 | 98 |
| 77 void Automation::GoBack(bool* success) { | 99 void Automation::GoBack(bool* success) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 92 | 114 |
| 93 void Automation::GetTabTitle(std::string* tab_title, | 115 void Automation::GetTabTitle(std::string* tab_title, |
| 94 bool* success) { | 116 bool* success) { |
| 95 std::wstring wide_title; | 117 std::wstring wide_title; |
| 96 *success = tab_->GetTabTitle(&wide_title); | 118 *success = tab_->GetTabTitle(&wide_title); |
| 97 if (*success) | 119 if (*success) |
| 98 *tab_title = WideToUTF8(wide_title); | 120 *tab_title = WideToUTF8(wide_title); |
| 99 } | 121 } |
| 100 | 122 |
| 101 } // namespace webdriver | 123 } // namespace webdriver |
| OLD | NEW |