| 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "chrome/browser/chromeos/extensions/file_browser_handler.h" | |
| 8 #include "chrome/browser/chromeos/extensions/file_browser_resource_throttle.h" | |
| 9 #include "chrome/browser/download/download_prefs.h" | 7 #include "chrome/browser/download/download_prefs.h" |
| 8 #include "chrome/browser/extensions/api/streams_private/streams_resource_throttl
e.h" |
| 10 #include "chrome/browser/extensions/event_router.h" | 9 #include "chrome/browser/extensions/event_router.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_info_map.h" | 11 #include "chrome/browser/extensions/extension_info_map.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/google_apis/test_server/http_request.h" | 13 #include "chrome/browser/google_apis/test_server/http_request.h" |
| 15 #include "chrome/browser/google_apis/test_server/http_response.h" | 14 #include "chrome/browser/google_apis/test_server/http_response.h" |
| 16 #include "chrome/browser/google_apis/test_server/http_server.h" | 15 #include "chrome/browser/google_apis/test_server/http_server.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/common/extensions/mime_types_handler.h" |
| 20 #include "chrome/common/pref_names.cc" | 20 #include "chrome/common/pref_names.cc" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 22 #include "content/public/browser/download_item.h" | 22 #include "content/public/browser/download_item.h" |
| 23 #include "content/public/browser/download_manager.h" | 23 #include "content/public/browser/download_manager.h" |
| 24 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 25 #include "content/public/browser/resource_controller.h" | 25 #include "content/public/browser/resource_controller.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/test/download_test_observer.h" | 27 #include "content/public/test/download_test_observer.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 | 29 |
| 30 using content::BrowserContext; | 30 using content::BrowserContext; |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 using content::DownloadItem; | 32 using content::DownloadItem; |
| 33 using content::DownloadManager; | 33 using content::DownloadManager; |
| 34 using content::DownloadUrlParameters; | 34 using content::DownloadUrlParameters; |
| 35 using content::ResourceController; | 35 using content::ResourceController; |
| 36 using content::WebContents; | 36 using content::WebContents; |
| 37 using extensions::Event; | 37 using extensions::Event; |
| 38 using extensions::ExtensionSystem; | 38 using extensions::ExtensionSystem; |
| 39 using google_apis::test_server::HttpRequest; | 39 using google_apis::test_server::HttpRequest; |
| 40 using google_apis::test_server::HttpResponse; | 40 using google_apis::test_server::HttpResponse; |
| 41 using google_apis::test_server::HttpServer; | 41 using google_apis::test_server::HttpServer; |
| 42 using testing::_; | 42 using testing::_; |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 // Used in FileBrowserResourceThrottleExtensionApiTest.Basic test to mock the | 46 // Used in StreamsResourceThrottleExtensionApiTest.Basic test to mock the |
| 47 // resource controller bound to the test resource throttle. | 47 // resource controller bound to the test resource throttle. |
| 48 class MockResourceController : public ResourceController { | 48 class MockResourceController : public ResourceController { |
| 49 public: | 49 public: |
| 50 virtual ~MockResourceController() {} | 50 virtual ~MockResourceController() {} |
| 51 MOCK_METHOD0(Cancel, void()); | 51 MOCK_METHOD0(Cancel, void()); |
| 52 MOCK_METHOD0(CancelAndIgnore, void()); | 52 MOCK_METHOD0(CancelAndIgnore, void()); |
| 53 MOCK_METHOD1(CancelWithError, void(int error_code)); | 53 MOCK_METHOD1(CancelWithError, void(int error_code)); |
| 54 MOCK_METHOD0(Resume, void()); | 54 MOCK_METHOD0(Resume, void()); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 // Creates and triggers a test FileBrowserResourceThrottle for the listed | 57 // Creates and triggers a test StreamsResourceThrottle for the listed |
| 58 // request parameters (child and routing id from which the request came, | 58 // request parameters (child and routing id from which the request came, |
| 59 // request's MIME type and URL), with extension info map |info_map| and resource | 59 // request's MIME type and URL), with extension info map |info_map| and resource |
| 60 // controller |controller|. | 60 // controller |controller|. |
| 61 // The created resource throttle is started by calling |WillProcessResponse|. | 61 // The created resource throttle is started by calling |WillProcessResponse|. |
| 62 // Used in FileBrowserResourceThrottleExtensionApiTest.Basic test. | 62 // Used in StreamsResourceThrottleExtensionApiTest.Basic test. |
| 63 // | 63 // |
| 64 // Must be called on the IO thread. | 64 // Must be called on the IO thread. |
| 65 void CreateAndTriggerThrottle(int child_id, | 65 void CreateAndTriggerThrottle(int child_id, |
| 66 int routing_id, | 66 int routing_id, |
| 67 const std::string& mime_type, | 67 const std::string& mime_type, |
| 68 const GURL& url, | 68 const GURL& url, |
| 69 bool is_incognito, | 69 bool is_incognito, |
| 70 scoped_refptr<ExtensionInfoMap> info_map, | 70 scoped_refptr<ExtensionInfoMap> info_map, |
| 71 ResourceController* controller) { | 71 ResourceController* controller) { |
| 72 typedef FileBrowserResourceThrottle::FileBrowserHandlerEventRouter | 72 typedef StreamsResourceThrottle::StreamsPrivateEventRouter |
| 73 HandlerEventRouter; | 73 HandlerEventRouter; |
| 74 scoped_ptr<FileBrowserResourceThrottle> throttle( | 74 scoped_ptr<StreamsResourceThrottle> throttle( |
| 75 FileBrowserResourceThrottle::CreateForTest(child_id, routing_id, | 75 StreamsResourceThrottle::CreateForTest(child_id, routing_id, |
| 76 mime_type, url, is_incognito, info_map, | 76 mime_type, url, is_incognito, info_map, |
| 77 scoped_ptr<HandlerEventRouter>())); | 77 scoped_ptr<HandlerEventRouter>())); |
| 78 | 78 |
| 79 throttle->set_controller_for_testing(controller); | 79 throttle->set_controller_for_testing(controller); |
| 80 | 80 |
| 81 bool defer; | 81 bool defer = false; |
| 82 throttle->WillProcessResponse(&defer); | 82 throttle->WillProcessResponse(&defer); |
| 83 EXPECT_FALSE(defer); | 83 EXPECT_FALSE(defer); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // Test server's request handler. | 86 // Test server's request handler. |
| 87 // Returns response that should be sent by the test server. | 87 // Returns response that should be sent by the test server. |
| 88 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { | 88 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request) { |
| 89 scoped_ptr<HttpResponse> response(new HttpResponse()); | 89 scoped_ptr<HttpResponse> response(new HttpResponse()); |
| 90 | 90 |
| 91 // For relative path "/doc_path.doc", return success response with MIME type | 91 // For relative path "/doc_path.doc", return success response with MIME type |
| (...skipping 24 matching lines...) Expand all Loading... |
| 116 return response.Pass(); | 116 return response.Pass(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 // No other requests should be handled in the tests. | 119 // No other requests should be handled in the tests. |
| 120 EXPECT_TRUE(false) << "NOTREACHED!"; | 120 EXPECT_TRUE(false) << "NOTREACHED!"; |
| 121 response->set_code(google_apis::test_server::NOT_FOUND); | 121 response->set_code(google_apis::test_server::NOT_FOUND); |
| 122 return response.Pass(); | 122 return response.Pass(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Tests to verify that resources are correctly intercepted by | 125 // Tests to verify that resources are correctly intercepted by |
| 126 // FileBrowserResourceThrottle. | 126 // StreamsResourceThrottle. |
| 127 // The test extension expects the resources that should be handed to the | 127 // The test extension expects the resources that should be handed to the |
| 128 // extension to have MIME type 'application/msword' and the resources that | 128 // extension to have MIME type 'application/msword' and the resources that |
| 129 // should be downloaded by the browser to have MIME type 'plain/text'. | 129 // should be downloaded by the browser to have MIME type 'plain/text'. |
| 130 class FileBrowserResourceThrottleExtensionApiTest : public ExtensionApiTest { | 130 class StreamsResourceThrottleExtensionApiTest : public ExtensionApiTest { |
| 131 public: | 131 public: |
| 132 FileBrowserResourceThrottleExtensionApiTest() {} | 132 StreamsResourceThrottleExtensionApiTest() {} |
| 133 | 133 |
| 134 virtual ~FileBrowserResourceThrottleExtensionApiTest() { | 134 virtual ~StreamsResourceThrottleExtensionApiTest() { |
| 135 // Clear the test extension from the white-list. | 135 // Clear the test extension from the white-list. |
| 136 FileBrowserHandler::set_extension_whitelisted_for_test(NULL); | 136 MimeTypesHandler::set_extension_whitelisted_for_test(NULL); |
| 137 } | 137 } |
| 138 | 138 |
| 139 virtual void SetUpOnMainThread() OVERRIDE { | 139 virtual void SetUpOnMainThread() OVERRIDE { |
| 140 // Init test server. | 140 // Init test server. |
| 141 test_server_.reset(new HttpServer()); | 141 test_server_.reset(new HttpServer()); |
| 142 test_server_->InitializeAndWaitUntilReady(); | 142 test_server_->InitializeAndWaitUntilReady(); |
| 143 test_server_->RegisterRequestHandler(base::Bind(&HandleRequest)); | 143 test_server_->RegisterRequestHandler(base::Bind(&HandleRequest)); |
| 144 | 144 |
| 145 ExtensionApiTest::SetUpOnMainThread(); | 145 ExtensionApiTest::SetUpOnMainThread(); |
| 146 } | 146 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 173 // test extension. | 173 // test extension. |
| 174 // The test extension calls 'chrome.test.notifySuccess' when it receives the | 174 // The test extension calls 'chrome.test.notifySuccess' when it receives the |
| 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 scoped_ptr<ListValue> event_args(new ListValue()); | 178 scoped_ptr<ListValue> event_args(new ListValue()); |
| 179 event_args->Append(new base::StringValue("test/done")); | 179 event_args->Append(new base::StringValue("test/done")); |
| 180 event_args->Append(new base::StringValue("http://foo")); | 180 event_args->Append(new base::StringValue("http://foo")); |
| 181 | 181 |
| 182 scoped_ptr<Event> event(new Event( | 182 scoped_ptr<Event> event(new Event( |
| 183 "fileBrowserHandler.onExecuteContentHandler", event_args.Pass())); | 183 "streamsPrivate.onExecuteMimeTypeHandler", event_args.Pass())); |
| 184 | 184 |
| 185 ExtensionSystem::Get(browser()->profile())->event_router()-> | 185 ExtensionSystem::Get(browser()->profile())->event_router()-> |
| 186 DispatchEventToExtension(test_extension_id_, event.Pass()); | 186 DispatchEventToExtension(test_extension_id_, event.Pass()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Loads the test extension and set's up its file_browser_handler to handle | 189 // Loads the test extension and set's up its file_browser_handler to handle |
| 190 // 'application/msword' and 'plain/text' MIME types. | 190 // 'application/msword' and 'plain/text' MIME types. |
| 191 // The extension will notify success when it detects an event with the MIME | 191 // The extension will notify success when it detects an event with the MIME |
| 192 // type 'application/msword' and notify fail when it detects an event with the | 192 // type 'application/msword' and notify fail when it detects an event with the |
| 193 // MIME type 'plain/text'. | 193 // MIME type 'plain/text'. |
| 194 const extensions::Extension* LoadTestExtension() { | 194 const extensions::Extension* LoadTestExtension() { |
| 195 // The test extension id is set by the key value in the manifest. |
| 196 test_extension_id_ = "oickdpebdnfbgkcaoklfcdhjniefkcji"; |
| 197 MimeTypesHandler::set_extension_whitelisted_for_test(&test_extension_id_); |
| 198 |
| 195 const extensions::Extension* extension = LoadExtension( | 199 const extensions::Extension* extension = LoadExtension( |
| 196 test_data_dir_.AppendASCII("file_browser/handle_mime_type")); | 200 test_data_dir_.AppendASCII("streams_private/handle_mime_type")); |
| 197 if (!extension) | 201 if (!extension) |
| 198 return NULL; | 202 return NULL; |
| 199 | 203 |
| 200 FileBrowserHandler::List* handlers = | 204 MimeTypesHandler* handler = MimeTypesHandler::GetHandler(extension); |
| 201 FileBrowserHandler::GetHandlers(extension); | 205 if (!handler) { |
| 202 if (!handlers || handlers->size() == 0u) { | 206 message_ = "No mime type handlers defined."; |
| 203 message_ = "No file browser handlers defined."; | |
| 204 return NULL; | 207 return NULL; |
| 205 } | 208 } |
| 206 | 209 |
| 207 test_extension_id_ = extension->id(); | 210 DCHECK_EQ(test_extension_id_, extension->id()); |
| 208 | |
| 209 FileBrowserHandler::set_extension_whitelisted_for_test(&test_extension_id_); | |
| 210 | |
| 211 // The MIME type filters cannot be defined directly in the extension's | |
| 212 // manifest because the extension installation would fail for the extension | |
| 213 // that is not white-listed to handle MIME types with its file browser | |
| 214 // handlers. | |
| 215 FileBrowserHandler* file_browser_handler = const_cast<FileBrowserHandler*>( | |
| 216 handlers->at(0).get()); | |
| 217 file_browser_handler->AddMIMEType("application/msword"); | |
| 218 file_browser_handler->AddMIMEType("plain/text"); | |
| 219 | 211 |
| 220 return extension; | 212 return extension; |
| 221 } | 213 } |
| 222 | 214 |
| 223 // Returns the download manager for the current browser. | 215 // Returns the download manager for the current browser. |
| 224 DownloadManager* GetDownloadManager() const { | 216 DownloadManager* GetDownloadManager() const { |
| 225 DownloadManager* download_manager = | 217 DownloadManager* download_manager = |
| 226 BrowserContext::GetDownloadManager(browser()->profile()); | 218 BrowserContext::GetDownloadManager(browser()->profile()); |
| 227 EXPECT_TRUE(download_manager); | 219 EXPECT_TRUE(download_manager); |
| 228 return download_manager; | 220 return download_manager; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 244 scoped_ptr<HttpServer> test_server_; | 236 scoped_ptr<HttpServer> test_server_; |
| 245 base::ScopedTempDir downloads_dir_; | 237 base::ScopedTempDir downloads_dir_; |
| 246 }; | 238 }; |
| 247 | 239 |
| 248 // http://crbug.com/176082: This test flaky on Chrome OS ASAN bots. | 240 // http://crbug.com/176082: This test flaky on Chrome OS ASAN bots. |
| 249 #if defined(OS_CHROMEOS) | 241 #if defined(OS_CHROMEOS) |
| 250 #define MAYBE_Basic DISABLED_Basic | 242 #define MAYBE_Basic DISABLED_Basic |
| 251 #else | 243 #else |
| 252 #define MAYBE_Basic Basic | 244 #define MAYBE_Basic Basic |
| 253 #endif | 245 #endif |
| 254 // Tests that invoking FileBrowserResourceThrottle with handleable MIME type | 246 // Tests that invoking StreamsResourceThrottle with handleable MIME type |
| 255 // actually invokes the fileBrowserHandler.onExecuteContnentHandler event. | 247 // actually invokes the mimeTypesHandler.onExecuteMimeTypeHandler event. |
| 256 IN_PROC_BROWSER_TEST_F(FileBrowserResourceThrottleExtensionApiTest, | 248 IN_PROC_BROWSER_TEST_F(StreamsResourceThrottleExtensionApiTest, |
| 257 MAYBE_Basic) { | 249 MAYBE_Basic) { |
| 258 ASSERT_TRUE(LoadTestExtension()) << message_; | 250 ASSERT_TRUE(LoadTestExtension()) << message_; |
| 259 | 251 |
| 260 ResultCatcher catcher; | 252 ResultCatcher catcher; |
| 261 | 253 |
| 262 MockResourceController mock_resource_controller; | 254 MockResourceController mock_resource_controller; |
| 263 EXPECT_CALL(mock_resource_controller, Cancel()).Times(0); | 255 EXPECT_CALL(mock_resource_controller, Cancel()).Times(0); |
| 264 EXPECT_CALL(mock_resource_controller, CancelAndIgnore()).Times(1); | 256 EXPECT_CALL(mock_resource_controller, CancelAndIgnore()).Times(1); |
| 265 EXPECT_CALL(mock_resource_controller, CancelWithError(_)).Times(0); | 257 EXPECT_CALL(mock_resource_controller, CancelWithError(_)).Times(0); |
| 266 EXPECT_CALL(mock_resource_controller, Resume()).Times(0); | 258 EXPECT_CALL(mock_resource_controller, Resume()).Times(0); |
| 267 | 259 |
| 268 // Get child and routing id from the current web contents (the real values | 260 // Get child and routing id from the current web contents (the real values |
| 269 // should be used so the FileBrowserHandlerEventRouter can correctly extract | 261 // should be used so the StreamsPrivateEventRouter can correctly extract |
| 270 // profile from them). | 262 // profile from them). |
| 271 WebContents* web_contents = | 263 WebContents* web_contents = |
| 272 browser()->tab_strip_model()->GetActiveWebContents(); | 264 browser()->tab_strip_model()->GetActiveWebContents(); |
| 273 ASSERT_TRUE(web_contents); | 265 ASSERT_TRUE(web_contents); |
| 274 int child_id = web_contents->GetRenderProcessHost()->GetID(); | 266 int child_id = web_contents->GetRenderProcessHost()->GetID(); |
| 275 int routing_id = web_contents->GetRoutingID(); | 267 int routing_id = web_contents->GetRoutingID(); |
| 276 | 268 |
| 277 scoped_refptr<ExtensionInfoMap> info_map = | 269 scoped_refptr<ExtensionInfoMap> info_map = |
| 278 extensions::ExtensionSystem::Get(browser()->profile())->info_map(); | 270 extensions::ExtensionSystem::Get(browser()->profile())->info_map(); |
| 279 | 271 |
| 280 // The resource throttle must be created and invoked on IO thread. | 272 // The resource throttle must be created and invoked on IO thread. |
| 281 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 273 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 282 base::Bind(&CreateAndTriggerThrottle, child_id, routing_id, | 274 base::Bind(&CreateAndTriggerThrottle, child_id, routing_id, |
| 283 "application/msword", GURL("http://foo"), false, info_map, | 275 "application/msword", GURL("http://foo"), false, info_map, |
| 284 &mock_resource_controller)); | 276 &mock_resource_controller)); |
| 285 | 277 |
| 286 // Wait for the test extension to received the onExecuteContentHandler event. | 278 // Wait for the test extension to received the onExecuteContentHandler event. |
| 287 EXPECT_TRUE(catcher.GetNextResult()); | 279 EXPECT_TRUE(catcher.GetNextResult()); |
| 288 } | 280 } |
| 289 | 281 |
| 290 // Tests that navigating to a resource with a MIME type handleable by an | 282 // Tests that navigating to a resource with a MIME type handleable by an |
| 291 // installed, white-listed extension invokes the extension's | 283 // installed, white-listed extension invokes the extension's |
| 292 // onExecuteContentHandler event (and does not start a download). | 284 // onExecuteContentHandler event (and does not start a download). |
| 293 IN_PROC_BROWSER_TEST_F(FileBrowserResourceThrottleExtensionApiTest, Navigate) { | 285 IN_PROC_BROWSER_TEST_F(StreamsResourceThrottleExtensionApiTest, Navigate) { |
| 294 ASSERT_TRUE(LoadTestExtension()) << message_; | 286 ASSERT_TRUE(LoadTestExtension()) << message_; |
| 295 | 287 |
| 296 ResultCatcher catcher; | 288 ResultCatcher catcher; |
| 297 | 289 |
| 298 ui_test_utils::NavigateToURL(browser(), | 290 ui_test_utils::NavigateToURL(browser(), |
| 299 test_server_->GetURL("/doc_path.doc")); | 291 test_server_->GetURL("/doc_path.doc")); |
| 300 | 292 |
| 301 // Wait for the response from the test server. | 293 // Wait for the response from the test server. |
| 302 MessageLoop::current()->RunUntilIdle(); | 294 MessageLoop::current()->RunUntilIdle(); |
| 303 | 295 |
| 304 // There should be no downloads started by the navigation. | 296 // There should be no downloads started by the navigation. |
| 305 DownloadManager* download_manager = GetDownloadManager(); | 297 DownloadManager* download_manager = GetDownloadManager(); |
| 306 std::vector<DownloadItem*> downloads; | 298 std::vector<DownloadItem*> downloads; |
| 307 download_manager->GetAllDownloads(&downloads); | 299 download_manager->GetAllDownloads(&downloads); |
| 308 ASSERT_EQ(0u, downloads.size()); | 300 ASSERT_EQ(0u, downloads.size()); |
| 309 | 301 |
| 310 // The test extension should receive onExecuteContentHandler event with MIME | 302 // The test extension should receive onExecuteContentHandler event with MIME |
| 311 // type 'application/msword' (and call chrome.test.notifySuccess). | 303 // type 'application/msword' (and call chrome.test.notifySuccess). |
| 312 EXPECT_TRUE(catcher.GetNextResult()); | 304 EXPECT_TRUE(catcher.GetNextResult()); |
| 313 } | 305 } |
| 314 | 306 |
| 315 // Tests that navigation to an attachment starts a download, even if there is an | 307 // Tests that navigation to an attachment starts a download, even if there is an |
| 316 // extension with a file browser handler that can handle the attachment's MIME | 308 // extension with a file browser handler that can handle the attachment's MIME |
| 317 // type. | 309 // type. |
| 318 IN_PROC_BROWSER_TEST_F(FileBrowserResourceThrottleExtensionApiTest, | 310 IN_PROC_BROWSER_TEST_F(StreamsResourceThrottleExtensionApiTest, |
| 319 NavigateToAnAttachment) { | 311 NavigateToAnAttachment) { |
| 320 InitializeDownloadSettings(); | 312 InitializeDownloadSettings(); |
| 321 | 313 |
| 322 ASSERT_TRUE(LoadTestExtension()) << message_; | 314 ASSERT_TRUE(LoadTestExtension()) << message_; |
| 323 | 315 |
| 324 ResultCatcher catcher; | 316 ResultCatcher catcher; |
| 325 | 317 |
| 326 // The test should start a downloadm. | 318 // The test should start a downloadm. |
| 327 DownloadManager* download_manager = GetDownloadManager(); | 319 DownloadManager* download_manager = GetDownloadManager(); |
| 328 scoped_ptr<content::DownloadTestObserver> download_observer( | 320 scoped_ptr<content::DownloadTestObserver> download_observer( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 345 // The test extension should not receive any events by now. Send it an event | 337 // The test extension should not receive any events by now. Send it an event |
| 346 // with MIME type "test/done", so it stops waiting for the events. (If there | 338 // with MIME type "test/done", so it stops waiting for the events. (If there |
| 347 // was an event with MIME type 'plain/text', |catcher.GetNextResult()| will | 339 // was an event with MIME type 'plain/text', |catcher.GetNextResult()| will |
| 348 // fail regardless of the sent event; chrome.test.notifySuccess will not be | 340 // fail regardless of the sent event; chrome.test.notifySuccess will not be |
| 349 // called by the extension). | 341 // called by the extension). |
| 350 SendDoneEvent(); | 342 SendDoneEvent(); |
| 351 EXPECT_TRUE(catcher.GetNextResult()); | 343 EXPECT_TRUE(catcher.GetNextResult()); |
| 352 } | 344 } |
| 353 | 345 |
| 354 // Tests that direct download requests don't get intercepted by | 346 // Tests that direct download requests don't get intercepted by |
| 355 // FileBrowserResourceThrottle, even if there is an extension with a file | 347 // StreamsResourceThrottle, even if there is an extension with a file |
| 356 // browser handler that can handle the download's MIME type. | 348 // browser handler that can handle the download's MIME type. |
| 357 IN_PROC_BROWSER_TEST_F(FileBrowserResourceThrottleExtensionApiTest, | 349 IN_PROC_BROWSER_TEST_F(StreamsResourceThrottleExtensionApiTest, |
| 358 DirectDownload) { | 350 DirectDownload) { |
| 359 InitializeDownloadSettings(); | 351 InitializeDownloadSettings(); |
| 360 | 352 |
| 361 ASSERT_TRUE(LoadTestExtension()) << message_; | 353 ASSERT_TRUE(LoadTestExtension()) << message_; |
| 362 | 354 |
| 363 ResultCatcher catcher; | 355 ResultCatcher catcher; |
| 364 | 356 |
| 365 DownloadManager* download_manager = GetDownloadManager(); | 357 DownloadManager* download_manager = GetDownloadManager(); |
| 366 scoped_ptr<content::DownloadTestObserver> download_observer( | 358 scoped_ptr<content::DownloadTestObserver> download_observer( |
| 367 new content::DownloadTestObserverInProgress(download_manager, 1)); | 359 new content::DownloadTestObserverInProgress(download_manager, 1)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 398 // The test extension should not receive any events by now. Send it an event | 390 // The test extension should not receive any events by now. Send it an event |
| 399 // with MIME type "test/done", so it stops waiting for the events. (If there | 391 // with MIME type "test/done", so it stops waiting for the events. (If there |
| 400 // was an event with MIME type 'plain/text', |catcher.GetNextResult()| will | 392 // was an event with MIME type 'plain/text', |catcher.GetNextResult()| will |
| 401 // fail regardless of the sent event; chrome.test.notifySuccess will not be | 393 // fail regardless of the sent event; chrome.test.notifySuccess will not be |
| 402 // called by the extension). | 394 // called by the extension). |
| 403 SendDoneEvent(); | 395 SendDoneEvent(); |
| 404 EXPECT_TRUE(catcher.GetNextResult()); | 396 EXPECT_TRUE(catcher.GetNextResult()); |
| 405 } | 397 } |
| 406 | 398 |
| 407 } // namespace | 399 } // namespace |
| OLD | NEW |