| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <queue> | 5 #include <queue> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 | 9 |
| 10 #include "chrome/browser/extensions/extension_event_router_forwarder.h" | 10 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Tests that we handle disagreements among extensions about responses to | 102 // Tests that we handle disagreements among extensions about responses to |
| 103 // blocking events (redirection) by choosing the response from the | 103 // blocking events (redirection) by choosing the response from the |
| 104 // most-recently-installed extension. | 104 // most-recently-installed extension. |
| 105 TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) { | 105 TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) { |
| 106 std::string extension1_id("1"); | 106 std::string extension1_id("1"); |
| 107 std::string extension2_id("2"); | 107 std::string extension2_id("2"); |
| 108 ExtensionWebRequestEventRouter::RequestFilter filter; | 108 ExtensionWebRequestEventRouter::RequestFilter filter; |
| 109 const std::string kEventName(keys::kOnBeforeRequest); | 109 const std::string kEventName(keys::kOnBeforeRequest); |
| 110 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); | 110 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); |
| 111 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 111 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 112 &profile_, extension1_id, kEventName, kEventName + "/1", filter, | 112 &profile_, extension1_id, extension1_id, kEventName, kEventName + "/1", |
| 113 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, | 113 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, |
| 114 ipc_sender_factory.GetWeakPtr()); | 114 ipc_sender_factory.GetWeakPtr()); |
| 115 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 115 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 116 &profile_, extension2_id, kEventName, kEventName + "/2", filter, | 116 &profile_, extension2_id, extension2_id, kEventName, kEventName + "/2", |
| 117 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, | 117 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, |
| 118 ipc_sender_factory.GetWeakPtr()); | 118 ipc_sender_factory.GetWeakPtr()); |
| 119 | 119 |
| 120 GURL redirect_url("about:redirected"); | 120 GURL redirect_url("about:redirected"); |
| 121 GURL not_chosen_redirect_url("about:not_chosen"); | 121 GURL not_chosen_redirect_url("about:not_chosen"); |
| 122 | 122 |
| 123 net::URLRequest request(GURL("about:blank"), &delegate_); | 123 net::URLRequest request(GURL("about:blank"), &delegate_); |
| 124 request.set_context(context_); | 124 request.set_context(context_); |
| 125 { | 125 { |
| 126 // onBeforeRequest will be dispatched twice initially. The second response - | 126 // onBeforeRequest will be dispatched twice initially. The second response - |
| 127 // the redirect - should win, since it has a later |install_time|. The | 127 // the redirect - should win, since it has a later |install_time|. The |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 | 233 |
| 234 // Test that a request is canceled if this is requested by any extension | 234 // Test that a request is canceled if this is requested by any extension |
| 235 // regardless whether it is the extension with the highest precedence. | 235 // regardless whether it is the extension with the highest precedence. |
| 236 TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceCancel) { | 236 TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceCancel) { |
| 237 std::string extension1_id("1"); | 237 std::string extension1_id("1"); |
| 238 std::string extension2_id("2"); | 238 std::string extension2_id("2"); |
| 239 ExtensionWebRequestEventRouter::RequestFilter filter; | 239 ExtensionWebRequestEventRouter::RequestFilter filter; |
| 240 const std::string kEventName(keys::kOnBeforeRequest); | 240 const std::string kEventName(keys::kOnBeforeRequest); |
| 241 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); | 241 base::WeakPtrFactory<TestIPCSender> ipc_sender_factory(&ipc_sender_); |
| 242 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 242 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 243 &profile_, extension1_id, kEventName, kEventName + "/1", filter, | 243 &profile_, extension1_id, extension1_id, kEventName, kEventName + "/1", |
| 244 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, | 244 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, |
| 245 ipc_sender_factory.GetWeakPtr()); | 245 ipc_sender_factory.GetWeakPtr()); |
| 246 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( | 246 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( |
| 247 &profile_, extension2_id, kEventName, kEventName + "/2", filter, | 247 &profile_, extension2_id, extension2_id, kEventName, kEventName + "/2", |
| 248 ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, | 248 filter, ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING, |
| 249 ipc_sender_factory.GetWeakPtr()); | 249 ipc_sender_factory.GetWeakPtr()); |
| 250 | 250 |
| 251 GURL request_url("about:blank"); | 251 GURL request_url("about:blank"); |
| 252 net::URLRequest request(request_url, &delegate_); | 252 net::URLRequest request(request_url, &delegate_); |
| 253 request.set_context(context_); | 253 request.set_context(context_); |
| 254 | 254 |
| 255 // onBeforeRequest will be dispatched twice. The second response - | 255 // onBeforeRequest will be dispatched twice. The second response - |
| 256 // the redirect - would win, since it has a later |install_time|, but | 256 // the redirect - would win, since it has a later |install_time|, but |
| 257 // the first response takes precedence because cancel >> redirect. | 257 // the first response takes precedence because cancel >> redirect. |
| 258 GURL redirect_url("about:redirected"); | 258 GURL redirect_url("about:redirected"); |
| 259 ExtensionWebRequestEventRouter::EventResponse* response = NULL; | 259 ExtensionWebRequestEventRouter::EventResponse* response = NULL; |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 {"header2", "bar"} } | 642 {"header2", "bar"} } |
| 643 }, | 643 }, |
| 644 }; | 644 }; |
| 645 | 645 |
| 646 INSTANTIATE_TEST_CASE_P( | 646 INSTANTIATE_TEST_CASE_P( |
| 647 ExtensionWebRequest, | 647 ExtensionWebRequest, |
| 648 ExtensionWebRequestHeaderModificationTest, | 648 ExtensionWebRequestHeaderModificationTest, |
| 649 ::testing::ValuesIn(kTests)); | 649 ::testing::ValuesIn(kTests)); |
| 650 | 650 |
| 651 } // namespace | 651 } // namespace |
| OLD | NEW |