| 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_builder.h" | 21 #include "chrome/common/extensions/extension_builder.h" |
| 22 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 23 #include "chrome/common/extensions/extension_test_util.h" | 22 #include "chrome/common/extensions/extension_test_util.h" |
| 24 #include "chrome/common/extensions/features/api_feature.h" | 23 #include "chrome/common/extensions/features/api_feature.h" |
| 25 #include "chrome/common/extensions/features/base_feature_provider.h" | 24 #include "chrome/common/extensions/features/base_feature_provider.h" |
| 26 #include "chrome/common/extensions/features/simple_feature.h" | 25 #include "chrome/common/extensions/features/simple_feature.h" |
| 27 #include "chrome/common/extensions/manifest.h" | 26 #include "chrome/common/extensions/manifest.h" |
| 28 #include "chrome/common/extensions/value_builder.h" | 27 #include "chrome/common/extensions/value_builder.h" |
| 28 #include "extensions/common/manifest_constants.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 namespace extensions { | 31 namespace extensions { |
| 32 | 32 |
| 33 using extension_test_util::BuildExtension; | 33 using extension_test_util::BuildExtension; |
| 34 | 34 |
| 35 SimpleFeature* CreateAPIFeature() { | 35 SimpleFeature* CreateAPIFeature() { |
| 36 return new APIFeature(); | 36 return new APIFeature(); |
| 37 } | 37 } |
| 38 | 38 |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 GURL())); | 461 GURL())); |
| 462 EXPECT_FALSE(extension_api->IsAnyFeatureAvailableToContext( | 462 EXPECT_FALSE(extension_api->IsAnyFeatureAvailableToContext( |
| 463 "history", | 463 "history", |
| 464 NULL, | 464 NULL, |
| 465 Feature::CONTENT_SCRIPT_CONTEXT, | 465 Feature::CONTENT_SCRIPT_CONTEXT, |
| 466 GURL())); | 466 GURL())); |
| 467 } | 467 } |
| 468 | 468 |
| 469 scoped_refptr<Extension> CreateHostedApp() { | 469 scoped_refptr<Extension> CreateHostedApp() { |
| 470 base::DictionaryValue values; | 470 base::DictionaryValue values; |
| 471 values.SetString(extension_manifest_keys::kName, "test"); | 471 values.SetString(manifest_keys::kName, "test"); |
| 472 values.SetString(extension_manifest_keys::kVersion, "0.1"); | 472 values.SetString(manifest_keys::kVersion, "0.1"); |
| 473 values.Set(extension_manifest_keys::kWebURLs, new base::ListValue()); | 473 values.Set(manifest_keys::kWebURLs, new base::ListValue()); |
| 474 values.SetString(extension_manifest_keys::kLaunchWebURL, | 474 values.SetString(manifest_keys::kLaunchWebURL, |
| 475 "http://www.example.com"); | 475 "http://www.example.com"); |
| 476 std::string error; | 476 std::string error; |
| 477 scoped_refptr<Extension> extension(Extension::Create( | 477 scoped_refptr<Extension> extension(Extension::Create( |
| 478 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, | 478 base::FilePath(), Manifest::INTERNAL, values, Extension::NO_FLAGS, |
| 479 &error)); | 479 &error)); |
| 480 CHECK(extension.get()); | 480 CHECK(extension.get()); |
| 481 return extension; | 481 return extension; |
| 482 } | 482 } |
| 483 | 483 |
| 484 scoped_refptr<Extension> CreatePackagedAppWithPermissions( | 484 scoped_refptr<Extension> CreatePackagedAppWithPermissions( |
| 485 const std::set<std::string>& permissions) { | 485 const std::set<std::string>& permissions) { |
| 486 base::DictionaryValue values; | 486 base::DictionaryValue values; |
| 487 values.SetString(extension_manifest_keys::kName, "test"); | 487 values.SetString(manifest_keys::kName, "test"); |
| 488 values.SetString(extension_manifest_keys::kVersion, "0.1"); | 488 values.SetString(manifest_keys::kVersion, "0.1"); |
| 489 values.SetString(extension_manifest_keys::kPlatformAppBackground, | 489 values.SetString(manifest_keys::kPlatformAppBackground, |
| 490 "http://www.example.com"); | 490 "http://www.example.com"); |
| 491 | 491 |
| 492 base::DictionaryValue* app = new base::DictionaryValue(); | 492 base::DictionaryValue* app = new base::DictionaryValue(); |
| 493 base::DictionaryValue* background = new base::DictionaryValue(); | 493 base::DictionaryValue* background = new base::DictionaryValue(); |
| 494 base::ListValue* scripts = new base::ListValue(); | 494 base::ListValue* scripts = new base::ListValue(); |
| 495 scripts->Append(new base::StringValue("test.js")); | 495 scripts->Append(new base::StringValue("test.js")); |
| 496 background->Set("scripts", scripts); | 496 background->Set("scripts", scripts); |
| 497 app->Set("background", background); | 497 app->Set("background", background); |
| 498 values.Set(extension_manifest_keys::kApp, app); | 498 values.Set(manifest_keys::kApp, app); |
| 499 { | 499 { |
| 500 scoped_ptr<base::ListValue> permissions_list(new base::ListValue()); | 500 scoped_ptr<base::ListValue> permissions_list(new base::ListValue()); |
| 501 for (std::set<std::string>::const_iterator i = permissions.begin(); | 501 for (std::set<std::string>::const_iterator i = permissions.begin(); |
| 502 i != permissions.end(); ++i) { | 502 i != permissions.end(); ++i) { |
| 503 permissions_list->Append(new base::StringValue(*i)); | 503 permissions_list->Append(new base::StringValue(*i)); |
| 504 } | 504 } |
| 505 values.Set("permissions", permissions_list.release()); | 505 values.Set("permissions", permissions_list.release()); |
| 506 } | 506 } |
| 507 | 507 |
| 508 std::string error; | 508 std::string error; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 extension.get(), | 899 extension.get(), |
| 900 Feature::BLESSED_EXTENSION_CONTEXT, | 900 Feature::BLESSED_EXTENSION_CONTEXT, |
| 901 GURL()).is_available()); | 901 GURL()).is_available()); |
| 902 EXPECT_FALSE(extension_api->IsAvailable("pageAction", | 902 EXPECT_FALSE(extension_api->IsAvailable("pageAction", |
| 903 extension.get(), | 903 extension.get(), |
| 904 Feature::BLESSED_EXTENSION_CONTEXT, | 904 Feature::BLESSED_EXTENSION_CONTEXT, |
| 905 GURL()).is_available()); | 905 GURL()).is_available()); |
| 906 } | 906 } |
| 907 | 907 |
| 908 } // namespace extensions | 908 } // namespace extensions |
| OLD | NEW |