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

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

Issue 10828245: Final set of conversions of automation calls to the JSON interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/pyautolib/pyautolib.h ('k') | chrome/test/pyautolib/pyautolib.i » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/json/json_writer.h" 6 #include "base/json/json_writer.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/common/automation_messages.h" 15 #include "chrome/common/automation_messages.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/automation/automation_proxy.h" 17 #include "chrome/test/automation/automation_proxy.h"
18 #include "chrome/test/automation/tab_proxy.h" 18 #include "chrome/test/automation/tab_proxy.h"
19 #include "chrome/test/pyautolib/pyautolib.h" 19 #include "chrome/test/pyautolib/pyautolib.h"
20 #include "googleurl/src/gurl.h" 20 #include "googleurl/src/gurl.h"
21 21
22 static int64 StringToId(const std::wstring& str) {
23 int64 id;
24 base::StringToInt64(WideToUTF8(str), &id);
25 return id;
26 }
27
28 // PyUITestSuiteBase 22 // PyUITestSuiteBase
29 PyUITestSuiteBase::PyUITestSuiteBase(int argc, char** argv) 23 PyUITestSuiteBase::PyUITestSuiteBase(int argc, char** argv)
30 : UITestSuite(argc, argv) { 24 : UITestSuite(argc, argv) {
31 } 25 }
32 26
33 PyUITestSuiteBase::~PyUITestSuiteBase() { 27 PyUITestSuiteBase::~PyUITestSuiteBase() {
34 #if defined(OS_MACOSX) 28 #if defined(OS_MACOSX)
35 pool_.Recycle(); 29 pool_.Recycle();
36 #endif 30 #endif
37 Shutdown(); 31 Shutdown();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::string homepage_original; 89 std::string homepage_original;
96 std::swap(homepage_original, homepage_); 90 std::swap(homepage_original, homepage_);
97 91
98 UITestBase::SetLaunchSwitches(); 92 UITestBase::SetLaunchSwitches();
99 93
100 // However, we *do* want the --homepage switch. 94 // However, we *do* want the --homepage switch.
101 std::swap(homepage_original, homepage_); 95 std::swap(homepage_original, homepage_);
102 launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_); 96 launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_);
103 } 97 }
104 98
105 bool PyUITestBase::GetBookmarkBarState(bool* visible,
106 bool* detached,
107 int window_index) {
108 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
109 EXPECT_TRUE(browser_proxy.get());
110 if (!browser_proxy.get())
111 return false;
112
113 // We have no use for animating in this context.
114 bool animating;
115 EXPECT_TRUE(browser_proxy->GetBookmarkBarVisibility(visible,
116 &animating,
117 detached));
118 return true;
119 }
120
121 bool PyUITestBase::GetBookmarkBarVisibility() {
122 // We have no use for detached in this context.
123 bool visible, detached;
124 if (!GetBookmarkBarState(&visible, &detached))
125 return false;
126 return visible;
127 }
128
129 bool PyUITestBase::IsBookmarkBarDetached() {
130 // We have no use for visible in this context.
131 bool visible, detached;
132 if (!GetBookmarkBarState(&visible, &detached))
133 return false;
134 return detached;
135 }
136
137 bool PyUITestBase::WaitForBookmarkBarVisibilityChange(bool wait_for_open,
138 int window_index) {
139 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
140 EXPECT_TRUE(browser_proxy.get());
141 if (!browser_proxy.get())
142 return false;
143
144 // This has a 20sec timeout. If that's not enough we have serious problems.
145 bool completed = UITestBase::WaitForBookmarkBarVisibilityChange(
146 browser_proxy.get(),
147 wait_for_open);
148 EXPECT_TRUE(completed);
149 return completed;
150 }
151
152 std::string PyUITestBase::_GetBookmarksAsJSON(int window_index) {
153 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
154 EXPECT_TRUE(browser_proxy.get());
155 if (!browser_proxy.get())
156 return std::string();
157
158 std::string s;
159 EXPECT_TRUE(browser_proxy->GetBookmarksAsJSON(&s));
160 return s;
161 }
162
163 bool PyUITestBase::AddBookmarkGroup(std::wstring& parent_id,
164 int index,
165 std::wstring& title,
166 int window_index) {
167 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
168 EXPECT_TRUE(browser_proxy.get());
169 if (!browser_proxy.get())
170 return false;
171
172 return browser_proxy->AddBookmarkGroup(StringToId(parent_id), index, title);
173 }
174
175 bool PyUITestBase::AddBookmarkURL(std::wstring& parent_id,
176 int index,
177 std::wstring& title,
178 std::wstring& url,
179 int window_index) {
180 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
181 EXPECT_TRUE(browser_proxy.get());
182 if (!browser_proxy.get())
183 return false;
184
185 return browser_proxy->AddBookmarkURL(StringToId(parent_id),
186 index, title,
187 GURL(WideToUTF8(url)));
188 }
189
190 bool PyUITestBase::ReparentBookmark(std::wstring& id,
191 std::wstring& new_parent_id,
192 int index,
193 int window_index) {
194 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
195 EXPECT_TRUE(browser_proxy.get());
196 if (!browser_proxy.get())
197 return false;
198
199 return browser_proxy->ReparentBookmark(StringToId(id),
200 StringToId(new_parent_id),
201 index);
202 }
203
204 bool PyUITestBase::SetBookmarkTitle(std::wstring& id,
205 std::wstring& title,
206 int window_index) {
207 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
208 EXPECT_TRUE(browser_proxy.get());
209 if (!browser_proxy.get())
210 return false;
211
212 return browser_proxy->SetBookmarkTitle(StringToId(id), title);
213 }
214
215 bool PyUITestBase::SetBookmarkURL(std::wstring& id,
216 std::wstring& url,
217 int window_index) {
218 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
219 EXPECT_TRUE(browser_proxy.get());
220 if (!browser_proxy.get())
221 return false;
222
223 return browser_proxy->SetBookmarkURL(StringToId(id), GURL(WideToUTF8(url)));
224 }
225
226 bool PyUITestBase::RemoveBookmark(std::wstring& id, int window_index) {
227 scoped_refptr<BrowserProxy> browser_proxy = GetBrowserWindow(window_index);
228 EXPECT_TRUE(browser_proxy.get());
229 if (!browser_proxy.get())
230 return false;
231
232 return browser_proxy->RemoveBookmark(StringToId(id));
233 }
234
235 AutomationProxy* PyUITestBase::automation() const { 99 AutomationProxy* PyUITestBase::automation() const {
236 AutomationProxy* automation_proxy = UITestBase::automation(); 100 AutomationProxy* automation_proxy = UITestBase::automation();
237 if (!automation_proxy) { 101 if (!automation_proxy) {
238 LOG(FATAL) << "The automation proxy is NULL."; 102 LOG(FATAL) << "The automation proxy is NULL.";
239 } 103 }
240 return automation_proxy; 104 return automation_proxy;
241 } 105 }
242 106
243
244 scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) { 107 scoped_refptr<BrowserProxy> PyUITestBase::GetBrowserWindow(int window_index) {
245 return automation()->GetBrowserWindow(window_index); 108 return automation()->GetBrowserWindow(window_index);
246 } 109 }
247 110
248 std::string PyUITestBase::_SendJSONRequest(int window_index, 111 std::string PyUITestBase::_SendJSONRequest(int window_index,
249 const std::string& request, 112 const std::string& request,
250 int timeout) { 113 int timeout) {
251 std::string response; 114 std::string response;
252 bool success; 115 bool success;
253 AutomationMessageSender* automation_sender = automation(); 116 AutomationMessageSender* automation_sender = automation();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if (duration >= timeout) { 150 if (duration >= timeout) {
288 ErrorResponse( 151 ErrorResponse(
289 StringPrintf("Request timed out after %d seconds", 152 StringPrintf("Request timed out after %d seconds",
290 static_cast<int>(duration.InSeconds())), 153 static_cast<int>(duration.InSeconds())),
291 request, response); 154 request, response);
292 } else { 155 } else {
293 // TODO(craigdh): Determine specific cause. 156 // TODO(craigdh): Determine specific cause.
294 ErrorResponse("Chrome failed to respond", request, response); 157 ErrorResponse("Chrome failed to respond", request, response);
295 } 158 }
296 } 159 }
OLDNEW
« no previous file with comments | « chrome/test/pyautolib/pyautolib.h ('k') | chrome/test/pyautolib/pyautolib.i » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698