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

Side by Side Diff: chrome/test/webdriver/commands/target_locator_commands.cc

Issue 8806030: Add commands to Chrome WebDriver for installing and manipulating extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years 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) 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/commands/target_locator_commands.h" 5 #include "chrome/test/webdriver/commands/target_locator_commands.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/test/webdriver/commands/response.h" 9 #include "chrome/test/webdriver/commands/response.h"
10 #include "chrome/test/webdriver/webdriver_element_id.h" 10 #include "chrome/test/webdriver/webdriver_element_id.h"
11 #include "chrome/test/webdriver/webdriver_error.h" 11 #include "chrome/test/webdriver/webdriver_error.h"
12 #include "chrome/test/webdriver/webdriver_session.h" 12 #include "chrome/test/webdriver/webdriver_session.h"
13 #include "chrome/test/webdriver/webdriver_util.h"
14
15 using base::Value;
13 16
14 namespace webdriver { 17 namespace webdriver {
15 18
16 WindowHandleCommand::WindowHandleCommand( 19 WindowHandleCommand::WindowHandleCommand(
17 const std::vector<std::string>& path_segments, 20 const std::vector<std::string>& path_segments,
18 DictionaryValue* parameters) 21 DictionaryValue* parameters)
19 : WebDriverCommand(path_segments, parameters) {} 22 : WebDriverCommand(path_segments, parameters) {}
20 23
21 WindowHandleCommand::~WindowHandleCommand() {} 24 WindowHandleCommand::~WindowHandleCommand() {}
22 25
23 bool WindowHandleCommand::DoesGet() { 26 bool WindowHandleCommand::DoesGet() {
24 return true; 27 return true;
25 } 28 }
26 29
27 void WindowHandleCommand::ExecuteGet(Response* const response) { 30 void WindowHandleCommand::ExecuteGet(Response* const response) {
28 response->SetValue(new StringValue( 31 response->SetValue(Value::CreateStringValue(
29 base::IntToString(session_->current_target().window_id))); 32 WebViewIdToString(session_->current_target().view_id)));
30 } 33 }
31 34
32 WindowHandlesCommand::WindowHandlesCommand( 35 WindowHandlesCommand::WindowHandlesCommand(
33 const std::vector<std::string>& path_segments, 36 const std::vector<std::string>& path_segments,
34 DictionaryValue* parameters) 37 DictionaryValue* parameters)
35 : WebDriverCommand(path_segments, parameters) {} 38 : WebDriverCommand(path_segments, parameters) {}
36 39
37 WindowHandlesCommand::~WindowHandlesCommand() {} 40 WindowHandlesCommand::~WindowHandlesCommand() {}
38 41
39 bool WindowHandlesCommand::DoesGet() { 42 bool WindowHandlesCommand::DoesGet() {
40 return true; 43 return true;
41 } 44 }
42 45
43 void WindowHandlesCommand::ExecuteGet(Response* const response) { 46 void WindowHandlesCommand::ExecuteGet(Response* const response) {
44 std::vector<int> window_ids; 47 std::vector<WebViewInfo> views;
45 Error* error = session_->GetWindowIds(&window_ids); 48 Error* error = session_->GetViews(&views);
46 if (error) { 49 if (error) {
47 response->SetError(error); 50 response->SetError(error);
48 return; 51 return;
49 } 52 }
50 ListValue* id_list = new ListValue(); 53 base::ListValue* id_list = new base::ListValue();
51 for (size_t i = 0; i < window_ids.size(); ++i) 54 for (size_t i = 0; i < views.size(); ++i) {
52 id_list->Append(new StringValue(base::IntToString(window_ids[i]))); 55 if (!views[i].view_id.IsTab())
56 continue;
57 id_list->Append(Value::CreateStringValue(
58 WebViewIdToString(views[i].view_id)));
59 }
53 response->SetValue(id_list); 60 response->SetValue(id_list);
54 } 61 }
55 62
56 WindowCommand::WindowCommand( 63 WindowCommand::WindowCommand(
57 const std::vector<std::string>& path_segments, 64 const std::vector<std::string>& path_segments,
58 DictionaryValue* parameters) 65 DictionaryValue* parameters)
59 : WebDriverCommand(path_segments, parameters) {} 66 : WebDriverCommand(path_segments, parameters) {}
60 67
61 WindowCommand::~WindowCommand() {} 68 WindowCommand::~WindowCommand() {}
62 69
63 bool WindowCommand::DoesPost() { 70 bool WindowCommand::DoesPost() {
64 return true; 71 return true;
65 } 72 }
66 73
67 bool WindowCommand::DoesDelete() { 74 bool WindowCommand::DoesDelete() {
68 return true; 75 return true;
69 } 76 }
70 77
71 void WindowCommand::ExecutePost(Response* const response) { 78 void WindowCommand::ExecutePost(Response* const response) {
72 std::string name; 79 std::string name;
73 if (!GetStringParameter("name", &name)) { 80 if (!GetStringParameter("name", &name)) {
74 response->SetError(new Error( 81 response->SetError(new Error(
75 kBadRequest, "Missing or invalid 'name' parameter")); 82 kBadRequest, "Missing or invalid 'name' parameter"));
76 return; 83 return;
77 } 84 }
78 85
79 Error* error = session_->SwitchToWindow(name); 86 Error* error = session_->SwitchToView(name);
80 if (error) 87 if (error)
81 response->SetError(error); 88 response->SetError(error);
82 } 89 }
83 90
84 void WindowCommand::ExecuteDelete(Response* const response) { 91 void WindowCommand::ExecuteDelete(Response* const response) {
85 Error* error = session_->CloseWindow(); 92 Error* error = session_->CloseWindow();
86 if (error) 93 if (error)
87 response->SetError(error); 94 response->SetError(error);
88 } 95 }
89 96
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 Error* error = session_->ExecuteScript( 158 Error* error = session_->ExecuteScript(
152 "return document.activeElement || document.body", &args, &result); 159 "return document.activeElement || document.body", &args, &result);
153 if (error) { 160 if (error) {
154 response->SetError(error); 161 response->SetError(error);
155 return; 162 return;
156 } 163 }
157 response->SetValue(result); 164 response->SetValue(result);
158 } 165 }
159 166
160 } // namespace webdriver 167 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/commands/chrome_commands.cc ('k') | chrome/test/webdriver/test/chromedriver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698