OLD | NEW |
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 "content/public/test/browser_test_utils.h" | 5 #include "content/public/test/browser_test_utils.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/synchronization/waitable_event.h" |
13 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "content/public/browser/browser_context.h" |
16 #include "content/public/browser/dom_operation_notification_details.h" | 18 #include "content/public/browser/dom_operation_notification_details.h" |
17 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
18 #include "content/public/browser/render_process_host.h" | 20 #include "content/public/browser/render_process_host.h" |
19 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
20 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_contents_observer.h" | 23 #include "content/public/browser/web_contents_observer.h" |
22 #include "content/public/browser/web_contents_view.h" | 24 #include "content/public/browser/web_contents_view.h" |
23 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 26 #include "net/cookies/cookie_store.h" |
24 #include "net/test/python_utils.h" | 27 #include "net/test/python_utils.h" |
| 28 #include "net/url_request/url_request_context.h" |
| 29 #include "net/url_request/url_request_context_getter.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
26 | 31 |
27 static const int kDefaultWsPort = 8880; | 32 static const int kDefaultWsPort = 8880; |
28 | 33 |
29 namespace content { | 34 namespace content { |
30 | 35 |
31 namespace { | 36 namespace { |
32 | 37 |
33 class DOMOperationObserver : public NotificationObserver, | 38 class DOMOperationObserver : public NotificationObserver, |
34 public WebContentsObserver { | 39 public WebContentsObserver { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (shift) | 144 if (shift) |
140 event->modifiers |= WebKit::WebInputEvent::ShiftKey; | 145 event->modifiers |= WebKit::WebInputEvent::ShiftKey; |
141 | 146 |
142 if (alt) | 147 if (alt) |
143 event->modifiers |= WebKit::WebInputEvent::AltKey; | 148 event->modifiers |= WebKit::WebInputEvent::AltKey; |
144 | 149 |
145 if (command) | 150 if (command) |
146 event->modifiers |= WebKit::WebInputEvent::MetaKey; | 151 event->modifiers |= WebKit::WebInputEvent::MetaKey; |
147 } | 152 } |
148 | 153 |
| 154 void GetCookiesCallback(std::string* cookies_out, |
| 155 base::WaitableEvent* event, |
| 156 const std::string& cookies) { |
| 157 *cookies_out = cookies; |
| 158 event->Signal(); |
| 159 } |
| 160 |
| 161 void GetCookiesOnIOThread(const GURL& url, |
| 162 net::URLRequestContextGetter* context_getter, |
| 163 base::WaitableEvent* event, |
| 164 std::string* cookies) { |
| 165 net::CookieStore* cookie_store = |
| 166 context_getter->GetURLRequestContext()->cookie_store(); |
| 167 cookie_store->GetCookiesWithOptionsAsync( |
| 168 url, net::CookieOptions(), |
| 169 base::Bind(&GetCookiesCallback, |
| 170 base::Unretained(cookies), base::Unretained(event))); |
| 171 } |
| 172 |
149 } // namespace | 173 } // namespace |
150 | 174 |
151 | 175 |
152 GURL GetFileUrlWithQuery(const FilePath& path, | 176 GURL GetFileUrlWithQuery(const FilePath& path, |
153 const std::string& query_string) { | 177 const std::string& query_string) { |
154 GURL url = net::FilePathToFileURL(path); | 178 GURL url = net::FilePathToFileURL(path); |
155 if (!query_string.empty()) { | 179 if (!query_string.empty()) { |
156 GURL::Replacements replacements; | 180 GURL::Replacements replacements; |
157 replacements.SetQueryStr(query_string); | 181 replacements.SetQueryStr(query_string); |
158 return url.ReplaceComponents(replacements); | 182 return url.ReplaceComponents(replacements); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 std::string* result) { | 298 std::string* result) { |
275 DCHECK(result); | 299 DCHECK(result); |
276 scoped_ptr<Value> value; | 300 scoped_ptr<Value> value; |
277 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) || | 301 if (!ExecuteJavaScriptHelper(render_view_host, frame_xpath, script, &value) || |
278 !value.get()) | 302 !value.get()) |
279 return false; | 303 return false; |
280 | 304 |
281 return value->GetAsString(result); | 305 return value->GetAsString(result); |
282 } | 306 } |
283 | 307 |
| 308 std::string GetCookies(BrowserContext* browser_context, const GURL& url) { |
| 309 std::string cookies; |
| 310 base::WaitableEvent event(true, false); |
| 311 net::URLRequestContextGetter* context_getter = |
| 312 browser_context->GetRequestContext(); |
| 313 |
| 314 BrowserThread::PostTask( |
| 315 BrowserThread::IO, FROM_HERE, |
| 316 base::Bind(&GetCookiesOnIOThread, url, |
| 317 make_scoped_refptr(context_getter), &event, &cookies)); |
| 318 event.Wait(); |
| 319 return cookies; |
| 320 } |
| 321 |
284 TitleWatcher::TitleWatcher(WebContents* web_contents, | 322 TitleWatcher::TitleWatcher(WebContents* web_contents, |
285 const string16& expected_title) | 323 const string16& expected_title) |
286 : web_contents_(web_contents), | 324 : web_contents_(web_contents), |
287 expected_title_observed_(false), | 325 expected_title_observed_(false), |
288 quit_loop_on_observation_(false) { | 326 quit_loop_on_observation_(false) { |
289 EXPECT_TRUE(web_contents != NULL); | 327 EXPECT_TRUE(web_contents != NULL); |
290 expected_titles_.push_back(expected_title); | 328 expected_titles_.push_back(expected_title); |
291 notification_registrar_.Add(this, | 329 notification_registrar_.Add(this, |
292 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | 330 NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
293 Source<WebContents>(web_contents)); | 331 Source<WebContents>(web_contents)); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 base::LaunchProcess(*cmd_line.get(), options, NULL); | 528 base::LaunchProcess(*cmd_line.get(), options, NULL); |
491 | 529 |
492 #if defined(OS_POSIX) | 530 #if defined(OS_POSIX) |
493 // Just to make sure that the server process terminates certainly. | 531 // Just to make sure that the server process terminates certainly. |
494 if (process_group_id_ != base::kNullProcessHandle) | 532 if (process_group_id_ != base::kNullProcessHandle) |
495 base::KillProcessGroup(process_group_id_); | 533 base::KillProcessGroup(process_group_id_); |
496 #endif | 534 #endif |
497 } | 535 } |
498 | 536 |
499 } // namespace content | 537 } // namespace content |
OLD | NEW |