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 <map> | 5 #include <map> |
6 #include <queue> | 6 #include <queue> |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 scoped_refptr<net::HttpResponseHeaders> base_headers( | 1268 scoped_refptr<net::HttpResponseHeaders> base_headers( |
1269 new net::HttpResponseHeaders( | 1269 new net::HttpResponseHeaders( |
1270 net::HttpUtil::AssembleRawHeaders( | 1270 net::HttpUtil::AssembleRawHeaders( |
1271 base_headers_string, sizeof(base_headers_string)))); | 1271 base_headers_string, sizeof(base_headers_string)))); |
1272 | 1272 |
1273 ResponseHeaders new_headers; | 1273 ResponseHeaders new_headers; |
1274 new_headers.push_back(ResponseHeader("kEy1", "Value1")); // Unchanged | 1274 new_headers.push_back(ResponseHeader("kEy1", "Value1")); // Unchanged |
1275 new_headers.push_back(ResponseHeader("Key2", "Value1")); // Modified | 1275 new_headers.push_back(ResponseHeader("Key2", "Value1")); // Modified |
1276 // Key3 is deleted | 1276 // Key3 is deleted |
1277 new_headers.push_back(ResponseHeader("Key4", "Value4")); // Added | 1277 new_headers.push_back(ResponseHeader("Key4", "Value4")); // Added |
| 1278 GURL effective_new_url; |
1278 | 1279 |
1279 scoped_ptr<EventResponseDelta> delta(CalculateOnHeadersReceivedDelta( | 1280 scoped_ptr<EventResponseDelta> delta(CalculateOnHeadersReceivedDelta( |
1280 "extid", base::Time::Now(), cancel, base_headers.get(), &new_headers)); | 1281 "extid", base::Time::Now(), cancel, effective_new_url, |
| 1282 base_headers.get(), &new_headers)); |
1281 ASSERT_TRUE(delta.get()); | 1283 ASSERT_TRUE(delta.get()); |
1282 EXPECT_TRUE(delta->cancel); | 1284 EXPECT_TRUE(delta->cancel); |
1283 EXPECT_EQ(2u, delta->added_response_headers.size()); | 1285 EXPECT_EQ(2u, delta->added_response_headers.size()); |
1284 EXPECT_TRUE(Contains(delta->added_response_headers, | 1286 EXPECT_TRUE(Contains(delta->added_response_headers, |
1285 ResponseHeader("Key2", "Value1"))); | 1287 ResponseHeader("Key2", "Value1"))); |
1286 EXPECT_TRUE(Contains(delta->added_response_headers, | 1288 EXPECT_TRUE(Contains(delta->added_response_headers, |
1287 ResponseHeader("Key4", "Value4"))); | 1289 ResponseHeader("Key4", "Value4"))); |
1288 EXPECT_EQ(2u, delta->deleted_response_headers.size()); | 1290 EXPECT_EQ(2u, delta->deleted_response_headers.size()); |
1289 EXPECT_TRUE(Contains(delta->deleted_response_headers, | 1291 EXPECT_TRUE(Contains(delta->deleted_response_headers, |
1290 ResponseHeader("Key2", "Value2, Bar"))); | 1292 ResponseHeader("Key2", "Value2, Bar"))); |
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2056 std::string value; | 2058 std::string value; |
2057 std::multimap<std::string, std::string> actual1; | 2059 std::multimap<std::string, std::string> actual1; |
2058 while (new_headers1->EnumerateHeaderLines(&iter, &name, &value)) { | 2060 while (new_headers1->EnumerateHeaderLines(&iter, &name, &value)) { |
2059 actual1.insert(std::pair<std::string, std::string>(name, value)); | 2061 actual1.insert(std::pair<std::string, std::string>(name, value)); |
2060 } | 2062 } |
2061 EXPECT_EQ(expected1, actual1); | 2063 EXPECT_EQ(expected1, actual1); |
2062 EXPECT_EQ(0u, warning_set.size()); | 2064 EXPECT_EQ(0u, warning_set.size()); |
2063 EXPECT_EQ(1u, capturing_net_log.GetSize()); | 2065 EXPECT_EQ(1u, capturing_net_log.GetSize()); |
2064 } | 2066 } |
2065 | 2067 |
| 2068 // Tests whether onHeadersReceived can initiate a redirect. |
| 2069 // The URL merge logic is shared with onBeforeRequest, so we only need to test |
| 2070 // whether the URLs are merged at all. |
| 2071 TEST(ExtensionWebRequestHelpersTest, |
| 2072 TestMergeOnHeadersReceivedResponsesRedirect) { |
| 2073 EventResponseDeltas deltas; |
| 2074 net::CapturingBoundNetLog capturing_net_log; |
| 2075 net::BoundNetLog net_log = capturing_net_log.bound(); |
| 2076 ExtensionWarningSet warning_set; |
| 2077 GURL effective_new_url; |
| 2078 |
| 2079 // No redirect |
| 2080 linked_ptr<EventResponseDelta> d0( |
| 2081 new EventResponseDelta("extid0", base::Time::FromInternalValue(0))); |
| 2082 deltas.push_back(d0); |
| 2083 MergeOnBeforeRequestResponses( |
| 2084 deltas, &effective_new_url, &warning_set, &net_log); |
| 2085 EXPECT_TRUE(effective_new_url.is_empty()); |
| 2086 |
| 2087 // Single redirect. |
| 2088 GURL new_url_1("http://foo.com"); |
| 2089 linked_ptr<EventResponseDelta> d1( |
| 2090 new EventResponseDelta("extid1", base::Time::FromInternalValue(1000))); |
| 2091 d1->new_url = GURL(new_url_1); |
| 2092 deltas.push_back(d1); |
| 2093 deltas.sort(&InDecreasingExtensionInstallationTimeOrder); |
| 2094 capturing_net_log.Clear(); |
| 2095 MergeOnBeforeRequestResponses( |
| 2096 deltas, &effective_new_url, &warning_set, &net_log); |
| 2097 EXPECT_EQ(new_url_1, effective_new_url); |
| 2098 EXPECT_TRUE(warning_set.empty()); |
| 2099 EXPECT_EQ(1u, capturing_net_log.GetSize()); |
| 2100 } |
| 2101 |
2066 TEST(ExtensionWebRequestHelpersTest, TestMergeOnAuthRequiredResponses) { | 2102 TEST(ExtensionWebRequestHelpersTest, TestMergeOnAuthRequiredResponses) { |
2067 net::CapturingBoundNetLog capturing_net_log; | 2103 net::CapturingBoundNetLog capturing_net_log; |
2068 net::BoundNetLog net_log = capturing_net_log.bound(); | 2104 net::BoundNetLog net_log = capturing_net_log.bound(); |
2069 ExtensionWarningSet warning_set; | 2105 ExtensionWarningSet warning_set; |
2070 EventResponseDeltas deltas; | 2106 EventResponseDeltas deltas; |
2071 base::string16 username = base::ASCIIToUTF16("foo"); | 2107 base::string16 username = base::ASCIIToUTF16("foo"); |
2072 base::string16 password = base::ASCIIToUTF16("bar"); | 2108 base::string16 password = base::ASCIIToUTF16("bar"); |
2073 base::string16 password2 = base::ASCIIToUTF16("baz"); | 2109 base::string16 password2 = base::ASCIIToUTF16("baz"); |
2074 | 2110 |
2075 // Check that we can handle if not returning credentials. | 2111 // Check that we can handle if not returning credentials. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2136 EXPECT_TRUE(credentials_set); | 2172 EXPECT_TRUE(credentials_set); |
2137 EXPECT_FALSE(auth3.Empty()); | 2173 EXPECT_FALSE(auth3.Empty()); |
2138 EXPECT_EQ(username, auth1.username()); | 2174 EXPECT_EQ(username, auth1.username()); |
2139 EXPECT_EQ(password, auth1.password()); | 2175 EXPECT_EQ(password, auth1.password()); |
2140 EXPECT_EQ(1u, warning_set.size()); | 2176 EXPECT_EQ(1u, warning_set.size()); |
2141 EXPECT_TRUE(HasWarning(warning_set, "extid2")); | 2177 EXPECT_TRUE(HasWarning(warning_set, "extid2")); |
2142 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 2178 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
2143 } | 2179 } |
2144 | 2180 |
2145 } // namespace extensions | 2181 } // namespace extensions |
OLD | NEW |