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