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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <queue> | 10 #include <queue> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 const std::string& extension_id, | 102 const std::string& extension_id, |
103 const std::string& event_name, | 103 const std::string& event_name, |
104 const std::string& sub_event_name, | 104 const std::string& sub_event_name, |
105 uint64_t request_id, | 105 uint64_t request_id, |
106 ExtensionWebRequestEventRouter::EventResponse* response) { | 106 ExtensionWebRequestEventRouter::EventResponse* response) { |
107 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( | 107 ExtensionWebRequestEventRouter::GetInstance()->OnEventHandled( |
108 profile, extension_id, event_name, sub_event_name, request_id, | 108 profile, extension_id, event_name, sub_event_name, request_id, |
109 response); | 109 response); |
110 } | 110 } |
111 | 111 |
112 // Searches |key| in |collection| by iterating over its elements and returns | |
113 // true if found. | |
114 template <typename Collection, typename Key> | |
115 bool Contains(const Collection& collection, const Key& key) { | |
116 return std::find(collection.begin(), collection.end(), key) != | |
117 collection.end(); | |
118 } | |
119 | |
120 // Returns whether |warnings| contains an extension for |extension_id|. | 112 // Returns whether |warnings| contains an extension for |extension_id|. |
121 bool HasWarning(const WarningSet& warnings, | 113 bool HasWarning(const WarningSet& warnings, |
122 const std::string& extension_id) { | 114 const std::string& extension_id) { |
123 for (WarningSet::const_iterator i = warnings.begin(); | 115 for (WarningSet::const_iterator i = warnings.begin(); |
124 i != warnings.end(); ++i) { | 116 i != warnings.end(); ++i) { |
125 if (i->extension_id() == extension_id) | 117 if (i->extension_id() == extension_id) |
126 return true; | 118 return true; |
127 } | 119 } |
128 return false; | 120 return false; |
129 } | 121 } |
(...skipping 1376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1506 new_headers.push_back(ResponseHeader("Key4", "Value4")); // Added | 1498 new_headers.push_back(ResponseHeader("Key4", "Value4")); // Added |
1507 new_headers.push_back(ResponseHeader("Key5", "Value5, end5")); // Unchanged | 1499 new_headers.push_back(ResponseHeader("Key5", "Value5, end5")); // Unchanged |
1508 GURL effective_new_url; | 1500 GURL effective_new_url; |
1509 | 1501 |
1510 std::unique_ptr<EventResponseDelta> delta(CalculateOnHeadersReceivedDelta( | 1502 std::unique_ptr<EventResponseDelta> delta(CalculateOnHeadersReceivedDelta( |
1511 "extid", base::Time::Now(), cancel, effective_new_url, base_headers.get(), | 1503 "extid", base::Time::Now(), cancel, effective_new_url, base_headers.get(), |
1512 &new_headers)); | 1504 &new_headers)); |
1513 ASSERT_TRUE(delta.get()); | 1505 ASSERT_TRUE(delta.get()); |
1514 EXPECT_TRUE(delta->cancel); | 1506 EXPECT_TRUE(delta->cancel); |
1515 EXPECT_EQ(2u, delta->added_response_headers.size()); | 1507 EXPECT_EQ(2u, delta->added_response_headers.size()); |
1516 EXPECT_TRUE(Contains(delta->added_response_headers, | 1508 EXPECT_TRUE(base::ContainsValue(delta->added_response_headers, |
1517 ResponseHeader("Key2", "Value1"))); | 1509 ResponseHeader("Key2", "Value1"))); |
1518 EXPECT_TRUE(Contains(delta->added_response_headers, | 1510 EXPECT_TRUE(base::ContainsValue(delta->added_response_headers, |
1519 ResponseHeader("Key4", "Value4"))); | 1511 ResponseHeader("Key4", "Value4"))); |
1520 EXPECT_EQ(2u, delta->deleted_response_headers.size()); | 1512 EXPECT_EQ(2u, delta->deleted_response_headers.size()); |
1521 EXPECT_TRUE(Contains(delta->deleted_response_headers, | 1513 EXPECT_TRUE(base::ContainsValue(delta->deleted_response_headers, |
1522 ResponseHeader("Key2", "Value2, Bar"))); | 1514 ResponseHeader("Key2", "Value2, Bar"))); |
1523 EXPECT_TRUE(Contains(delta->deleted_response_headers, | 1515 EXPECT_TRUE(base::ContainsValue(delta->deleted_response_headers, |
1524 ResponseHeader("Key3", "Value3"))); | 1516 ResponseHeader("Key3", "Value3"))); |
1525 } | 1517 } |
1526 | 1518 |
1527 TEST(ExtensionWebRequestHelpersTest, TestCalculateOnAuthRequiredDelta) { | 1519 TEST(ExtensionWebRequestHelpersTest, TestCalculateOnAuthRequiredDelta) { |
1528 const bool cancel = true; | 1520 const bool cancel = true; |
1529 | 1521 |
1530 base::string16 username = base::ASCIIToUTF16("foo"); | 1522 base::string16 username = base::ASCIIToUTF16("foo"); |
1531 base::string16 password = base::ASCIIToUTF16("bar"); | 1523 base::string16 password = base::ASCIIToUTF16("bar"); |
1532 std::unique_ptr<net::AuthCredentials> credentials( | 1524 std::unique_ptr<net::AuthCredentials> credentials( |
1533 new net::AuthCredentials(username, password)); | 1525 new net::AuthCredentials(username, password)); |
1534 | 1526 |
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2482 EXPECT_TRUE(credentials_set); | 2474 EXPECT_TRUE(credentials_set); |
2483 EXPECT_FALSE(auth3.Empty()); | 2475 EXPECT_FALSE(auth3.Empty()); |
2484 EXPECT_EQ(username, auth1.username()); | 2476 EXPECT_EQ(username, auth1.username()); |
2485 EXPECT_EQ(password, auth1.password()); | 2477 EXPECT_EQ(password, auth1.password()); |
2486 EXPECT_EQ(1u, warning_set.size()); | 2478 EXPECT_EQ(1u, warning_set.size()); |
2487 EXPECT_TRUE(HasWarning(warning_set, "extid2")); | 2479 EXPECT_TRUE(HasWarning(warning_set, "extid2")); |
2488 EXPECT_EQ(3u, capturing_net_log.GetSize()); | 2480 EXPECT_EQ(3u, capturing_net_log.GetSize()); |
2489 } | 2481 } |
2490 | 2482 |
2491 } // namespace extensions | 2483 } // namespace extensions |
OLD | NEW |