Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry_unittest.cc

Issue 2806283002: Revert of Stop passing raw pointers to base::Value API in c/b/chromeos and c/b/extensions (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <utility>
12 #include <vector> 11 #include <vector>
13 12
14 #include "base/json/json_reader.h" 13 #include "base/json/json_reader.h"
15 #include "base/macros.h" 14 #include "base/macros.h"
16 #include "base/memory/linked_ptr.h" 15 #include "base/memory/linked_ptr.h"
17 #include "base/memory/ptr_util.h"
18 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
19 #include "base/run_loop.h" 17 #include "base/run_loop.h"
20 #include "base/stl_util.h" 18 #include "base/stl_util.h"
21 #include "base/test/values_test_util.h" 19 #include "base/test/values_test_util.h"
22 #include "base/values.h" 20 #include "base/values.h"
23 #include "chrome/common/extensions/extension_test_util.h" 21 #include "chrome/common/extensions/extension_test_util.h"
24 #include "components/url_matcher/url_matcher_constants.h" 22 #include "components/url_matcher/url_matcher_constants.h"
25 #include "content/public/test/test_browser_thread.h" 23 #include "content/public/test/test_browser_thread.h"
26 #include "extensions/browser/api/declarative/rules_registry_service.h" 24 #include "extensions/browser/api/declarative/rules_registry_service.h"
27 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 25 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 void SetUp() override; 94 void SetUp() override;
97 95
98 void TearDown() override { 96 void TearDown() override {
99 // Make sure that deletion traits of all registries are executed. 97 // Make sure that deletion traits of all registries are executed.
100 base::RunLoop().RunUntilIdle(); 98 base::RunLoop().RunUntilIdle();
101 } 99 }
102 100
103 // Returns a rule that roughly matches http://*.example.com and 101 // Returns a rule that roughly matches http://*.example.com and
104 // https://www.example.com and cancels it 102 // https://www.example.com and cancels it
105 linked_ptr<api::events::Rule> CreateRule1() { 103 linked_ptr<api::events::Rule> CreateRule1() {
106 auto scheme_http = base::MakeUnique<base::ListValue>(); 104 base::ListValue* scheme_http = new base::ListValue();
107 scheme_http->AppendString("http"); 105 scheme_http->AppendString("http");
108 auto http_condition_dict = base::MakeUnique<base::DictionaryValue>(); 106 base::DictionaryValue* http_condition_dict = new base::DictionaryValue();
107 http_condition_dict->Set(keys2::kSchemesKey, scheme_http);
109 http_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); 108 http_condition_dict->SetString(keys2::kHostSuffixKey, "example.com");
110 base::DictionaryValue http_condition_url_filter; 109 base::DictionaryValue http_condition_url_filter;
110 http_condition_url_filter.Set(keys::kUrlKey, http_condition_dict);
111 http_condition_url_filter.SetString(keys::kInstanceTypeKey, 111 http_condition_url_filter.SetString(keys::kInstanceTypeKey,
112 keys::kRequestMatcherType); 112 keys::kRequestMatcherType);
113 113
114 base::ListValue* scheme_https = new base::ListValue();
114 scheme_http->AppendString("https"); 115 scheme_http->AppendString("https");
115 auto https_condition_dict = base::MakeUnique<base::DictionaryValue>(); 116 base::DictionaryValue* https_condition_dict = new base::DictionaryValue();
116 https_condition_dict->Set(keys2::kSchemesKey, 117 https_condition_dict->Set(keys2::kSchemesKey, scheme_https);
117 base::MakeUnique<base::ListValue>());
118 https_condition_dict->SetString(keys2::kHostSuffixKey, "example.com"); 118 https_condition_dict->SetString(keys2::kHostSuffixKey, "example.com");
119 https_condition_dict->SetString(keys2::kHostPrefixKey, "www"); 119 https_condition_dict->SetString(keys2::kHostPrefixKey, "www");
120 base::DictionaryValue https_condition_url_filter; 120 base::DictionaryValue https_condition_url_filter;
121 https_condition_url_filter.Set(keys::kUrlKey, 121 https_condition_url_filter.Set(keys::kUrlKey, https_condition_dict);
122 std::move(https_condition_dict));
123 https_condition_url_filter.SetString(keys::kInstanceTypeKey, 122 https_condition_url_filter.SetString(keys::kInstanceTypeKey,
124 keys::kRequestMatcherType); 123 keys::kRequestMatcherType);
125 124
126 base::DictionaryValue action_dict; 125 base::DictionaryValue action_dict;
127 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType); 126 action_dict.SetString(keys::kInstanceTypeKey, keys::kCancelRequestType);
128 127
129 linked_ptr<api::events::Rule> rule(new api::events::Rule); 128 linked_ptr<api::events::Rule> rule(new api::events::Rule);
130 rule->id.reset(new std::string(kRuleId1)); 129 rule->id.reset(new std::string(kRuleId1));
131 rule->priority.reset(new int(100)); 130 rule->priority.reset(new int(100));
132 rule->actions.push_back(action_dict.CreateDeepCopy()); 131 rule->actions.push_back(action_dict.CreateDeepCopy());
133 http_condition_dict->Set(keys2::kSchemesKey, std::move(scheme_http));
134 http_condition_url_filter.Set(keys::kUrlKey,
135 std::move(http_condition_dict));
136 rule->conditions.push_back(http_condition_url_filter.CreateDeepCopy()); 132 rule->conditions.push_back(http_condition_url_filter.CreateDeepCopy());
137 rule->conditions.push_back(https_condition_url_filter.CreateDeepCopy()); 133 rule->conditions.push_back(https_condition_url_filter.CreateDeepCopy());
138 return rule; 134 return rule;
139 } 135 }
140 136
141 // Returns a rule that matches anything and cancels it. 137 // Returns a rule that matches anything and cancels it.
142 linked_ptr<api::events::Rule> CreateRule2() { 138 linked_ptr<api::events::Rule> CreateRule2() {
143 base::DictionaryValue condition_dict; 139 base::DictionaryValue condition_dict;
144 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 140 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
145 141
(...skipping 22 matching lines...) Expand all
168 rule->priority.reset(new int(100)); 164 rule->priority.reset(new int(100));
169 rule->actions.push_back(action_dict.CreateDeepCopy()); 165 rule->actions.push_back(action_dict.CreateDeepCopy());
170 rule->conditions.push_back(condition_dict.CreateDeepCopy()); 166 rule->conditions.push_back(condition_dict.CreateDeepCopy());
171 return rule; 167 return rule;
172 } 168 }
173 169
174 // Create a rule to ignore all other rules for a destination that 170 // Create a rule to ignore all other rules for a destination that
175 // contains index.html. 171 // contains index.html.
176 linked_ptr<api::events::Rule> CreateIgnoreRule() { 172 linked_ptr<api::events::Rule> CreateIgnoreRule() {
177 base::DictionaryValue condition_dict; 173 base::DictionaryValue condition_dict;
178 auto http_condition_dict = base::MakeUnique<base::DictionaryValue>(); 174 base::DictionaryValue* http_condition_dict = new base::DictionaryValue();
179 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html"); 175 http_condition_dict->SetString(keys2::kPathContainsKey, "index.html");
180 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType); 176 condition_dict.SetString(keys::kInstanceTypeKey, keys::kRequestMatcherType);
181 condition_dict.Set(keys::kUrlKey, std::move(http_condition_dict)); 177 condition_dict.Set(keys::kUrlKey, http_condition_dict);
182 178
183 base::DictionaryValue action_dict; 179 base::DictionaryValue action_dict;
184 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType); 180 action_dict.SetString(keys::kInstanceTypeKey, keys::kIgnoreRulesType);
185 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150); 181 action_dict.SetInteger(keys::kLowerPriorityThanKey, 150);
186 182
187 linked_ptr<api::events::Rule> rule(new api::events::Rule); 183 linked_ptr<api::events::Rule> rule(new api::events::Rule);
188 rule->id.reset(new std::string(kRuleId4)); 184 rule->id.reset(new std::string(kRuleId4));
189 rule->priority.reset(new int(200)); 185 rule->priority.reset(new int(200));
190 rule->actions.push_back(action_dict.CreateDeepCopy()); 186 rule->actions.push_back(action_dict.CreateDeepCopy());
191 rule->conditions.push_back(condition_dict.CreateDeepCopy()); 187 rule->conditions.push_back(condition_dict.CreateDeepCopy());
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 // This is a correct match. 813 // This is a correct match.
818 GURL url2("http://foo.com/index.html"); 814 GURL url2("http://foo.com/index.html");
819 std::unique_ptr<net::URLRequest> request2(context.CreateRequest( 815 std::unique_ptr<net::URLRequest> request2(context.CreateRequest(
820 url2, net::DEFAULT_PRIORITY, NULL, TRAFFIC_ANNOTATION_FOR_TESTS)); 816 url2, net::DEFAULT_PRIORITY, NULL, TRAFFIC_ANNOTATION_FOR_TESTS));
821 WebRequestData request_data2(request2.get(), ON_BEFORE_REQUEST); 817 WebRequestData request_data2(request2.get(), ON_BEFORE_REQUEST);
822 deltas = registry->CreateDeltas(NULL, request_data2, false); 818 deltas = registry->CreateDeltas(NULL, request_data2, false);
823 EXPECT_EQ(1u, deltas.size()); 819 EXPECT_EQ(1u, deltas.size());
824 } 820 }
825 821
826 } // namespace extensions 822 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/debugger/debugger_api.cc ('k') | chrome/browser/extensions/api/downloads/downloads_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698