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 "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/synchronization/waitable_event.h" | |
7 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
8 #include "content/browser/download/download_manager_impl.h" | 7 #include "content/browser/download/download_manager_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 8 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/common/test_url_constants.h" | 9 #include "content/common/test_url_constants.h" |
11 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
12 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/notification_types.h" | 13 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
16 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
17 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
18 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
19 #include "content/shell/shell.h" | 18 #include "content/shell/shell.h" |
20 #include "content/test/content_browser_test.h" | 19 #include "content/test/content_browser_test.h" |
21 #include "content/test/content_browser_test_utils.h" | 20 #include "content/test/content_browser_test_utils.h" |
22 #include "content/test/net/url_request_failed_job.h" | 21 #include "content/test/net/url_request_failed_job.h" |
23 #include "content/test/net/url_request_mock_http_job.h" | 22 #include "content/test/net/url_request_mock_http_job.h" |
24 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
25 #include "net/cookies/cookie_store.h" | |
26 #include "net/test/test_server.h" | 24 #include "net/test/test_server.h" |
27 #include "net/url_request/url_request_context.h" | |
28 #include "net/url_request/url_request_context_getter.h" | |
29 | 25 |
30 namespace content { | 26 namespace content { |
31 | 27 |
32 namespace { | |
33 | |
34 void GetCookiesCallback(std::string* cookies_out, | |
35 base::WaitableEvent* event, | |
36 const std::string& cookies) { | |
37 *cookies_out = cookies; | |
38 event->Signal(); | |
39 } | |
40 | |
41 void GetCookiesOnIOThread(const GURL& url, | |
42 net::URLRequestContextGetter* context_getter, | |
43 base::WaitableEvent* event, | |
44 std::string* cookies) { | |
45 net::CookieStore* cookie_store = | |
46 context_getter->GetURLRequestContext()->cookie_store(); | |
47 cookie_store->GetCookiesWithOptionsAsync( | |
48 url, net::CookieOptions(), | |
49 base::Bind(&GetCookiesCallback, | |
50 base::Unretained(cookies), base::Unretained(event))); | |
51 } | |
52 | |
53 } // namespace | |
54 | |
55 class ResourceDispatcherHostBrowserTest : public ContentBrowserTest, | 28 class ResourceDispatcherHostBrowserTest : public ContentBrowserTest, |
56 public DownloadManager::Observer { | 29 public DownloadManager::Observer { |
57 public: | 30 public: |
58 ResourceDispatcherHostBrowserTest() : got_downloads_(false) {} | 31 ResourceDispatcherHostBrowserTest() : got_downloads_(false) {} |
59 | 32 |
60 protected: | 33 protected: |
61 virtual void SetUpOnMainThread() OVERRIDE { | 34 virtual void SetUpOnMainThread() OVERRIDE { |
62 FilePath path = GetTestFilePath("", ""); | 35 FilePath path = GetTestFilePath("", ""); |
63 BrowserThread::PostTask( | 36 BrowserThread::PostTask( |
64 BrowserThread::IO, FROM_HERE, | 37 BrowserThread::IO, FROM_HERE, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Create dynamic popup. | 70 // Create dynamic popup. |
98 if (!ExecuteJavaScript(render_view_host(), L"", L"OpenPopup();")) | 71 if (!ExecuteJavaScript(render_view_host(), L"", L"OpenPopup();")) |
99 return false; | 72 return false; |
100 | 73 |
101 Shell* new_shell = new_shell_observer.GetShell(); | 74 Shell* new_shell = new_shell_observer.GetShell(); |
102 *title = new_shell->web_contents()->GetTitle(); | 75 *title = new_shell->web_contents()->GetTitle(); |
103 return true; | 76 return true; |
104 } | 77 } |
105 | 78 |
106 std::string GetCookies(const GURL& url) { | 79 std::string GetCookies(const GURL& url) { |
107 std::string cookies; | 80 return content::GetCookies( |
108 base::WaitableEvent event(true, false); | 81 shell()->web_contents()->GetBrowserContext(), url); |
109 net::URLRequestContextGetter* context_getter = | |
110 shell()->web_contents()->GetBrowserContext()->GetRequestContext(); | |
111 | |
112 BrowserThread::PostTask( | |
113 BrowserThread::IO, FROM_HERE, | |
114 base::Bind(&GetCookiesOnIOThread, url, | |
115 make_scoped_refptr(context_getter), &event, &cookies)); | |
116 event.Wait(); | |
117 return cookies; | |
118 } | 82 } |
119 | 83 |
120 bool got_downloads() const { return got_downloads_; } | 84 bool got_downloads() const { return got_downloads_; } |
121 | 85 |
122 private: | 86 private: |
123 bool got_downloads_; | 87 bool got_downloads_; |
124 }; | 88 }; |
125 | 89 |
126 // Test title for content created by javascript window.open(). | 90 // Test title for content created by javascript window.open(). |
127 // See http://crbug.com/5988 | 91 // See http://crbug.com/5988 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 CrossSiteFailedRequest) { | 395 CrossSiteFailedRequest) { |
432 // Visit another URL first to trigger a cross-site navigation. | 396 // Visit another URL first to trigger a cross-site navigation. |
433 NavigateToURL(shell(), GetTestUrl("", "simple_page.html")); | 397 NavigateToURL(shell(), GetTestUrl("", "simple_page.html")); |
434 | 398 |
435 // Visit a URL that fails without calling ResourceDispatcherHost::Read. | 399 // Visit a URL that fails without calling ResourceDispatcherHost::Read. |
436 GURL broken_url("chrome://theme"); | 400 GURL broken_url("chrome://theme"); |
437 NavigateToURL(shell(), broken_url); | 401 NavigateToURL(shell(), broken_url); |
438 } | 402 } |
439 | 403 |
440 } // namespace content | 404 } // namespace content |
OLD | NEW |