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

Side by Side Diff: chrome/test/pyautolib/pyautolib.cc

Issue 6312154: Remove wstring from RVH's run Javascript command.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/scoped_ptr.h" 5 #include "base/scoped_ptr.h"
6 #include "base/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/test/automation/extension_proxy.h" 9 #include "chrome/test/automation/extension_proxy.h"
10 #include "chrome/test/automation/tab_proxy.h" 10 #include "chrome/test/automation/tab_proxy.h"
11 #include "chrome/test/pyautolib/pyautolib.h" 11 #include "chrome/test/pyautolib/pyautolib.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 13
14 static int64 StringToId(const std::wstring& str) { 14 static int64 StringToId(const string16& str) {
15 int64 id; 15 int64 id;
16 base::StringToInt64(WideToUTF8(str), &id); 16 base::StringToInt64(str, &id);
17 return id; 17 return id;
18 } 18 }
19 19
20 // PyUITestSuiteBase 20 // PyUITestSuiteBase
21 PyUITestSuiteBase::PyUITestSuiteBase(int argc, char** argv) 21 PyUITestSuiteBase::PyUITestSuiteBase(int argc, char** argv)
22 : UITestSuite(argc, argv) { 22 : UITestSuite(argc, argv) {
23 } 23 }
24 24
25 PyUITestSuiteBase::~PyUITestSuiteBase() { 25 PyUITestSuiteBase::~PyUITestSuiteBase() {
26 pool_.Recycle(); 26 pool_.Recycle();
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 automation()->GetBrowserWindow(0); // Window doesn't matter. 234 automation()->GetBrowserWindow(0); // Window doesn't matter.
235 EXPECT_TRUE(browser_proxy.get()); 235 EXPECT_TRUE(browser_proxy.get());
236 if (!browser_proxy.get()) 236 if (!browser_proxy.get())
237 return false; 237 return false;
238 238
239 std::string s; 239 std::string s;
240 EXPECT_TRUE(browser_proxy->GetBookmarksAsJSON(&s)); 240 EXPECT_TRUE(browser_proxy->GetBookmarksAsJSON(&s));
241 return s; 241 return s;
242 } 242 }
243 243
244 bool PyUITestBase::AddBookmarkGroup(std::wstring& parent_id, int index, 244 bool PyUITestBase::AddBookmarkGroup(const string16& parent_id, int index,
245 std::wstring& title) { 245 const string16& title) {
246 scoped_refptr<BrowserProxy> browser_proxy = 246 scoped_refptr<BrowserProxy> browser_proxy =
247 automation()->GetBrowserWindow(0); // Window doesn't matter. 247 automation()->GetBrowserWindow(0); // Window doesn't matter.
248 EXPECT_TRUE(browser_proxy.get()); 248 EXPECT_TRUE(browser_proxy.get());
249 if (!browser_proxy.get()) 249 if (!browser_proxy.get())
250 return false; 250 return false;
251 251
252 return browser_proxy->AddBookmarkGroup(StringToId(parent_id), index, title); 252 return browser_proxy->AddBookmarkGroup(StringToId(parent_id),
253 index,
254 title);
253 } 255 }
254 256
255 bool PyUITestBase::AddBookmarkURL(std::wstring& parent_id, int index, 257 bool PyUITestBase::AddBookmarkURL(const string16& parent_id, int index,
256 std::wstring& title, std::wstring& url) { 258 const string16& title,
259 const string16& url) {
257 scoped_refptr<BrowserProxy> browser_proxy = 260 scoped_refptr<BrowserProxy> browser_proxy =
258 automation()->GetBrowserWindow(0); // Window doesn't matter. 261 automation()->GetBrowserWindow(0); // Window doesn't matter.
259 EXPECT_TRUE(browser_proxy.get()); 262 EXPECT_TRUE(browser_proxy.get());
260 if (!browser_proxy.get()) 263 if (!browser_proxy.get())
261 return false; 264 return false;
262 265
263 return browser_proxy->AddBookmarkURL(StringToId(parent_id), 266 return browser_proxy->AddBookmarkURL(StringToId(parent_id),
264 index, title, 267 index,
265 GURL(WideToUTF8(url))); 268 title,
269 GURL(UTF16ToUTF8(url)));
266 } 270 }
267 271
268 bool PyUITestBase::ReparentBookmark( 272 bool PyUITestBase::ReparentBookmark(
269 std::wstring& id, std::wstring& new_parent_id, int index) { 273 const string16& id, const string16& new_parent_id, int index) {
270 scoped_refptr<BrowserProxy> browser_proxy = 274 scoped_refptr<BrowserProxy> browser_proxy =
271 automation()->GetBrowserWindow(0); // Window doesn't matter. 275 automation()->GetBrowserWindow(0); // Window doesn't matter.
272 EXPECT_TRUE(browser_proxy.get()); 276 EXPECT_TRUE(browser_proxy.get());
273 if (!browser_proxy.get()) 277 if (!browser_proxy.get())
274 return false; 278 return false;
275 279
276 return browser_proxy->ReparentBookmark(StringToId(id), 280 return browser_proxy->ReparentBookmark(StringToId(id),
277 StringToId(new_parent_id), 281 StringToId(new_parent_id),
278 index); 282 index);
279 } 283 }
280 284
281 bool PyUITestBase::SetBookmarkTitle(std::wstring& id, std::wstring& title) { 285 bool PyUITestBase::SetBookmarkTitle(const string16& id, const string16& title) {
282 scoped_refptr<BrowserProxy> browser_proxy = 286 scoped_refptr<BrowserProxy> browser_proxy =
283 automation()->GetBrowserWindow(0); // Window doesn't matter. 287 automation()->GetBrowserWindow(0); // Window doesn't matter.
284 EXPECT_TRUE(browser_proxy.get()); 288 EXPECT_TRUE(browser_proxy.get());
285 if (!browser_proxy.get()) 289 if (!browser_proxy.get())
286 return false; 290 return false;
287 291
288 return browser_proxy->SetBookmarkTitle(StringToId(id), title); 292 return browser_proxy->SetBookmarkTitle(StringToId(id), title);
289 } 293 }
290 294
291 bool PyUITestBase::SetBookmarkURL(std::wstring& id, std::wstring& url) { 295 bool PyUITestBase::SetBookmarkURL(const string16& id, const string16& url) {
292 scoped_refptr<BrowserProxy> browser_proxy = 296 scoped_refptr<BrowserProxy> browser_proxy =
293 automation()->GetBrowserWindow(0); // Window doesn't matter. 297 automation()->GetBrowserWindow(0); // Window doesn't matter.
294 EXPECT_TRUE(browser_proxy.get()); 298 EXPECT_TRUE(browser_proxy.get());
295 if (!browser_proxy.get()) 299 if (!browser_proxy.get())
296 return false; 300 return false;
297 301
298 return browser_proxy->SetBookmarkURL(StringToId(id), GURL(WideToUTF8(url))); 302 return browser_proxy->SetBookmarkURL(StringToId(id), GURL(UTF16ToUTF8(url)));
299 } 303 }
300 304
301 bool PyUITestBase::RemoveBookmark(std::wstring& id) { 305 bool PyUITestBase::RemoveBookmark(const string16& id) {
302 scoped_refptr<BrowserProxy> browser_proxy = 306 scoped_refptr<BrowserProxy> browser_proxy =
303 automation()->GetBrowserWindow(0); // Window doesn't matter. 307 automation()->GetBrowserWindow(0); // Window doesn't matter.
304 EXPECT_TRUE(browser_proxy.get()); 308 EXPECT_TRUE(browser_proxy.get());
305 if (!browser_proxy.get()) 309 if (!browser_proxy.get())
306 return false; 310 return false;
307 311
308 return browser_proxy->RemoveBookmark(StringToId(id)); 312 return browser_proxy->RemoveBookmark(StringToId(id));
309 } 313 }
310 314
311 scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) { 315 scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) {
(...skipping 12 matching lines...) Expand all
324 return response; 328 return response;
325 } 329 }
326 330
327 std::wstring PyUITestBase::ExecuteJavascript(const std::wstring& script, 331 std::wstring PyUITestBase::ExecuteJavascript(const std::wstring& script,
328 int window_index, 332 int window_index,
329 int tab_index, 333 int tab_index,
330 const std::wstring& frame_xpath) { 334 const std::wstring& frame_xpath) {
331 scoped_refptr<BrowserProxy> browser_proxy = 335 scoped_refptr<BrowserProxy> browser_proxy =
332 automation()->GetBrowserWindow(window_index); 336 automation()->GetBrowserWindow(window_index);
333 EXPECT_TRUE(browser_proxy.get()); 337 EXPECT_TRUE(browser_proxy.get());
334 std::wstring response;
335 if (!browser_proxy.get()) 338 if (!browser_proxy.get())
336 return response; 339 return std::wstring();
337 scoped_refptr<TabProxy> tab_proxy = 340 scoped_refptr<TabProxy> tab_proxy =
338 browser_proxy->GetTab(tab_index); 341 browser_proxy->GetTab(tab_index);
339 EXPECT_TRUE(tab_proxy.get()); 342 EXPECT_TRUE(tab_proxy.get());
340 if (!tab_proxy.get()) 343 if (!tab_proxy.get())
341 return response; 344 return std::wstring();
342 345
343 EXPECT_TRUE(tab_proxy->ExecuteAndExtractString(frame_xpath, script, 346 string16 response;
347 EXPECT_TRUE(tab_proxy->ExecuteAndExtractString(WideToUTF16Hack(frame_xpath),
348 WideToUTF16Hack(script),
344 &response)); 349 &response));
345 return response; 350 return UTF16ToWideHack(response);
346 } 351 }
347 352
348 std::wstring PyUITestBase::GetDOMValue(const std::wstring& expr, 353 std::wstring PyUITestBase::GetDOMValue(const std::wstring& expr,
349 int window_index, 354 int window_index,
350 int tab_index, 355 int tab_index,
351 const std::wstring& frame_xpath) { 356 const std::wstring& frame_xpath) {
352 std::wstring script = std::wstring(L"window.domAutomationController.send(") + 357 std::wstring script = std::wstring(L"window.domAutomationController.send(") +
353 expr + std::wstring(L")"); 358 expr + std::wstring(L")");
354 return ExecuteJavascript(script, window_index, tab_index, frame_xpath); 359 return ExecuteJavascript(script, window_index, tab_index, frame_xpath);
355 } 360 }
(...skipping 26 matching lines...) Expand all
382 // TODO(phadjan.jr): figure out a way to unambiguously report error. 387 // TODO(phadjan.jr): figure out a way to unambiguously report error.
383 if (!browser_proxy.get()) 388 if (!browser_proxy.get())
384 return cookie_val; 389 return cookie_val;
385 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index); 390 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index);
386 EXPECT_TRUE(tab_proxy.get()); 391 EXPECT_TRUE(tab_proxy.get());
387 if (!tab_proxy.get()) 392 if (!tab_proxy.get())
388 return cookie_val; 393 return cookie_val;
389 EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val)); 394 EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val));
390 return cookie_val; 395 return cookie_val;
391 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698