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/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "content/browser/download/download_manager_impl.h" | 8 #include "content/browser/download/download_manager_impl.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
14 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
15 #include "content/public/test/content_browser_test.h" | 15 #include "content/public/test/content_browser_test.h" |
16 #include "content/public/test/content_browser_test_utils.h" | 16 #include "content/public/test/content_browser_test_utils.h" |
17 #include "content/public/test/test_utils.h" | 17 #include "content/public/test/test_utils.h" |
18 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
19 #include "content/shell/browser/shell_content_browser_client.h" | 19 #include "content/shell/browser/shell_content_browser_client.h" |
20 #include "content/shell/browser/shell_network_delegate.h" | 20 #include "content/shell/browser/shell_network_delegate.h" |
21 #include "content/test/net/url_request_failed_job.h" | 21 #include "content/test/net/url_request_failed_job.h" |
22 #include "content/test/net/url_request_mock_http_job.h" | |
23 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
24 #include "net/test/embedded_test_server/embedded_test_server.h" | 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
25 #include "net/test/embedded_test_server/http_request.h" | 24 #include "net/test/embedded_test_server/http_request.h" |
26 #include "net/test/embedded_test_server/http_response.h" | 25 #include "net/test/embedded_test_server/http_response.h" |
26 #include "net/test/url_request/url_request_mock_http_job.h" | |
27 | 27 |
28 using base::ASCIIToUTF16; | 28 using base::ASCIIToUTF16; |
29 | 29 |
30 namespace content { | 30 namespace content { |
31 | 31 |
32 class ResourceDispatcherHostBrowserTest : public ContentBrowserTest, | 32 class ResourceDispatcherHostBrowserTest : public ContentBrowserTest, |
33 public DownloadManager::Observer { | 33 public DownloadManager::Observer { |
34 public: | 34 public: |
35 ResourceDispatcherHostBrowserTest() : got_downloads_(false) {} | 35 ResourceDispatcherHostBrowserTest() : got_downloads_(false) {} |
36 | 36 |
37 protected: | 37 protected: |
38 virtual void SetUpOnMainThread() OVERRIDE { | 38 virtual void SetUpOnMainThread() OVERRIDE { |
39 base::FilePath path = GetTestFilePath("", ""); | 39 base::FilePath path = GetTestFilePath("", ""); |
40 BrowserThread::PostTask( | 40 BrowserThread::PostTask( |
41 BrowserThread::IO, FROM_HERE, | 41 BrowserThread::IO, FROM_HERE, |
42 base::Bind(&URLRequestMockHTTPJob::AddUrlHandler, path)); | 42 base::Bind(&net::URLRequestMockHTTPJob::AddUrlHandler, path, |
43 content::BrowserThread::GetBlockingPool())); | |
mmenke
2014/09/04 18:05:11
I think you need to wrap these make_scoped_refptr(
xunjieli
2014/09/04 18:44:25
Done. Thanks!
| |
43 BrowserThread::PostTask( | 44 BrowserThread::PostTask( |
44 BrowserThread::IO, FROM_HERE, | 45 BrowserThread::IO, FROM_HERE, |
45 base::Bind(&URLRequestFailedJob::AddUrlHandler)); | 46 base::Bind(&URLRequestFailedJob::AddUrlHandler)); |
46 } | 47 } |
47 | 48 |
48 virtual void OnDownloadCreated( | 49 virtual void OnDownloadCreated( |
49 DownloadManager* manager, | 50 DownloadManager* manager, |
50 DownloadItem* item) OVERRIDE { | 51 DownloadItem* item) OVERRIDE { |
51 if (!got_downloads_) | 52 if (!got_downloads_) |
52 got_downloads_ = !!manager->InProgressCount(); | 53 got_downloads_ = !!manager->InProgressCount(); |
53 } | 54 } |
54 | 55 |
55 GURL GetMockURL(const std::string& file) { | 56 GURL GetMockURL(const std::string& file) { |
56 return URLRequestMockHTTPJob::GetMockUrl( | 57 return net::URLRequestMockHTTPJob::GetMockUrl( |
57 base::FilePath().AppendASCII(file)); | 58 base::FilePath().AppendASCII(file)); |
58 } | 59 } |
59 | 60 |
60 void CheckTitleTest(const GURL& url, | 61 void CheckTitleTest(const GURL& url, |
61 const std::string& expected_title) { | 62 const std::string& expected_title) { |
62 base::string16 expected_title16(ASCIIToUTF16(expected_title)); | 63 base::string16 expected_title16(ASCIIToUTF16(expected_title)); |
63 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); | 64 TitleWatcher title_watcher(shell()->web_contents(), expected_title16); |
64 NavigateToURL(shell(), url); | 65 NavigateToURL(shell(), url); |
65 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); | 66 EXPECT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); |
66 } | 67 } |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 "http://localhost:%d/set_cookie.html", embedded_test_server()->port())); | 462 "http://localhost:%d/set_cookie.html", embedded_test_server()->port())); |
462 GURL url(embedded_test_server()->GetURL("/redirect?" + set_cookie_url)); | 463 GURL url(embedded_test_server()->GetURL("/redirect?" + set_cookie_url)); |
463 | 464 |
464 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); | 465 ShellContentBrowserClient::SetSwapProcessesForRedirect(true); |
465 ShellNetworkDelegate::SetAcceptAllCookies(false); | 466 ShellNetworkDelegate::SetAcceptAllCookies(false); |
466 | 467 |
467 CheckTitleTest(url, "cookie set"); | 468 CheckTitleTest(url, "cookie set"); |
468 } | 469 } |
469 | 470 |
470 } // namespace content | 471 } // namespace content |
OLD | NEW |