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

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

Issue 10804038: Convert cookie and download automation commands to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 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 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/base_paths.h" 5 #include "base/base_paths.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 // However, we *do* want the --homepage switch. 99 // However, we *do* want the --homepage switch.
100 std::swap(homepage_original, homepage_); 100 std::swap(homepage_original, homepage_);
101 launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_); 101 launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_);
102 } 102 }
103 103
104 bool PyUITestBase::ActivateTab(int tab_index, int window_index) { 104 bool PyUITestBase::ActivateTab(int tab_index, int window_index) {
105 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index); 105 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
106 return browser_proxy->BringToFront() && browser_proxy->ActivateTab(tab_index); 106 return browser_proxy->BringToFront() && browser_proxy->ActivateTab(tab_index);
107 } 107 }
108 108
109 void PyUITestBase::SetDownloadShelfVisible(bool is_visible, int window_index) {
110 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
111 ASSERT_TRUE(browser_proxy.get());
112 EXPECT_TRUE(browser_proxy->SetShelfVisible(is_visible));
113 }
114
115 bool PyUITestBase::IsDownloadShelfVisible(int window_index) {
116 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
117 EXPECT_TRUE(browser_proxy.get());
118 if (!browser_proxy.get())
119 return false;
120 bool visible = false;
121 EXPECT_TRUE(browser_proxy->IsShelfVisible(&visible));
122 return visible;
123 }
124
125 int PyUITestBase::GetTabCount(int window_index) { 109 int PyUITestBase::GetTabCount(int window_index) {
126 return UITestBase::GetTabCount(window_index); 110 return UITestBase::GetTabCount(window_index);
127 } 111 }
128 112
129 GURL PyUITestBase::GetActiveTabURL(int window_index) { 113 GURL PyUITestBase::GetActiveTabURL(int window_index) {
130 return UITestBase::GetActiveTabURL(window_index); 114 return UITestBase::GetActiveTabURL(window_index);
131 } 115 }
132 116
133 void PyUITestBase::OpenFindInPage(int window_index) { 117 void PyUITestBase::OpenFindInPage(int window_index) {
134 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index); 118 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
135 ASSERT_TRUE(browser_proxy.get()); 119 ASSERT_TRUE(browser_proxy.get());
136 EXPECT_TRUE(browser_proxy->OpenFindInPage()); 120 EXPECT_TRUE(browser_proxy->OpenFindInPage());
137 } 121 }
138 122
139 bool PyUITestBase::IsFindInPageVisible(int window_index) { 123 bool PyUITestBase::IsFindInPageVisible(int window_index) {
140 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index); 124 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
141 EXPECT_TRUE(browser_proxy.get()); 125 EXPECT_TRUE(browser_proxy.get());
142 if (!browser_proxy.get()) 126 if (!browser_proxy.get())
143 return false; 127 return false;
144 bool is_visible; 128 bool is_visible;
145 EXPECT_TRUE(browser_proxy->IsFindWindowFullyVisible(&is_visible)); 129 EXPECT_TRUE(browser_proxy->IsFindWindowFullyVisible(&is_visible));
146 return is_visible; 130 return is_visible;
147 } 131 }
148 132
149 FilePath PyUITestBase::GetDownloadDirectory() {
150 FilePath download_dir;
151 scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
152 EXPECT_TRUE(tab_proxy.get());
153 if (!tab_proxy.get())
154 return download_dir;
155 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_dir));
156 return download_dir;
157 }
158
159 bool PyUITestBase::OpenNewBrowserWindow(bool show) { 133 bool PyUITestBase::OpenNewBrowserWindow(bool show) {
160 return automation()->OpenNewBrowserWindow(Browser::TYPE_TABBED, show); 134 return automation()->OpenNewBrowserWindow(Browser::TYPE_TABBED, show);
161 } 135 }
162 136
163 bool PyUITestBase::CloseBrowserWindow(int window_index) { 137 bool PyUITestBase::CloseBrowserWindow(int window_index) {
164 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index); 138 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
165 if (!browser_proxy.get()) 139 if (!browser_proxy.get())
166 return false; 140 return false;
167 bool app_closed; 141 bool app_closed;
168 return CloseBrowser(browser_proxy.get(), &app_closed); 142 return CloseBrowser(browser_proxy.get(), &app_closed);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 request, response); 338 request, response);
365 } else { 339 } else {
366 // TODO(craigdh): Determine specific cause. 340 // TODO(craigdh): Determine specific cause.
367 ErrorResponse("Chrome failed to respond", request, response); 341 ErrorResponse("Chrome failed to respond", request, response);
368 } 342 }
369 } 343 }
370 344
371 bool PyUITestBase::ResetToDefaultTheme() { 345 bool PyUITestBase::ResetToDefaultTheme() {
372 return automation()->ResetToDefaultTheme(); 346 return automation()->ResetToDefaultTheme();
373 } 347 }
374
375 bool PyUITestBase::SetCookie(const GURL& cookie_url,
376 const std::string& value,
377 int window_index,
378 int tab_index) {
379 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
380 EXPECT_TRUE(browser_proxy.get());
381 if (!browser_proxy.get())
382 return false;
383 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index);
384 EXPECT_TRUE(tab_proxy.get());
385 if (!tab_proxy.get())
386 return false;
387 return tab_proxy->SetCookie(cookie_url, value);
388 }
389
390 std::string PyUITestBase::GetCookie(const GURL& cookie_url,
391 int window_index,
392 int tab_index) {
393 std::string cookie_val;
394 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
395 EXPECT_TRUE(browser_proxy.get());
396 // TODO(phadjan.jr): figure out a way to unambiguously report error.
397 if (!browser_proxy.get())
398 return cookie_val;
399 scoped_refptr<TabProxy> tab_proxy = browser_proxy->GetTab(tab_index);
400 EXPECT_TRUE(tab_proxy.get());
401 if (!tab_proxy.get())
402 return cookie_val;
403 EXPECT_TRUE(tab_proxy->GetCookies(cookie_url, &cookie_val));
404 return cookie_val;
405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698