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 "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" | 5 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
jdoerrie
2017/04/06 14:25:50
#include <utility>
vabr (Chromium)
2017/04/07 20:40:40
Done.
| |
12 | 12 |
13 #include "base/json/json_reader.h" | 13 #include "base/json/json_reader.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/linked_ptr.h" | 15 #include "base/memory/linked_ptr.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
jdoerrie
2017/04/06 14:25:50
#include "base/memory/ptr_util.h"
vabr (Chromium)
2017/04/07 20:40:40
Done.
| |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
19 #include "base/test/values_test_util.h" | 19 #include "base/test/values_test_util.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/common/extensions/extension_test_util.h" | 21 #include "chrome/common/extensions/extension_test_util.h" |
22 #include "components/url_matcher/url_matcher_constants.h" | 22 #include "components/url_matcher/url_matcher_constants.h" |
23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
24 #include "extensions/browser/api/declarative/rules_registry_service.h" | 24 #include "extensions/browser/api/declarative/rules_registry_service.h" |
25 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 25 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
26 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 26 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 void SetUp() override; | 93 void SetUp() override; |
94 | 94 |
95 void TearDown() override { | 95 void TearDown() override { |
96 // Make sure that deletion traits of all registries are executed. | 96 // Make sure that deletion traits of all registries are executed. |
97 base::RunLoop().RunUntilIdle(); | 97 base::RunLoop().RunUntilIdle(); |
98 } | 98 } |
99 | 99 |
100 // Returns a rule that roughly matches http://*.example.com and | 100 // Returns a rule that roughly matches http://*.example.com and |
101 // https://www.example.com and cancels it | 101 // https://www.example.com and cancels it |
102 linked_ptr<api::events::Rule> CreateRule1() { | 102 linked_ptr<api::events::Rule> CreateRule1() { |
103 base::ListValue* scheme_http = new base::ListValue(); | 103 auto scheme_http = base::MakeUnique<base::ListValue>(); |
104 scheme_http->AppendString("http"); | 104 scheme_http->AppendString("http"); |
105 base::DictionaryValue* http_condition_dict = new base::DictionaryValue(); | 105 auto http_condition_dict = base::MakeUnique<base::DictionaryValue>(); |
106 http_condition_dict->Set(keys2::kSchemesKey, scheme_http); | |
107 http_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); | 106 http_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); |
108 base::DictionaryValue http_condition_url_filter; | 107 base::DictionaryValue http_condition_url_filter; |
109 http_condition_url_filter.Set(keys::kUrlKey, http_condition_dict); | |
110 http_condition_url_filter.SetString(keys::kInstanceTypeKey, | 108 http_condition_url_filter.SetString(keys::kInstanceTypeKey, |
111 keys::kRequestMatcherType); | 109 keys::kRequestMatcherType); |
112 | 110 |
113 base::ListValue* scheme_https = new base::ListValue(); | 111 auto scheme_https = base::MakeUnique<base::ListValue>(); |
jdoerrie
2017/04/06 14:25:50
Inline variable? This seems unused otherwise.
vabr (Chromium)
2017/04/07 20:40:40
Done.
| |
114 scheme_http->AppendString("https"); | 112 scheme_http->AppendString("https"); |
115 base::DictionaryValue* https_condition_dict = new base::DictionaryValue(); | 113 auto https_condition_dict = base::MakeUnique<base::DictionaryValue>(); |
116 https_condition_dict->Set(keys2::kSchemesKey, scheme_https); | 114 https_condition_dict->Set(keys2::kSchemesKey, std::move(scheme_https)); |
117 https_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); | 115 https_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); |
118 https_condition_dict->SetString(keys2::kHostPrefixKey, "www"); | 116 https_condition_dict->SetString(keys2::kHostPrefixKey, "www"); |
119 base::DictionaryValue https_condition_url_filter; | 117 base::DictionaryValue https_condition_url_filter; |
120 https_condition_url_filter.Set(keys::kUrlKey, https_condition_dict); | 118 https_condition_url_filter.Set(keys::kUrlKey, |
119 std::move(https_condition_dict)); | |
121 https_condition_url_filter.SetString(keys::kInstanceTypeKey, | 120 https_condition_url_filter.SetString(keys::kInstanceTypeKey, |
122 keys::kRequestMatcherType); | 121 keys::kRequestMatcherType); |
123 | 122 |
124 base::DictionaryValue action_dict; | 123 base::DictionaryValue action_dict; |
125 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); | 124 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); |
126 | 125 |
127 linked_ptr<api::events::Rule> rule(new api::events::Rule); | 126 linked_ptr<api::events::Rule> rule(new api::events::Rule); |
128 rule->id.reset(new std::string(kRuleId1)); | 127 rule->id.reset(new std::string(kRuleId1)); |
129 rule->priority.reset(new int(100)); | 128 rule->priority.reset(new int(100)); |
130 rule->actions.push_back(action_dict.CreateDeepCopy()); | 129 rule->actions.push_back(action_dict.CreateDeepCopy()); |
130 http_condition_dict->Set(keys2::kSchemesKey, std::move(scheme_http)); | |
131 http_condition_url_filter.Set(keys::kUrlKey, | |
132 std::move(http_condition_dict)); | |
131 rule->conditions.push_back(http_condition_url_filter.CreateDeepCopy()); | 133 rule->conditions.push_back(http_condition_url_filter.CreateDeepCopy()); |
132 rule->conditions.push_back(https_condition_url_filter.CreateDeepCopy()); | 134 rule->conditions.push_back(https_condition_url_filter.CreateDeepCopy()); |
133 return rule; | 135 return rule; |
134 } | 136 } |
135 | 137 |
136 // Returns a rule that matches anything and cancels it. | 138 // Returns a rule that matches anything and cancels it. |
137 linked_ptr<api::events::Rule> CreateRule2() { | 139 linked_ptr<api::events::Rule> CreateRule2() { |
138 base::DictionaryValue condition_dict; | 140 base::DictionaryValue condition_dict; |
139 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); | 141 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); |
140 | 142 |
(...skipping 22 matching lines...) Expand all Loading... | |
163 rule->priority.reset(new int(100)); | 165 rule->priority.reset(new int(100)); |
164 rule->actions.push_back(action_dict.CreateDeepCopy()); | 166 rule->actions.push_back(action_dict.CreateDeepCopy()); |
165 rule->conditions.push_back(condition_dict.CreateDeepCopy()); | 167 rule->conditions.push_back(condition_dict.CreateDeepCopy()); |
166 return rule; | 168 return rule; |
167 } | 169 } |
168 | 170 |
169 // Create a rule to ignore all other rules for a destination that | 171 // Create a rule to ignore all other rules for a destination that |
170 // contains index.html. | 172 // contains index.html. |
171 linked_ptr<api::events::Rule> CreateIgnoreRule() { | 173 linked_ptr<api::events::Rule> CreateIgnoreRule() { |
172 base::DictionaryValue condition_dict; | 174 base::DictionaryValue condition_dict; |
173 base::DictionaryValue* http_condition_dict = new base::DictionaryValue(); | 175 auto http_condition_dict = base::MakeUnique<base::DictionaryValue>(); |
174 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html"); | 176 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html"); |
175 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); | 177 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); |
176 condition_dict.Set(keys::kUrlKey, http_condition_dict); | 178 condition_dict.Set(keys::kUrlKey, std::move(http_condition_dict)); |
177 | 179 |
178 base::DictionaryValue action_dict; | 180 base::DictionaryValue action_dict; |
179 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); | 181 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); |
180 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150); | 182 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150); |
181 | 183 |
182 linked_ptr<api::events::Rule> rule(new api::events::Rule); | 184 linked_ptr<api::events::Rule> rule(new api::events::Rule); |
183 rule->id.reset(new std::string(kRuleId4)); | 185 rule->id.reset(new std::string(kRuleId4)); |
184 rule->priority.reset(new int(200)); | 186 rule->priority.reset(new int(200)); |
185 rule->actions.push_back(action_dict.CreateDeepCopy()); | 187 rule->actions.push_back(action_dict.CreateDeepCopy()); |
186 rule->conditions.push_back(condition_dict.CreateDeepCopy()); | 188 rule->conditions.push_back(condition_dict.CreateDeepCopy()); |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
812 // This is a correct match. | 814 // This is a correct match. |
813 GURL url2("http://foo.com/index.html"); | 815 GURL url2("http://foo.com/index.html"); |
814 std::unique_ptr<net::URLRequest> request2( | 816 std::unique_ptr<net::URLRequest> request2( |
815 context.CreateRequest(url2, net::DEFAULT_PRIORITY, NULL)); | 817 context.CreateRequest(url2, net::DEFAULT_PRIORITY, NULL)); |
816 WebRequestData request_data2(request2.get(), ON_BEFORE_REQUEST); | 818 WebRequestData request_data2(request2.get(), ON_BEFORE_REQUEST); |
817 deltas = registry->CreateDeltas(NULL, request_data2, false); | 819 deltas = registry->CreateDeltas(NULL, request_data2, false); |
818 EXPECT_EQ(1u, deltas.size()); | 820 EXPECT_EQ(1u, deltas.size()); |
819 } | 821 } |
820 | 822 |
821 } // namespace extensions | 823 } // namespace extensions |
OLD | NEW |