| 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> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/download/download_prefs.h" | 10 #include "chrome/browser/download/download_prefs.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 using net::test_server::HttpRequest; | 47 using net::test_server::HttpRequest; |
| 48 using net::test_server::HttpResponse; | 48 using net::test_server::HttpResponse; |
| 49 using testing::_; | 49 using testing::_; |
| 50 | 50 |
| 51 namespace streams_private = extensions::api::streams_private; | 51 namespace streams_private = extensions::api::streams_private; |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 | 54 |
| 55 // Test server's request handler. | 55 // Test server's request handler. |
| 56 // Returns response that should be sent by the test server. | 56 // Returns response that should be sent by the test server. |
| 57 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { | 57 std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
| 58 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse()); | 58 std::unique_ptr<BasicHttpResponse> response(new BasicHttpResponse()); |
| 59 | 59 |
| 60 // 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 |
| 61 // "application/msword". | 61 // "application/msword". |
| 62 if (request.relative_url == "/doc_path.doc") { | 62 if (request.relative_url == "/doc_path.doc") { |
| 63 response->set_code(net::HTTP_OK); | 63 response->set_code(net::HTTP_OK); |
| 64 response->set_content_type("application/msword"); | 64 response->set_content_type("application/msword"); |
| 65 return std::move(response); | 65 return std::move(response); |
| 66 } | 66 } |
| 67 | 67 |
| 68 // For relative path "/spreadsheet_path.xls", return success response with | 68 // For relative path "/spreadsheet_path.xls", return success response with |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // event with the "test/done" MIME type (unless the 'chrome.test.notifyFail' | 175 // event with the "test/done" MIME type (unless the 'chrome.test.notifyFail' |
| 176 // has already been called). | 176 // has already been called). |
| 177 void SendDoneEvent() { | 177 void SendDoneEvent() { |
| 178 streams_private::StreamInfo info; | 178 streams_private::StreamInfo info; |
| 179 info.mime_type = "test/done"; | 179 info.mime_type = "test/done"; |
| 180 info.original_url = "http://foo"; | 180 info.original_url = "http://foo"; |
| 181 info.stream_url = "blob://bar"; | 181 info.stream_url = "blob://bar"; |
| 182 info.tab_id = 10; | 182 info.tab_id = 10; |
| 183 info.expected_content_size = 20; | 183 info.expected_content_size = 20; |
| 184 | 184 |
| 185 scoped_ptr<Event> event(new Event( | 185 std::unique_ptr<Event> event(new Event( |
| 186 extensions::events::STREAMS_PRIVATE_ON_EXECUTE_MIME_TYPE_HANDLER, | 186 extensions::events::STREAMS_PRIVATE_ON_EXECUTE_MIME_TYPE_HANDLER, |
| 187 streams_private::OnExecuteMimeTypeHandler::kEventName, | 187 streams_private::OnExecuteMimeTypeHandler::kEventName, |
| 188 streams_private::OnExecuteMimeTypeHandler::Create(info))); | 188 streams_private::OnExecuteMimeTypeHandler::Create(info))); |
| 189 | 189 |
| 190 extensions::EventRouter::Get(browser()->profile()) | 190 extensions::EventRouter::Get(browser()->profile()) |
| 191 ->DispatchEventToExtension(test_extension_id_, std::move(event)); | 191 ->DispatchEventToExtension(test_extension_id_, std::move(event)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // 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 |
| 195 // 'application/msword' and 'text/plain' MIME types. | 195 // 'application/msword' and 'text/plain' MIME types. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 DownloadManager* manager) { | 230 DownloadManager* manager) { |
| 231 scoped_refptr<content::DownloadTestFlushObserver> flush_observer( | 231 scoped_refptr<content::DownloadTestFlushObserver> flush_observer( |
| 232 new content::DownloadTestFlushObserver(manager)); | 232 new content::DownloadTestFlushObserver(manager)); |
| 233 download->Remove(); | 233 download->Remove(); |
| 234 flush_observer->WaitForFlush(); | 234 flush_observer->WaitForFlush(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 protected: | 237 protected: |
| 238 std::string test_extension_id_; | 238 std::string test_extension_id_; |
| 239 // The HTTP server used in the tests. | 239 // The HTTP server used in the tests. |
| 240 scoped_ptr<net::EmbeddedTestServer> test_server_; | 240 std::unique_ptr<net::EmbeddedTestServer> test_server_; |
| 241 base::ScopedTempDir downloads_dir_; | 241 base::ScopedTempDir downloads_dir_; |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 // Tests that navigating to a resource with a MIME type handleable by an | 244 // Tests that navigating to a resource with a MIME type handleable by an |
| 245 // installed, white-listed extension invokes the extension's | 245 // installed, white-listed extension invokes the extension's |
| 246 // onExecuteContentHandler event (and does not start a download). | 246 // onExecuteContentHandler event (and does not start a download). |
| 247 IN_PROC_BROWSER_TEST_F(StreamsPrivateApiTest, Navigate) { | 247 IN_PROC_BROWSER_TEST_F(StreamsPrivateApiTest, Navigate) { |
| 248 #if defined(OS_WIN) && defined(USE_ASH) | 248 #if defined(OS_WIN) && defined(USE_ASH) |
| 249 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 249 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 250 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 250 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 // type. | 350 // type. |
| 351 IN_PROC_BROWSER_TEST_F(StreamsPrivateApiTest, NavigateToAnAttachment) { | 351 IN_PROC_BROWSER_TEST_F(StreamsPrivateApiTest, NavigateToAnAttachment) { |
| 352 InitializeDownloadSettings(); | 352 InitializeDownloadSettings(); |
| 353 | 353 |
| 354 ASSERT_TRUE(LoadTestExtension()) << message_; | 354 ASSERT_TRUE(LoadTestExtension()) << message_; |
| 355 | 355 |
| 356 ResultCatcher catcher; | 356 ResultCatcher catcher; |
| 357 | 357 |
| 358 // The test should start a download. | 358 // The test should start a download. |
| 359 DownloadManager* download_manager = GetDownloadManager(); | 359 DownloadManager* download_manager = GetDownloadManager(); |
| 360 scoped_ptr<content::DownloadTestObserver> download_observer( | 360 std::unique_ptr<content::DownloadTestObserver> download_observer( |
| 361 new content::DownloadTestObserverInProgress(download_manager, 1)); | 361 new content::DownloadTestObserverInProgress(download_manager, 1)); |
| 362 | 362 |
| 363 ui_test_utils::NavigateToURL(browser(), | 363 ui_test_utils::NavigateToURL(browser(), |
| 364 test_server_->GetURL("/text_path_attch.txt")); | 364 test_server_->GetURL("/text_path_attch.txt")); |
| 365 | 365 |
| 366 // Wait for the download to start. | 366 // Wait for the download to start. |
| 367 download_observer->WaitForFinished(); | 367 download_observer->WaitForFinished(); |
| 368 | 368 |
| 369 // There should be one download started by the navigation. | 369 // There should be one download started by the navigation. |
| 370 DownloadManager::DownloadVector downloads; | 370 DownloadManager::DownloadVector downloads; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 387 // StreamsResourceThrottle, even if there is an extension with a file | 387 // StreamsResourceThrottle, even if there is an extension with a file |
| 388 // browser handler that can handle the download's MIME type. | 388 // browser handler that can handle the download's MIME type. |
| 389 IN_PROC_BROWSER_TEST_F(StreamsPrivateApiTest, DirectDownload) { | 389 IN_PROC_BROWSER_TEST_F(StreamsPrivateApiTest, DirectDownload) { |
| 390 InitializeDownloadSettings(); | 390 InitializeDownloadSettings(); |
| 391 | 391 |
| 392 ASSERT_TRUE(LoadTestExtension()) << message_; | 392 ASSERT_TRUE(LoadTestExtension()) << message_; |
| 393 | 393 |
| 394 ResultCatcher catcher; | 394 ResultCatcher catcher; |
| 395 | 395 |
| 396 DownloadManager* download_manager = GetDownloadManager(); | 396 DownloadManager* download_manager = GetDownloadManager(); |
| 397 scoped_ptr<content::DownloadTestObserver> download_observer( | 397 std::unique_ptr<content::DownloadTestObserver> download_observer( |
| 398 new content::DownloadTestObserverInProgress(download_manager, 1)); | 398 new content::DownloadTestObserverInProgress(download_manager, 1)); |
| 399 | 399 |
| 400 // The resource's URL on the test server. | 400 // The resource's URL on the test server. |
| 401 GURL url = test_server_->GetURL("/text_path.txt"); | 401 GURL url = test_server_->GetURL("/text_path.txt"); |
| 402 | 402 |
| 403 // The download's target file path. | 403 // The download's target file path. |
| 404 base::FilePath target_path = | 404 base::FilePath target_path = |
| 405 downloads_dir_.path().Append(FILE_PATH_LITERAL("download_target.txt")); | 405 downloads_dir_.path().Append(FILE_PATH_LITERAL("download_target.txt")); |
| 406 | 406 |
| 407 // Set the downloads parameters. | 407 // Set the downloads parameters. |
| 408 content::WebContents* web_contents = | 408 content::WebContents* web_contents = |
| 409 browser()->tab_strip_model()->GetActiveWebContents(); | 409 browser()->tab_strip_model()->GetActiveWebContents(); |
| 410 ASSERT_TRUE(web_contents); | 410 ASSERT_TRUE(web_contents); |
| 411 scoped_ptr<DownloadUrlParameters> params( | 411 std::unique_ptr<DownloadUrlParameters> params( |
| 412 DownloadUrlParameters::FromWebContents(web_contents, url)); | 412 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 413 params->set_file_path(target_path); | 413 params->set_file_path(target_path); |
| 414 | 414 |
| 415 // 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. |
| 416 download_manager->DownloadUrl(std::move(params)); | 416 download_manager->DownloadUrl(std::move(params)); |
| 417 | 417 |
| 418 // Wait for the download to start. | 418 // Wait for the download to start. |
| 419 download_observer->WaitForFinished(); | 419 download_observer->WaitForFinished(); |
| 420 | 420 |
| 421 // There should have been one download. | 421 // There should have been one download. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 base::MessageLoop::current()->RunUntilIdle(); | 483 base::MessageLoop::current()->RunUntilIdle(); |
| 484 EXPECT_TRUE(catcher.GetNextResult()); | 484 EXPECT_TRUE(catcher.GetNextResult()); |
| 485 | 485 |
| 486 ui_test_utils::NavigateToURL(browser(), | 486 ui_test_utils::NavigateToURL(browser(), |
| 487 test_server_->GetURL("/abort.rtf")); | 487 test_server_->GetURL("/abort.rtf")); |
| 488 base::MessageLoop::current()->RunUntilIdle(); | 488 base::MessageLoop::current()->RunUntilIdle(); |
| 489 EXPECT_TRUE(catcher.GetNextResult()); | 489 EXPECT_TRUE(catcher.GetNextResult()); |
| 490 } | 490 } |
| 491 | 491 |
| 492 } // namespace | 492 } // namespace |
| OLD | NEW |