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

Side by Side Diff: extensions/browser/api/declarative_webrequest/webrequest_condition_attribute_unittest.cc

Issue 2037703004: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « no previous file | extensions/browser/api/management/management_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_condition_att ribute.h" 5 #include "extensions/browser/api/declarative_webrequest/webrequest_condition_att ribute.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 TEST(WebRequestConditionAttributeTest, CreateConditionAttribute) { 44 TEST(WebRequestConditionAttributeTest, CreateConditionAttribute) {
45 // Necessary for TestURLRequest. 45 // Necessary for TestURLRequest.
46 base::MessageLoopForIO message_loop; 46 base::MessageLoopForIO message_loop;
47 47
48 std::string error; 48 std::string error;
49 scoped_refptr<const WebRequestConditionAttribute> result; 49 scoped_refptr<const WebRequestConditionAttribute> result;
50 base::StringValue string_value("main_frame"); 50 base::StringValue string_value("main_frame");
51 base::ListValue resource_types; 51 base::ListValue resource_types;
52 resource_types.Append(new base::StringValue("main_frame")); 52 resource_types.AppendString("main_frame");
53 53
54 // Test wrong condition name passed. 54 // Test wrong condition name passed.
55 error.clear(); 55 error.clear();
56 result = WebRequestConditionAttribute::Create( 56 result = WebRequestConditionAttribute::Create(
57 kUnknownConditionName, &resource_types, &error); 57 kUnknownConditionName, &resource_types, &error);
58 EXPECT_FALSE(error.empty()); 58 EXPECT_FALSE(error.empty());
59 EXPECT_FALSE(result.get()); 59 EXPECT_FALSE(result.get());
60 60
61 // Test wrong data type passed 61 // Test wrong data type passed
62 error.clear(); 62 error.clear();
(...skipping 20 matching lines...) Expand all
83 } 83 }
84 84
85 TEST(WebRequestConditionAttributeTest, ResourceType) { 85 TEST(WebRequestConditionAttributeTest, ResourceType) {
86 // Necessary for TestURLRequest. 86 // Necessary for TestURLRequest.
87 base::MessageLoopForIO message_loop; 87 base::MessageLoopForIO message_loop;
88 88
89 std::string error; 89 std::string error;
90 base::ListValue resource_types; 90 base::ListValue resource_types;
91 // The 'sub_frame' value is chosen arbitrarily, so as the corresponding 91 // The 'sub_frame' value is chosen arbitrarily, so as the corresponding
92 // content::ResourceType is not 0, the default value. 92 // content::ResourceType is not 0, the default value.
93 resource_types.Append(new base::StringValue("sub_frame")); 93 resource_types.AppendString("sub_frame");
94 94
95 scoped_refptr<const WebRequestConditionAttribute> attribute = 95 scoped_refptr<const WebRequestConditionAttribute> attribute =
96 WebRequestConditionAttribute::Create( 96 WebRequestConditionAttribute::Create(
97 keys::kResourceTypeKey, &resource_types, &error); 97 keys::kResourceTypeKey, &resource_types, &error);
98 EXPECT_EQ("", error); 98 EXPECT_EQ("", error);
99 ASSERT_TRUE(attribute.get()); 99 ASSERT_TRUE(attribute.get());
100 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName()); 100 EXPECT_EQ(std::string(keys::kResourceTypeKey), attribute->GetName());
101 101
102 net::TestURLRequestContext context; 102 net::TestURLRequestContext context;
103 std::unique_ptr<net::URLRequest> url_request_ok(context.CreateRequest( 103 std::unique_ptr<net::URLRequest> url_request_ok(context.CreateRequest(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 ASSERT_TRUE(test_server.Start()); 146 ASSERT_TRUE(test_server.Start());
147 147
148 net::TestURLRequestContext context; 148 net::TestURLRequestContext context;
149 net::TestDelegate delegate; 149 net::TestDelegate delegate;
150 std::unique_ptr<net::URLRequest> url_request(context.CreateRequest( 150 std::unique_ptr<net::URLRequest> url_request(context.CreateRequest(
151 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate)); 151 test_server.GetURL("/headers.html"), net::DEFAULT_PRIORITY, &delegate));
152 url_request->Start(); 152 url_request->Start();
153 base::MessageLoop::current()->Run(); 153 base::MessageLoop::current()->Run();
154 154
155 base::ListValue content_types; 155 base::ListValue content_types;
156 content_types.Append(new base::StringValue("text/plain")); 156 content_types.AppendString("text/plain");
157 scoped_refptr<const WebRequestConditionAttribute> attribute_include = 157 scoped_refptr<const WebRequestConditionAttribute> attribute_include =
158 WebRequestConditionAttribute::Create( 158 WebRequestConditionAttribute::Create(
159 keys::kContentTypeKey, &content_types, &error); 159 keys::kContentTypeKey, &content_types, &error);
160 EXPECT_EQ("", error); 160 EXPECT_EQ("", error);
161 ASSERT_TRUE(attribute_include.get()); 161 ASSERT_TRUE(attribute_include.get());
162 EXPECT_FALSE(attribute_include->IsFulfilled( 162 EXPECT_FALSE(attribute_include->IsFulfilled(
163 WebRequestData(url_request.get(), ON_BEFORE_REQUEST, 163 WebRequestData(url_request.get(), ON_BEFORE_REQUEST,
164 url_request->response_headers()))); 164 url_request->response_headers())));
165 EXPECT_TRUE(attribute_include->IsFulfilled( 165 EXPECT_TRUE(attribute_include->IsFulfilled(
166 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED, 166 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED,
167 url_request->response_headers()))); 167 url_request->response_headers())));
168 EXPECT_EQ(std::string(keys::kContentTypeKey), attribute_include->GetName()); 168 EXPECT_EQ(std::string(keys::kContentTypeKey), attribute_include->GetName());
169 169
170 scoped_refptr<const WebRequestConditionAttribute> attribute_exclude = 170 scoped_refptr<const WebRequestConditionAttribute> attribute_exclude =
171 WebRequestConditionAttribute::Create( 171 WebRequestConditionAttribute::Create(
172 keys::kExcludeContentTypeKey, &content_types, &error); 172 keys::kExcludeContentTypeKey, &content_types, &error);
173 EXPECT_EQ("", error); 173 EXPECT_EQ("", error);
174 ASSERT_TRUE(attribute_exclude.get()); 174 ASSERT_TRUE(attribute_exclude.get());
175 EXPECT_FALSE(attribute_exclude->IsFulfilled( 175 EXPECT_FALSE(attribute_exclude->IsFulfilled(
176 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED, 176 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED,
177 url_request->response_headers()))); 177 url_request->response_headers())));
178 178
179 content_types.Clear(); 179 content_types.Clear();
180 content_types.Append(new base::StringValue("something/invalid")); 180 content_types.AppendString("something/invalid");
181 scoped_refptr<const WebRequestConditionAttribute> attribute_unincluded = 181 scoped_refptr<const WebRequestConditionAttribute> attribute_unincluded =
182 WebRequestConditionAttribute::Create( 182 WebRequestConditionAttribute::Create(
183 keys::kContentTypeKey, &content_types, &error); 183 keys::kContentTypeKey, &content_types, &error);
184 EXPECT_EQ("", error); 184 EXPECT_EQ("", error);
185 ASSERT_TRUE(attribute_unincluded.get()); 185 ASSERT_TRUE(attribute_unincluded.get());
186 EXPECT_FALSE(attribute_unincluded->IsFulfilled( 186 EXPECT_FALSE(attribute_unincluded->IsFulfilled(
187 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED, 187 WebRequestData(url_request.get(), ON_HEADERS_RECEIVED,
188 url_request->response_headers()))); 188 url_request->response_headers())));
189 189
190 scoped_refptr<const WebRequestConditionAttribute> attribute_unexcluded = 190 scoped_refptr<const WebRequestConditionAttribute> attribute_unexcluded =
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 base::ListValue* list = NULL; 382 base::ListValue* list = NULL;
383 if (!dictionary->GetWithoutPathExpansion(*name, &entry)) 383 if (!dictionary->GetWithoutPathExpansion(*name, &entry))
384 return std::unique_ptr<base::DictionaryValue>(); 384 return std::unique_ptr<base::DictionaryValue>();
385 switch (entry->GetType()) { 385 switch (entry->GetType()) {
386 case base::Value::TYPE_STRING: 386 case base::Value::TYPE_STRING:
387 // Replace the present string with a list. 387 // Replace the present string with a list.
388 list = new base::ListValue; 388 list = new base::ListValue;
389 // Ignoring return value, we already verified the entry is there. 389 // Ignoring return value, we already verified the entry is there.
390 dictionary->RemoveWithoutPathExpansion(*name, &entry_owned); 390 dictionary->RemoveWithoutPathExpansion(*name, &entry_owned);
391 list->Append(entry_owned.release()); 391 list->Append(entry_owned.release());
392 list->Append(new base::StringValue(*value)); 392 list->AppendString(*value);
393 dictionary->SetWithoutPathExpansion(*name, list); 393 dictionary->SetWithoutPathExpansion(*name, list);
394 break; 394 break;
395 case base::Value::TYPE_LIST: // Just append to the list. 395 case base::Value::TYPE_LIST: // Just append to the list.
396 CHECK(entry->GetAsList(&list)); 396 CHECK(entry->GetAsList(&list));
397 list->Append(new base::StringValue(*value)); 397 list->AppendString(*value);
398 break; 398 break;
399 default: 399 default:
400 NOTREACHED(); // We never put other Values here. 400 NOTREACHED(); // We never put other Values here.
401 return std::unique_ptr<base::DictionaryValue>(); 401 return std::unique_ptr<base::DictionaryValue>();
402 } 402 }
403 } else { 403 } else {
404 dictionary->SetString(*name, *value); 404 dictionary->SetString(*name, *value);
405 } 405 }
406 } 406 }
407 return dictionary; 407 return dictionary;
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 }; 712 };
713 const size_t kExistingSize[] = { arraysize(kExisting) }; 713 const size_t kExistingSize[] = { arraysize(kExisting) };
714 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests); 714 GetArrayAsVector(kExisting, kExistingSize, 1u, &tests);
715 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage, 715 MatchAndCheck(tests, keys::kExcludeResponseHeadersKey, stage,
716 url_request.get(), &result); 716 url_request.get(), &result);
717 EXPECT_FALSE(result); 717 EXPECT_FALSE(result);
718 } 718 }
719 719
720 } // namespace 720 } // namespace
721 } // namespace extensions 721 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | extensions/browser/api/management/management_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698