OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/test/webdriver/commands/html5_storage_commands.h" | |
6 | |
7 #include "base/values.h" | |
8 #include "chrome/test/webdriver/commands/response.h" | |
9 #include "chrome/test/webdriver/webdriver_error.h" | |
10 #include "chrome/test/webdriver/webdriver_session.h" | |
11 | |
12 namespace webdriver { | |
13 | |
14 LocalStorageCommand::LocalStorageCommand( | |
15 const std::vector<std::string>& path_segments, | |
16 const base::DictionaryValue* const parameters) | |
17 : WebDriverCommand(path_segments, parameters) {} | |
18 | |
19 LocalStorageCommand::~LocalStorageCommand() {} | |
20 | |
21 bool LocalStorageCommand::DoesGet() { | |
22 return true; | |
23 } | |
24 | |
25 bool LocalStorageCommand::DoesPost() { | |
26 return true; | |
27 } | |
28 | |
29 bool LocalStorageCommand::DoesDelete() { | |
30 return true; | |
31 } | |
32 | |
33 void LocalStorageCommand::ExecuteGet(Response* const response) { | |
34 base::ListValue* keys; | |
35 Error* error = session_->GetStorageKeys(kLocalStorageType, &keys); | |
36 if (error) { | |
37 response->SetError(error); | |
38 return; | |
39 } | |
40 response->SetValue(keys); | |
41 } | |
42 | |
43 void LocalStorageCommand::ExecutePost(Response* const response) { | |
44 // "/session/$sessionId/local_storage" | |
45 std::string key; | |
46 std::string value; | |
47 if (!GetStringParameter("key", &key) || | |
48 !GetStringParameter("value", &value)) { | |
49 response->SetError(new Error( | |
50 kBadRequest, "('key', 'value') parameter is missing or invalid")); | |
51 return; | |
52 } | |
53 | |
54 Error* error = session_->SetStorageItem(kLocalStorageType, key, value); | |
55 if (error) | |
56 response->SetError(error); | |
57 } | |
58 | |
59 void LocalStorageCommand::ExecuteDelete(Response* const response) { | |
60 Error* error = session_->ClearStorage(kLocalStorageType); | |
61 if (error) | |
62 response->SetError(error); | |
63 } | |
64 | |
65 LocalStorageKeyCommand::LocalStorageKeyCommand( | |
66 const std::vector<std::string>& path_segments, | |
67 const base::DictionaryValue* const parameters) | |
68 : WebDriverCommand(path_segments, parameters) {} | |
69 | |
70 LocalStorageKeyCommand::~LocalStorageKeyCommand() {} | |
71 | |
72 bool LocalStorageKeyCommand::DoesGet() { | |
73 return true; | |
74 } | |
75 | |
76 bool LocalStorageKeyCommand::DoesDelete() { | |
77 return true; | |
78 } | |
79 | |
80 void LocalStorageKeyCommand::ExecuteGet(Response* const response) { | |
81 // "/session/$sessionId/local_storage/key/$key" | |
82 std::string key = GetPathVariable(5); | |
83 std::string value; | |
84 Error* error = session_->GetStorageItem(kLocalStorageType, key, &value); | |
85 if (error) { | |
86 response->SetError(error); | |
87 return; | |
88 } | |
89 response->SetValue(new base::StringValue(value)); | |
90 } | |
91 | |
92 void LocalStorageKeyCommand::ExecuteDelete(Response* const response) { | |
93 // "/session/$sessionId/local_storage/key/$key" | |
94 std::string key = GetPathVariable(5); | |
95 std::string value; | |
96 Error* error = session_->RemoveStorageItem(kLocalStorageType, key, &value); | |
97 if (error) { | |
98 response->SetError(error); | |
99 return; | |
100 } | |
101 response->SetValue(new base::StringValue(value)); | |
102 } | |
103 | |
104 LocalStorageSizeCommand::LocalStorageSizeCommand( | |
105 const std::vector<std::string>& path_segments, | |
106 const base::DictionaryValue* const parameters) | |
107 : WebDriverCommand(path_segments, parameters) {} | |
108 | |
109 LocalStorageSizeCommand::~LocalStorageSizeCommand() {} | |
110 | |
111 bool LocalStorageSizeCommand::DoesGet() { | |
112 return true; | |
113 } | |
114 | |
115 void LocalStorageSizeCommand::ExecuteGet(Response* const response) { | |
116 int size; | |
117 Error* error = session_->GetStorageSize(kLocalStorageType, &size); | |
118 if (error) { | |
119 response->SetError(error); | |
120 return; | |
121 } | |
122 response->SetValue(new base::FundamentalValue(size)); | |
123 } | |
124 | |
125 SessionStorageCommand::SessionStorageCommand( | |
126 const std::vector<std::string>& path_segments, | |
127 base::DictionaryValue* parameters) | |
128 : WebDriverCommand(path_segments, parameters) {} | |
129 | |
130 SessionStorageCommand::~SessionStorageCommand() {} | |
131 | |
132 bool SessionStorageCommand::DoesGet() { | |
133 return true; | |
134 } | |
135 | |
136 bool SessionStorageCommand::DoesPost() { | |
137 return true; | |
138 } | |
139 | |
140 bool SessionStorageCommand::DoesDelete() { | |
141 return true; | |
142 } | |
143 | |
144 void SessionStorageCommand::ExecuteGet(Response* const response) { | |
145 base::ListValue* keys; | |
146 Error* error = session_->GetStorageKeys(kSessionStorageType, &keys); | |
147 if (error) { | |
148 response->SetError(error); | |
149 return; | |
150 } | |
151 response->SetValue(keys); | |
152 } | |
153 | |
154 void SessionStorageCommand::ExecutePost(Response* const response) { | |
155 // "/session/$sessionId/session_storage" | |
156 std::string key; | |
157 std::string value; | |
158 if (!GetStringParameter("key", &key) || | |
159 !GetStringParameter("value", &value)) { | |
160 response->SetError(new Error( | |
161 kBadRequest, "('key', 'value') parameter is missing or invalid")); | |
162 return; | |
163 } | |
164 | |
165 Error* error = session_->SetStorageItem(kSessionStorageType, key, value); | |
166 if (error) | |
167 response->SetError(error); | |
168 } | |
169 | |
170 void SessionStorageCommand::ExecuteDelete(Response* const response) { | |
171 Error* error = session_->ClearStorage(kSessionStorageType); | |
172 if (error) | |
173 response->SetError(error); | |
174 } | |
175 | |
176 SessionStorageKeyCommand::SessionStorageKeyCommand( | |
177 const std::vector<std::string>& path_segments, | |
178 const base::DictionaryValue* const parameters) | |
179 : WebDriverCommand(path_segments, parameters) {} | |
180 | |
181 SessionStorageKeyCommand::~SessionStorageKeyCommand() {} | |
182 | |
183 bool SessionStorageKeyCommand::DoesGet() { | |
184 return true; | |
185 } | |
186 | |
187 bool SessionStorageKeyCommand::DoesDelete() { | |
188 return true; | |
189 } | |
190 | |
191 void SessionStorageKeyCommand::ExecuteGet(Response* const response) { | |
192 // "/session/$sessionId/session_storage/key/$key" | |
193 std::string key = GetPathVariable(5); | |
194 std::string value; | |
195 Error* error = session_->GetStorageItem(kSessionStorageType, key, &value); | |
196 if (error) { | |
197 response->SetError(error); | |
198 return; | |
199 } | |
200 response->SetValue(new base::StringValue(value)); | |
201 } | |
202 | |
203 void SessionStorageKeyCommand::ExecuteDelete(Response* const response) { | |
204 // "/session/$sessionId/session_storage/key/$key" | |
205 std::string key = GetPathVariable(5); | |
206 std::string value; | |
207 Error* error = session_->RemoveStorageItem(kSessionStorageType, key, &value); | |
208 if (error) { | |
209 response->SetError(error); | |
210 return; | |
211 } | |
212 response->SetValue(new base::StringValue(value)); | |
213 } | |
214 | |
215 SessionStorageSizeCommand::SessionStorageSizeCommand( | |
216 const std::vector<std::string>& path_segments, | |
217 const base::DictionaryValue* const parameters) | |
218 : WebDriverCommand(path_segments, parameters) {} | |
219 | |
220 SessionStorageSizeCommand::~SessionStorageSizeCommand() {} | |
221 | |
222 bool SessionStorageSizeCommand::DoesGet() { | |
223 return true; | |
224 } | |
225 | |
226 void SessionStorageSizeCommand::ExecuteGet(Response* const response) { | |
227 int size; | |
228 Error* error = session_->GetStorageSize(kSessionStorageType, &size); | |
229 if (error) { | |
230 response->SetError(error); | |
231 return; | |
232 } | |
233 response->SetValue(new base::FundamentalValue(size)); | |
234 } | |
235 | |
236 } // namespace webdriver | |
OLD | NEW |