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 <utility> |
| 6 |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
6 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
7 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
9 #include "chrome/browser/download/download_prefs.h" | 11 #include "chrome/browser/download/download_prefs.h" |
10 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
11 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
14 #include "chrome/common/extensions/api/streams_private.h" | 16 #include "chrome/common/extensions/api/streams_private.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // Test server's request handler. | 55 // Test server's request handler. |
54 // Returns response that should be sent by the test server. | 56 // Returns response that should be sent by the test server. |
55 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { | 57 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
56 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse()); | 58 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse()); |
57 | 59 |
58 // For relative path "/doc_path.doc", return success response with MIME type | 60 // For relative path "/doc_path.doc", return success response with MIME type |
59 // "application/msword". | 61 // "application/msword". |
60 if (request.relative_url == "/doc_path.doc") { | 62 if (request.relative_url == "/doc_path.doc") { |
61 response->set_code(net::HTTP_OK); | 63 response->set_code(net::HTTP_OK); |
62 response->set_content_type("application/msword"); | 64 response->set_content_type("application/msword"); |
63 return response.Pass(); | 65 return std::move(response); |
64 } | 66 } |
65 | 67 |
66 // For relative path "/spreadsheet_path.xls", return success response with | 68 // For relative path "/spreadsheet_path.xls", return success response with |
67 // MIME type "application/xls". | 69 // MIME type "application/xls". |
68 if (request.relative_url == "/spreadsheet_path.xls") { | 70 if (request.relative_url == "/spreadsheet_path.xls") { |
69 response->set_code(net::HTTP_OK); | 71 response->set_code(net::HTTP_OK); |
70 response->set_content_type("application/msexcel"); | 72 response->set_content_type("application/msexcel"); |
71 // Test that multiple headers with the same name are merged. | 73 // Test that multiple headers with the same name are merged. |
72 response->AddCustomHeader("Test-Header", "part1"); | 74 response->AddCustomHeader("Test-Header", "part1"); |
73 response->AddCustomHeader("Test-Header", "part2"); | 75 response->AddCustomHeader("Test-Header", "part2"); |
74 return response.Pass(); | 76 return std::move(response); |
75 } | 77 } |
76 | 78 |
77 // For relative path "/text_path_attch.txt", return success response with | 79 // For relative path "/text_path_attch.txt", return success response with |
78 // MIME type "text/plain" and content "txt content". Also, set content | 80 // MIME type "text/plain" and content "txt content". Also, set content |
79 // disposition to be attachment. | 81 // disposition to be attachment. |
80 if (request.relative_url == "/text_path_attch.txt") { | 82 if (request.relative_url == "/text_path_attch.txt") { |
81 response->set_code(net::HTTP_OK); | 83 response->set_code(net::HTTP_OK); |
82 response->set_content("txt content"); | 84 response->set_content("txt content"); |
83 response->set_content_type("text/plain"); | 85 response->set_content_type("text/plain"); |
84 response->AddCustomHeader("Content-Disposition", | 86 response->AddCustomHeader("Content-Disposition", |
85 "attachment; filename=test_path.txt"); | 87 "attachment; filename=test_path.txt"); |
86 return response.Pass(); | 88 return std::move(response); |
87 } | 89 } |
88 | 90 |
89 // For relative path "/test_path_attch.txt", return success response with | 91 // For relative path "/test_path_attch.txt", return success response with |
90 // MIME type "text/plain" and content "txt content". | 92 // MIME type "text/plain" and content "txt content". |
91 if (request.relative_url == "/text_path.txt") { | 93 if (request.relative_url == "/text_path.txt") { |
92 response->set_code(net::HTTP_OK); | 94 response->set_code(net::HTTP_OK); |
93 response->set_content("txt content"); | 95 response->set_content("txt content"); |
94 response->set_content_type("text/plain"); | 96 response->set_content_type("text/plain"); |
95 return response.Pass(); | 97 return std::move(response); |
96 } | 98 } |
97 | 99 |
98 // A random HTML file to navigate to. | 100 // A random HTML file to navigate to. |
99 if (request.relative_url == "/index.html") { | 101 if (request.relative_url == "/index.html") { |
100 response->set_code(net::HTTP_OK); | 102 response->set_code(net::HTTP_OK); |
101 response->set_content("html content"); | 103 response->set_content("html content"); |
102 response->set_content_type("text/html"); | 104 response->set_content_type("text/html"); |
103 return response.Pass(); | 105 return std::move(response); |
104 } | 106 } |
105 | 107 |
106 // RTF files for testing chrome.streamsPrivate.abort(). | 108 // RTF files for testing chrome.streamsPrivate.abort(). |
107 if (request.relative_url == "/abort.rtf" || | 109 if (request.relative_url == "/abort.rtf" || |
108 request.relative_url == "/no_abort.rtf") { | 110 request.relative_url == "/no_abort.rtf") { |
109 response->set_code(net::HTTP_OK); | 111 response->set_code(net::HTTP_OK); |
110 response->set_content_type("application/rtf"); | 112 response->set_content_type("application/rtf"); |
111 return response.Pass(); | 113 return std::move(response); |
112 } | 114 } |
113 | 115 |
114 // Respond to /favicon.ico for navigating to the page. | 116 // Respond to /favicon.ico for navigating to the page. |
115 if (request.relative_url == "/favicon.ico") { | 117 if (request.relative_url == "/favicon.ico") { |
116 response->set_code(net::HTTP_NOT_FOUND); | 118 response->set_code(net::HTTP_NOT_FOUND); |
117 return response.Pass(); | 119 return std::move(response); |
118 } | 120 } |
119 | 121 |
120 // No other requests should be handled in the tests. | 122 // No other requests should be handled in the tests. |
121 EXPECT_TRUE(false) << "NOTREACHED!"; | 123 EXPECT_TRUE(false) << "NOTREACHED!"; |
122 response->set_code(net::HTTP_NOT_FOUND); | 124 response->set_code(net::HTTP_NOT_FOUND); |
123 return response.Pass(); | 125 return std::move(response); |
124 } | 126 } |
125 | 127 |
126 // Tests to verify that resources are correctly intercepted by | 128 // Tests to verify that resources are correctly intercepted by |
127 // StreamsResourceThrottle. | 129 // StreamsResourceThrottle. |
128 // The test extension expects the resources that should be handed to the | 130 // The test extension expects the resources that should be handed to the |
129 // extension to have MIME type 'application/msword' and the resources that | 131 // extension to have MIME type 'application/msword' and the resources that |
130 // should be downloaded by the browser to have MIME type 'text/plain'. | 132 // should be downloaded by the browser to have MIME type 'text/plain'. |
131 class StreamsPrivateApiTest : public ExtensionApiTest { | 133 class StreamsPrivateApiTest : public ExtensionApiTest { |
132 public: | 134 public: |
133 StreamsPrivateApiTest() {} | 135 StreamsPrivateApiTest() {} |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 info.stream_url = "blob://bar"; | 181 info.stream_url = "blob://bar"; |
180 info.tab_id = 10; | 182 info.tab_id = 10; |
181 info.expected_content_size = 20; | 183 info.expected_content_size = 20; |
182 | 184 |
183 scoped_ptr<Event> event(new Event( | 185 scoped_ptr<Event> event(new Event( |
184 extensions::events::STREAMS_PRIVATE_ON_EXECUTE_MIME_TYPE_HANDLER, | 186 extensions::events::STREAMS_PRIVATE_ON_EXECUTE_MIME_TYPE_HANDLER, |
185 streams_private::OnExecuteMimeTypeHandler::kEventName, | 187 streams_private::OnExecuteMimeTypeHandler::kEventName, |
186 streams_private::OnExecuteMimeTypeHandler::Create(info))); | 188 streams_private::OnExecuteMimeTypeHandler::Create(info))); |
187 | 189 |
188 extensions::EventRouter::Get(browser()->profile()) | 190 extensions::EventRouter::Get(browser()->profile()) |
189 ->DispatchEventToExtension(test_extension_id_, event.Pass()); | 191 ->DispatchEventToExtension(test_extension_id_, std::move(event)); |
190 } | 192 } |
191 | 193 |
192 // Loads the test extension and set's up its file_browser_handler to handle | 194 // Loads the test extension and set's up its file_browser_handler to handle |
193 // 'application/msword' and 'text/plain' MIME types. | 195 // 'application/msword' and 'text/plain' MIME types. |
194 // The extension will notify success when it detects an event with the MIME | 196 // The extension will notify success when it detects an event with the MIME |
195 // type 'application/msword' and notify fail when it detects an event with the | 197 // type 'application/msword' and notify fail when it detects an event with the |
196 // MIME type 'text/plain'. | 198 // MIME type 'text/plain'. |
197 const extensions::Extension* LoadTestExtension() { | 199 const extensions::Extension* LoadTestExtension() { |
198 // The test extension id is set by the key value in the manifest. | 200 // The test extension id is set by the key value in the manifest. |
199 test_extension_id_ = "oickdpebdnfbgkcaoklfcdhjniefkcji"; | 201 test_extension_id_ = "oickdpebdnfbgkcaoklfcdhjniefkcji"; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 406 |
405 // Set the downloads parameters. | 407 // Set the downloads parameters. |
406 content::WebContents* web_contents = | 408 content::WebContents* web_contents = |
407 browser()->tab_strip_model()->GetActiveWebContents(); | 409 browser()->tab_strip_model()->GetActiveWebContents(); |
408 ASSERT_TRUE(web_contents); | 410 ASSERT_TRUE(web_contents); |
409 scoped_ptr<DownloadUrlParameters> params( | 411 scoped_ptr<DownloadUrlParameters> params( |
410 DownloadUrlParameters::FromWebContents(web_contents, url)); | 412 DownloadUrlParameters::FromWebContents(web_contents, url)); |
411 params->set_file_path(target_path); | 413 params->set_file_path(target_path); |
412 | 414 |
413 // Start download of the URL with a path "/text_path.txt" on the test server. | 415 // Start download of the URL with a path "/text_path.txt" on the test server. |
414 download_manager->DownloadUrl(params.Pass()); | 416 download_manager->DownloadUrl(std::move(params)); |
415 | 417 |
416 // Wait for the download to start. | 418 // Wait for the download to start. |
417 download_observer->WaitForFinished(); | 419 download_observer->WaitForFinished(); |
418 | 420 |
419 // There should have been one download. | 421 // There should have been one download. |
420 std::vector<DownloadItem*> downloads; | 422 std::vector<DownloadItem*> downloads; |
421 download_manager->GetAllDownloads(&downloads); | 423 download_manager->GetAllDownloads(&downloads); |
422 ASSERT_EQ(1u, downloads.size()); | 424 ASSERT_EQ(1u, downloads.size()); |
423 | 425 |
424 // Cancel and delete the download statred in the test. | 426 // Cancel and delete the download statred in the test. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 base::MessageLoop::current()->RunUntilIdle(); | 483 base::MessageLoop::current()->RunUntilIdle(); |
482 EXPECT_TRUE(catcher.GetNextResult()); | 484 EXPECT_TRUE(catcher.GetNextResult()); |
483 | 485 |
484 ui_test_utils::NavigateToURL(browser(), | 486 ui_test_utils::NavigateToURL(browser(), |
485 test_server_->GetURL("/abort.rtf")); | 487 test_server_->GetURL("/abort.rtf")); |
486 base::MessageLoop::current()->RunUntilIdle(); | 488 base::MessageLoop::current()->RunUntilIdle(); |
487 EXPECT_TRUE(catcher.GetNextResult()); | 489 EXPECT_TRUE(catcher.GetNextResult()); |
488 } | 490 } |
489 | 491 |
490 } // namespace | 492 } // namespace |
OLD | NEW |