extension_manifests_requirements_unittest.cc revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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 3// found in the LICENSE file. 4 5#include "chrome/common/extensions/manifest_handlers/requirements_handler.h" 6#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 7#include "extensions/common/error_utils.h" 8#include "extensions/common/manifest_constants.h" 9#include "testing/gtest/include/gtest/gtest.h" 10 11namespace extensions { 12 13namespace errors = manifest_errors; 14 15class RequirementsManifestTest : public ExtensionManifestTest { 16}; 17 18TEST_F(RequirementsManifestTest, RequirementsInvalid) { 19 Testcase testcases[] = { 20 Testcase("requirements_invalid_requirements.json", 21 errors::kInvalidRequirements), 22 Testcase("requirements_invalid_keys.json", errors::kInvalidRequirements), 23 Testcase("requirements_invalid_3d.json", 24 ErrorUtils::FormatErrorMessage( 25 errors::kInvalidRequirement, "3D")), 26 Testcase("requirements_invalid_3d_features.json", 27 ErrorUtils::FormatErrorMessage( 28 errors::kInvalidRequirement, "3D")), 29 Testcase("requirements_invalid_3d_features_value.json", 30 ErrorUtils::FormatErrorMessage( 31 errors::kInvalidRequirement, "3D")), 32 Testcase("requirements_invalid_3d_no_features.json", 33 ErrorUtils::FormatErrorMessage( 34 errors::kInvalidRequirement, "3D")), 35 Testcase("requirements_invalid_plugins.json", 36 ErrorUtils::FormatErrorMessage( 37 errors::kInvalidRequirement, "plugins")), 38 Testcase("requirements_invalid_plugins_key.json", 39 ErrorUtils::FormatErrorMessage( 40 errors::kInvalidRequirement, "plugins")), 41 Testcase("requirements_invalid_plugins_value.json", 42 ErrorUtils::FormatErrorMessage( 43 errors::kInvalidRequirement, "plugins")) 44 }; 45 46 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_ERROR); 47} 48 49TEST_F(RequirementsManifestTest, RequirementsValid) { 50 // Test the defaults. 51 scoped_refptr<Extension> extension(LoadAndExpectSuccess( 52 "requirements_valid_empty.json")); 53 ASSERT_TRUE(extension.get()); 54 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).webgl, false); 55 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).css3d, false); 56 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).npapi, false); 57 58 // Test loading all the requirements. 59 extension = LoadAndExpectSuccess("requirements_valid_full.json"); 60 ASSERT_TRUE(extension.get()); 61 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).webgl, true); 62 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).css3d, true); 63 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).npapi, true); 64} 65 66// When an npapi plugin is present, the default of the "npapi" requirement 67// changes. 68TEST_F(RequirementsManifestTest, RequirementsNpapiDefault) { 69 scoped_refptr<Extension> extension(LoadAndExpectSuccess( 70 "requirements_npapi_empty.json")); 71 ASSERT_TRUE(extension.get()); 72 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).webgl, false); 73 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).css3d, false); 74 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).npapi, true); 75 76 extension = LoadAndExpectSuccess( 77 "requirements_npapi_empty_plugins_empty.json"); 78 ASSERT_TRUE(extension.get()); 79 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).webgl, false); 80 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).css3d, false); 81 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).npapi, false); 82 83 extension = LoadAndExpectSuccess("requirements_npapi.json"); 84 ASSERT_TRUE(extension.get()); 85 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).webgl, false); 86 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).css3d, false); 87 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).npapi, false); 88 89 extension = LoadAndExpectSuccess("requirements_npapi_plugins_empty.json"); 90 ASSERT_TRUE(extension.get()); 91 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).webgl, false); 92 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).css3d, false); 93 EXPECT_EQ(RequirementsInfo::GetRequirements(extension.get()).npapi, true); 94} 95 96} // namespace extensions 97