| 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 "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_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 22 #include "chrome/common/extensions/extension_test_util.h" | 21 #include "chrome/common/extensions/extension_test_util.h" |
| 23 #include "chrome/common/extensions/features/api_feature.h" | 22 #include "chrome/common/extensions/features/api_feature.h" |
| 24 #include "chrome/common/extensions/features/base_feature_provider.h" | 23 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 25 #include "chrome/common/extensions/features/simple_feature.h" | 24 #include "chrome/common/extensions/features/simple_feature.h" |
| 26 #include "chrome/common/extensions/manifest.h" | 25 #include "chrome/common/extensions/manifest.h" |
| 26 #include "extensions/common/manifest_constants.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 namespace extensions { | 29 namespace extensions { |
| 30 | 30 |
| 31 using extension_test_util::BuildExtension; | 31 using extension_test_util::BuildExtension; |
| 32 | 32 |
| 33 SimpleFeature* CreateAPIFeature() { | 33 SimpleFeature* CreateAPIFeature() { |
| 34 return new APIFeature(); | 34 return new APIFeature(); |
| 35 } | 35 } |
| 36 | 36 |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 Feature::UNBLESSED_EXTENSION_CONTEXT, | 425 Feature::UNBLESSED_EXTENSION_CONTEXT, |
| 426 GURL())); | 426 GURL())); |
| 427 EXPECT_FALSE(extension_api->IsAnyFeatureAvailableToContext( | 427 EXPECT_FALSE(extension_api->IsAnyFeatureAvailableToContext( |
| 428 "history", | 428 "history", |
| 429 Feature::CONTENT_SCRIPT_CONTEXT, | 429 Feature::CONTENT_SCRIPT_CONTEXT, |
| 430 GURL())); | 430 GURL())); |
| 431 } | 431 } |
| 432 | 432 |
| 433 scoped_refptr<Extension> CreateHostedApp() { | 433 scoped_refptr<Extension> CreateHostedApp() { |
| 434 base::DictionaryValue values; | 434 base::DictionaryValue values; |
| 435 values.SetString(extension_manifest_keys::kName, "test"); | 435 values.SetString(manifest_keys::kName, "test"); |
| 436 values.SetString(extension_manifest_keys::kVersion, "0.1"); | 436 values.SetString(manifest_keys::kVersion, "0.1"); |
| 437 values.Set(extension_manifest_keys::kWebURLs, new base::ListValue()); | 437 values.Set(manifest_keys::kWebURLs, new base::ListValue()); |
| 438 values.SetString(extension_manifest_keys::kLaunchWebURL, | 438 values.SetString(manifest_keys::kLaunchWebURL, |
| 439 "http://www.example.com"); | 439 "http://www.example.com"); |
| 440 std::string error; | 440 std::string error; |
| 441 scoped_refptr<Extension> extension(Extension::Create( | 441 scoped_refptr<Extension> extension(Extension::Create( |
| 442 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, | 442 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, |
| 443 &error)); | 443 &error)); |
| 444 CHECK(extension.get()); | 444 CHECK(extension.get()); |
| 445 return extension; | 445 return extension; |
| 446 } | 446 } |
| 447 | 447 |
| 448 scoped_refptr<Extension> CreatePackagedAppWithPermissions( | 448 scoped_refptr<Extension> CreatePackagedAppWithPermissions( |
| 449 const std::set<std::string>& permissions) { | 449 const std::set<std::string>& permissions) { |
| 450 base::DictionaryValue values; | 450 base::DictionaryValue values; |
| 451 values.SetString(extension_manifest_keys::kName, "test"); | 451 values.SetString(manifest_keys::kName, "test"); |
| 452 values.SetString(extension_manifest_keys::kVersion, "0.1"); | 452 values.SetString(manifest_keys::kVersion, "0.1"); |
| 453 values.SetString(extension_manifest_keys::kPlatformAppBackground, | 453 values.SetString(manifest_keys::kPlatformAppBackground, |
| 454 "http://www.example.com"); | 454 "http://www.example.com"); |
| 455 | 455 |
| 456 base::DictionaryValue* app = new base::DictionaryValue(); | 456 base::DictionaryValue* app = new base::DictionaryValue(); |
| 457 base::DictionaryValue* background = new base::DictionaryValue(); | 457 base::DictionaryValue* background = new base::DictionaryValue(); |
| 458 base::ListValue* scripts = new base::ListValue(); | 458 base::ListValue* scripts = new base::ListValue(); |
| 459 scripts->Append(new base::StringValue("test.js")); | 459 scripts->Append(new base::StringValue("test.js")); |
| 460 background->Set("scripts", scripts); | 460 background->Set("scripts", scripts); |
| 461 app->Set("background", background); | 461 app->Set("background", background); |
| 462 values.Set(extension_manifest_keys::kApp, app); | 462 values.Set(manifest_keys::kApp, app); |
| 463 { | 463 { |
| 464 scoped_ptr<base::ListValue> permissions_list(new base::ListValue()); | 464 scoped_ptr<base::ListValue> permissions_list(new base::ListValue()); |
| 465 for (std::set<std::string>::const_iterator i = permissions.begin(); | 465 for (std::set<std::string>::const_iterator i = permissions.begin(); |
| 466 i != permissions.end(); ++i) { | 466 i != permissions.end(); ++i) { |
| 467 permissions_list->Append(new base::StringValue(*i)); | 467 permissions_list->Append(new base::StringValue(*i)); |
| 468 } | 468 } |
| 469 values.Set("permissions", permissions_list.release()); | 469 values.Set("permissions", permissions_list.release()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 std::string error; | 472 std::string error; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 extension.get(), | 863 extension.get(), |
| 864 Feature::BLESSED_EXTENSION_CONTEXT, | 864 Feature::BLESSED_EXTENSION_CONTEXT, |
| 865 GURL()).is_available()); | 865 GURL()).is_available()); |
| 866 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 866 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
| 867 extension.get(), | 867 extension.get(), |
| 868 Feature::BLESSED_EXTENSION_CONTEXT, | 868 Feature::BLESSED_EXTENSION_CONTEXT, |
| 869 GURL()).is_available()); | 869 GURL()).is_available()); |
| 870 } | 870 } |
| 871 | 871 |
| 872 } // namespace extensions | 872 } // namespace extensions |
| OLD | NEW |