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

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

Issue 3012039: Add ExecuteJavascript() method to PyUITestBase (Closed)
Patch Set: merge to head Created 10 years, 4 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
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_util.h" 6 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/test/automation/extension_proxy.h" 8 #include "chrome/test/automation/extension_proxy.h"
9 #include "chrome/test/automation/tab_proxy.h" 9 #include "chrome/test/automation/tab_proxy.h"
10 #include "chrome/test/pyautolib/pyautolib.h" 10 #include "chrome/test/pyautolib/pyautolib.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 scoped_refptr<BrowserProxy> browser_proxy = 288 scoped_refptr<BrowserProxy> browser_proxy =
289 automation()->GetBrowserWindow(window_index); 289 automation()->GetBrowserWindow(window_index);
290 EXPECT_TRUE(browser_proxy.get()); 290 EXPECT_TRUE(browser_proxy.get());
291 std::string response; 291 std::string response;
292 if (browser_proxy.get()) { 292 if (browser_proxy.get()) {
293 EXPECT_TRUE(browser_proxy->SendJSONRequest(request, &response)); 293 EXPECT_TRUE(browser_proxy->SendJSONRequest(request, &response));
294 } 294 }
295 return response; 295 return response;
296 } 296 }
297 297
298 std::wstring PyUITestBase::ExecuteJavascript(const std::wstring& script,
299 int window_index,
300 int tab_index,
301 const std::wstring& frame_xpath) {
302 scoped_refptr<BrowserProxy> browser_proxy =
303 automation()->GetBrowserWindow(window_index);
304 EXPECT_TRUE(browser_proxy.get());
305 std::wstring response;
306 if (!browser_proxy.get())
307 return response;
308 scoped_refptr<TabProxy> tab_proxy =
309 browser_proxy->GetTab(tab_index);
310 EXPECT_TRUE(tab_proxy.get());
311 if (!tab_proxy.get())
312 return response;
313
314 EXPECT_TRUE(tab_proxy->ExecuteAndExtractString(frame_xpath, script,
315 &response));
316 return response;
317 }
318
319 std::wstring PyUITestBase::GetDOMValue(const std::wstring& expr,
320 int window_index,
321 int tab_index,
322 const std::wstring& frame_xpath) {
323 std::wstring script = std::wstring(L"window.domAutomationController.send(") +
324 expr + std::wstring(L")");
325 return ExecuteJavascript(script, window_index, tab_index, frame_xpath);
326 }
327
298 bool PyUITestBase::ResetToDefaultTheme() { 328 bool PyUITestBase::ResetToDefaultTheme() {
299 return automation()->ResetToDefaultTheme(); 329 return automation()->ResetToDefaultTheme();
300 } 330 }
301 331
302 bool PyUITestBase::SetCookie(const GURL& cookie_url, 332 bool PyUITestBase::SetCookie(const GURL& cookie_url,
303 const std::string& value, 333 const std::string& value,
304 int window_index, 334 int window_index,
305 int tab_index) { 335 int tab_index) {
306 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index); 336 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
307 EXPECT_TRUE(browser_proxy.get()); 337 EXPECT_TRUE(browser_proxy.get());
(...skipping 15 matching lines...) Expand all
323 // TODO(phadjan.jr): figure out a way to unambiguously report error. 353 // TODO(phadjan.jr): figure out a way to unambiguously report error.
324 if (!browser_proxy.get()) 354 if (!browser_proxy.get())
325 return cookie_val; 355 return cookie_val;
326 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index); 356 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index);
327 EXPECT_TRUE(tab_proxy.get()); 357 EXPECT_TRUE(tab_proxy.get());
328 if (!tab_proxy.get()) 358 if (!tab_proxy.get())
329 return cookie_val; 359 return cookie_val;
330 EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val)); 360 EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val));
331 return cookie_val; 361 return cookie_val;
332 } 362 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698