| 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/test_launcher_utils.h" | 13 #include "chrome/test/test_launcher_utils.h" |
| 12 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 13 | 15 |
| 14 namespace webdriver { | 16 namespace webdriver { |
| 15 | 17 |
| 16 void Automation::Init(bool* success) { | 18 void Automation::Init(bool* success) { |
| 17 *success = false; | 19 *success = false; |
| 18 | 20 |
| 19 // Create a temp directory for the new profile. | 21 // Create a temp directory for the new profile. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 bool* success) { | 54 bool* success) { |
| 53 std::wstring wide_xpath = UTF8ToWide(frame_xpath); | 55 std::wstring wide_xpath = UTF8ToWide(frame_xpath); |
| 54 std::wstring wide_script = UTF8ToWide(script); | 56 std::wstring wide_script = UTF8ToWide(script); |
| 55 std::wstring wide_result; | 57 std::wstring wide_result; |
| 56 *success = tab_->ExecuteAndExtractString( | 58 *success = tab_->ExecuteAndExtractString( |
| 57 wide_xpath, wide_script, &wide_result); | 59 wide_xpath, wide_script, &wide_result); |
| 58 if (*success) | 60 if (*success) |
| 59 *result = WideToUTF8(wide_result); | 61 *result = WideToUTF8(wide_result); |
| 60 } | 62 } |
| 61 | 63 |
| 64 void Automation::SendWebKeyEvent(const WebKeyEvent& key_event, |
| 65 bool* success) { |
| 66 scoped_ptr<DictionaryValue> dict(new DictionaryValue); |
| 67 dict->SetString("command", "SendKeyEventToActiveTab"); |
| 68 dict->SetInteger("type", key_event.type); |
| 69 dict->SetInteger("nativeKeyCode", key_event.key_code); |
| 70 dict->SetInteger("windowsKeyCode", key_event.key_code); |
| 71 dict->SetString("unmodifiedText", key_event.unmodified_text); |
| 72 dict->SetString("text", key_event.modified_text); |
| 73 dict->SetInteger("modifiers", key_event.modifiers); |
| 74 dict->SetBoolean("isSystemKey", false); |
| 75 std::string request; |
| 76 base::JSONWriter::Write(dict.get(), false, &request); |
| 77 std::string reply; |
| 78 *success = browser_->SendJSONRequest(request, &reply); |
| 79 if (!*success) { |
| 80 LOG(ERROR) << "Could not send web key event. Reply: " << reply; |
| 81 } |
| 82 } |
| 83 |
| 62 void Automation::NavigateToURL(const std::string& url, | 84 void Automation::NavigateToURL(const std::string& url, |
| 63 bool* success) { | 85 bool* success) { |
| 64 *success = tab_->NavigateToURL(GURL(url)); | 86 *success = tab_->NavigateToURL(GURL(url)); |
| 65 } | 87 } |
| 66 | 88 |
| 67 void Automation::GoForward(bool* success) { | 89 void Automation::GoForward(bool* success) { |
| 68 *success = tab_->GoForward(); | 90 *success = tab_->GoForward(); |
| 69 } | 91 } |
| 70 | 92 |
| 71 void Automation::GoBack(bool* success) { | 93 void Automation::GoBack(bool* success) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 86 | 108 |
| 87 void Automation::GetTabTitle(std::string* tab_title, | 109 void Automation::GetTabTitle(std::string* tab_title, |
| 88 bool* success) { | 110 bool* success) { |
| 89 std::wstring wide_title; | 111 std::wstring wide_title; |
| 90 *success = tab_->GetTabTitle(&wide_title); | 112 *success = tab_->GetTabTitle(&wide_title); |
| 91 if (*success) | 113 if (*success) |
| 92 *tab_title = WideToUTF8(wide_title); | 114 *tab_title = WideToUTF8(wide_title); |
| 93 } | 115 } |
| 94 | 116 |
| 95 } // namespace webdriver | 117 } // namespace webdriver |
| OLD | NEW |