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

Side by Side Diff: chrome/common/extensions/api/extension_api_unittest.cc

Issue 12207167: Cleanup: Remove deprecated base::Value methods from chrome/common. Use base::Value too. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 "chrome/common/extensions/api/extension_api.h" 5 #include "chrome/common/extensions/api/extension_api.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 EXPECT_TRUE(apis->GetSchema("extension")); 186 EXPECT_TRUE(apis->GetSchema("extension"));
187 EXPECT_TRUE(apis->GetSchema("extension")); 187 EXPECT_TRUE(apis->GetSchema("extension"));
188 EXPECT_TRUE(apis->GetSchema("omnibox")); 188 EXPECT_TRUE(apis->GetSchema("omnibox"));
189 EXPECT_TRUE(apis->GetSchema("omnibox")); 189 EXPECT_TRUE(apis->GetSchema("omnibox"));
190 EXPECT_TRUE(apis->GetSchema("storage")); 190 EXPECT_TRUE(apis->GetSchema("storage"));
191 EXPECT_TRUE(apis->GetSchema("storage")); 191 EXPECT_TRUE(apis->GetSchema("storage"));
192 } 192 }
193 193
194 scoped_refptr<Extension> CreateExtensionWithPermissions( 194 scoped_refptr<Extension> CreateExtensionWithPermissions(
195 const std::set<std::string>& permissions) { 195 const std::set<std::string>& permissions) {
196 DictionaryValue manifest; 196 base::DictionaryValue manifest;
197 manifest.SetString("name", "extension"); 197 manifest.SetString("name", "extension");
198 manifest.SetString("version", "1.0"); 198 manifest.SetString("version", "1.0");
199 manifest.SetInteger("manifest_version", 2); 199 manifest.SetInteger("manifest_version", 2);
200 { 200 {
201 scoped_ptr<ListValue> permissions_list(new ListValue()); 201 scoped_ptr<base::ListValue> permissions_list(new base::ListValue());
202 for (std::set<std::string>::const_iterator i = permissions.begin(); 202 for (std::set<std::string>::const_iterator i = permissions.begin();
203 i != permissions.end(); ++i) { 203 i != permissions.end(); ++i) {
204 permissions_list->Append(Value::CreateStringValue(*i)); 204 permissions_list->Append(new base::StringValue(*i));
205 } 205 }
206 manifest.Set("permissions", permissions_list.release()); 206 manifest.Set("permissions", permissions_list.release());
207 } 207 }
208 208
209 std::string error; 209 std::string error;
210 scoped_refptr<Extension> extension(Extension::Create( 210 scoped_refptr<Extension> extension(Extension::Create(
211 base::FilePath(), Manifest::LOAD, manifest, Extension::NO_FLAGS, &error)); 211 base::FilePath(), Manifest::LOAD, manifest, Extension::NO_FLAGS, &error));
212 CHECK(extension.get()); 212 CHECK(extension.get());
213 CHECK(error.empty()); 213 CHECK(error.empty());
214 214
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 Feature::BLESSED_EXTENSION_CONTEXT)); 379 Feature::BLESSED_EXTENSION_CONTEXT));
380 380
381 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location()); 381 EXPECT_EQ(Feature::UNSPECIFIED_LOCATION, feature->location());
382 EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform()); 382 EXPECT_EQ(Feature::UNSPECIFIED_PLATFORM, feature->platform());
383 EXPECT_EQ(0, feature->min_manifest_version()); 383 EXPECT_EQ(0, feature->min_manifest_version());
384 EXPECT_EQ(0, feature->max_manifest_version()); 384 EXPECT_EQ(0, feature->max_manifest_version());
385 } 385 }
386 } 386 }
387 387
388 TEST(ExtensionAPI, FeaturesRequireContexts) { 388 TEST(ExtensionAPI, FeaturesRequireContexts) {
389 scoped_ptr<ListValue> schema1(new ListValue()); 389 scoped_ptr<base::ListValue> schema1(new base::ListValue());
390 DictionaryValue* feature_definition = new DictionaryValue(); 390 base::DictionaryValue* feature_definition = new base::DictionaryValue();
391 schema1->Append(feature_definition); 391 schema1->Append(feature_definition);
392 feature_definition->SetString("namespace", "test"); 392 feature_definition->SetString("namespace", "test");
393 feature_definition->SetBoolean("uses_feature_system", true); 393 feature_definition->SetBoolean("uses_feature_system", true);
394 394
395 scoped_ptr<ListValue> schema2(schema1->DeepCopy()); 395 scoped_ptr<base::ListValue> schema2(schema1->DeepCopy());
396 396
397 ListValue* contexts = new ListValue(); 397 base::ListValue* contexts = new base::ListValue();
398 contexts->Append(Value::CreateStringValue("content_script")); 398 contexts->Append(new base::StringValue("content_script"));
399 feature_definition->Set("contexts", contexts); 399 feature_definition->Set("contexts", contexts);
400 400
401 struct { 401 struct {
402 ListValue* schema; 402 base::ListValue* schema;
403 bool expect_success; 403 bool expect_success;
404 } test_data[] = { 404 } test_data[] = {
405 { schema1.get(), true }, 405 { schema1.get(), true },
406 { schema2.get(), false } 406 { schema2.get(), false }
407 }; 407 };
408 408
409 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) { 409 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_data); ++i) {
410 std::string schema_source; 410 std::string schema_source;
411 base::JSONWriter::Write(test_data[i].schema, &schema_source); 411 base::JSONWriter::Write(test_data[i].schema, &schema_source);
412 412
413 ExtensionAPI api; 413 ExtensionAPI api;
414 api.RegisterSchema("test", base::StringPiece(schema_source)); 414 api.RegisterSchema("test", base::StringPiece(schema_source));
415 api.LoadAllSchemas(); 415 api.LoadAllSchemas();
416 416
417 Feature* feature = api.GetFeature("test"); 417 Feature* feature = api.GetFeature("test");
418 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i; 418 EXPECT_EQ(test_data[i].expect_success, feature != NULL) << i;
419 } 419 }
420 } 420 }
421 421
422 static void GetDictionaryFromList(const DictionaryValue* schema, 422 static void GetDictionaryFromList(const base::DictionaryValue* schema,
423 const std::string& list_name, 423 const std::string& list_name,
424 const int list_index, 424 const int list_index,
425 const DictionaryValue** out) { 425 const base::DictionaryValue** out) {
426 const ListValue* list; 426 const base::ListValue* list;
427 EXPECT_TRUE(schema->GetList(list_name, &list)); 427 EXPECT_TRUE(schema->GetList(list_name, &list));
428 EXPECT_TRUE(list->GetDictionary(list_index, out)); 428 EXPECT_TRUE(list->GetDictionary(list_index, out));
429 } 429 }
430 430
431 TEST(ExtensionAPI, TypesHaveNamespace) { 431 TEST(ExtensionAPI, TypesHaveNamespace) {
432 base::FilePath manifest_path; 432 base::FilePath manifest_path;
433 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path); 433 PathService::Get(chrome::DIR_TEST_DATA, &manifest_path);
434 manifest_path = manifest_path.AppendASCII("extensions") 434 manifest_path = manifest_path.AppendASCII("extensions")
435 .AppendASCII("extension_api_unittest") 435 .AppendASCII("extension_api_unittest")
436 .AppendASCII("types_have_namespace.json"); 436 .AppendASCII("types_have_namespace.json");
437 437
438 std::string manifest_str; 438 std::string manifest_str;
439 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str)) 439 ASSERT_TRUE(file_util::ReadFileToString(manifest_path, &manifest_str))
440 << "Failed to load: " << manifest_path.value(); 440 << "Failed to load: " << manifest_path.value();
441 441
442 ExtensionAPI api; 442 ExtensionAPI api;
443 api.RegisterSchema("test.foo", manifest_str); 443 api.RegisterSchema("test.foo", manifest_str);
444 api.LoadAllSchemas(); 444 api.LoadAllSchemas();
445 445
446 const DictionaryValue* schema = api.GetSchema("test.foo"); 446 const base::DictionaryValue* schema = api.GetSchema("test.foo");
447 447
448 const DictionaryValue* dict; 448 const base::DictionaryValue* dict;
449 const DictionaryValue* sub_dict; 449 const base::DictionaryValue* sub_dict;
450 std::string type; 450 std::string type;
451 451
452 GetDictionaryFromList(schema, "types", 0, &dict); 452 GetDictionaryFromList(schema, "types", 0, &dict);
453 EXPECT_TRUE(dict->GetString("id", &type)); 453 EXPECT_TRUE(dict->GetString("id", &type));
454 EXPECT_EQ("test.foo.TestType", type); 454 EXPECT_EQ("test.foo.TestType", type);
455 EXPECT_TRUE(dict->GetString("customBindings", &type)); 455 EXPECT_TRUE(dict->GetString("customBindings", &type));
456 EXPECT_EQ("test.foo.TestType", type); 456 EXPECT_EQ("test.foo.TestType", type);
457 EXPECT_TRUE(dict->GetDictionary("properties", &sub_dict)); 457 EXPECT_TRUE(dict->GetDictionary("properties", &sub_dict));
458 const DictionaryValue* property; 458 const base::DictionaryValue* property;
459 EXPECT_TRUE(sub_dict->GetDictionary("foo", &property)); 459 EXPECT_TRUE(sub_dict->GetDictionary("foo", &property));
460 EXPECT_TRUE(property->GetString("$ref", &type)); 460 EXPECT_TRUE(property->GetString("$ref", &type));
461 EXPECT_EQ("test.foo.OtherType", type); 461 EXPECT_EQ("test.foo.OtherType", type);
462 EXPECT_TRUE(sub_dict->GetDictionary("bar", &property)); 462 EXPECT_TRUE(sub_dict->GetDictionary("bar", &property));
463 EXPECT_TRUE(property->GetString("$ref", &type)); 463 EXPECT_TRUE(property->GetString("$ref", &type));
464 EXPECT_EQ("fully.qualified.Type", type); 464 EXPECT_EQ("fully.qualified.Type", type);
465 465
466 GetDictionaryFromList(schema, "functions", 0, &dict); 466 GetDictionaryFromList(schema, "functions", 0, &dict);
467 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); 467 GetDictionaryFromList(dict, "parameters", 0, &sub_dict);
468 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); 468 EXPECT_TRUE(sub_dict->GetString("$ref", &type));
(...skipping 14 matching lines...) Expand all
483 GetDictionaryFromList(dict, "parameters", 0, &sub_dict); 483 GetDictionaryFromList(dict, "parameters", 0, &sub_dict);
484 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); 484 EXPECT_TRUE(sub_dict->GetString("$ref", &type));
485 EXPECT_EQ("test.foo.TestType", type); 485 EXPECT_EQ("test.foo.TestType", type);
486 GetDictionaryFromList(dict, "parameters", 1, &sub_dict); 486 GetDictionaryFromList(dict, "parameters", 1, &sub_dict);
487 EXPECT_TRUE(sub_dict->GetString("$ref", &type)); 487 EXPECT_TRUE(sub_dict->GetString("$ref", &type));
488 EXPECT_EQ("fully.qualified.Type", type); 488 EXPECT_EQ("fully.qualified.Type", type);
489 } 489 }
490 490
491 } // namespace 491 } // namespace
492 } // namespace extensions 492 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698