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/manifest.h" | 5 #include "chrome/common/extensions/manifest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 string16 error; | 51 string16 error; |
52 EXPECT_TRUE(manifest->ValidateManifest(&error)); | 52 EXPECT_TRUE(manifest->ValidateManifest(&error)); |
53 EXPECT_EQ(ASCIIToUTF16(""), error); | 53 EXPECT_EQ(ASCIIToUTF16(""), error); |
54 AssertType(manifest.get(), Extension::TYPE_EXTENSION); | 54 AssertType(manifest.get(), Extension::TYPE_EXTENSION); |
55 | 55 |
56 // The known key 'background_page' should be accessible. | 56 // The known key 'background_page' should be accessible. |
57 std::string value; | 57 std::string value; |
58 EXPECT_TRUE(manifest->GetString(keys::kBackgroundPageLegacy, &value)); | 58 EXPECT_TRUE(manifest->GetString(keys::kBackgroundPageLegacy, &value)); |
59 EXPECT_EQ("bg.html", value); | 59 EXPECT_EQ("bg.html", value); |
60 | 60 |
61 // The unknown key 'unknown_key' should be inaccesible. | 61 // The unknown key 'unknown_key' should be accesible. |
62 value.clear(); | 62 value.clear(); |
63 EXPECT_FALSE(manifest->GetString("unknown_key", &value)); | 63 EXPECT_TRUE(manifest->GetString("unknown_key", &value)); |
64 EXPECT_EQ("", value); | 64 EXPECT_EQ("foo", value); |
65 | 65 |
66 // Set the manifest_version to 2; background_page should stop working. | 66 // Set the manifest_version to 2; background_page should stop working. |
67 value.clear(); | 67 value.clear(); |
68 manifest->value()->SetInteger(keys::kManifestVersion, 2); | 68 manifest->value()->SetInteger(keys::kManifestVersion, 2); |
69 EXPECT_FALSE(manifest->GetString("background_page", &value)); | 69 EXPECT_FALSE(manifest->GetString("background_page", &value)); |
70 EXPECT_EQ("", value); | 70 EXPECT_EQ("", value); |
71 | 71 |
72 // Validate should also stop working. | 72 // Validate should also stop working. |
73 error.clear(); | 73 error.clear(); |
74 EXPECT_FALSE(manifest->ValidateManifest(&error)); | 74 EXPECT_FALSE(manifest->ValidateManifest(&error)); |
75 { | 75 { |
76 Feature feature; | 76 Feature feature; |
77 feature.set_name("background_page"); | 77 feature.set_name("background_page"); |
78 feature.set_max_manifest_version(1); | 78 feature.set_max_manifest_version(1); |
79 EXPECT_EQ(ExtensionErrorUtils::FormatErrorMessageUTF16( | 79 EXPECT_EQ(ExtensionErrorUtils::FormatErrorMessageUTF16( |
80 errors::kFeatureNotAllowed, | 80 "*", feature.GetErrorMessage(Feature::INVALID_MAX_MANIFEST_VERSION)), |
81 "background_page", | 81 error); |
82 feature.GetErrorMessage(Feature::INVALID_MAX_MANIFEST_VERSION)), error); | |
83 } | 82 } |
84 | 83 |
85 // Test DeepCopy and Equals. | 84 // Test DeepCopy and Equals. |
86 scoped_ptr<Manifest> manifest2(manifest->DeepCopy()); | 85 scoped_ptr<Manifest> manifest2(manifest->DeepCopy()); |
87 EXPECT_TRUE(manifest->Equals(manifest2.get())); | 86 EXPECT_TRUE(manifest->Equals(manifest2.get())); |
88 EXPECT_TRUE(manifest2->Equals(manifest.get())); | 87 EXPECT_TRUE(manifest2->Equals(manifest.get())); |
89 manifest->value()->Set("foo", Value::CreateStringValue("blah")); | 88 manifest->value()->Set("foo", Value::CreateStringValue("blah")); |
90 EXPECT_FALSE(manifest->Equals(manifest2.get())); | 89 EXPECT_FALSE(manifest->Equals(manifest2.get())); |
91 } | 90 } |
92 | 91 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 | 124 |
126 // Hosted app. | 125 // Hosted app. |
127 manifest->value()->Set(keys::kWebURLs, new ListValue()); | 126 manifest->value()->Set(keys::kWebURLs, new ListValue()); |
128 AssertType(manifest.get(), Extension::TYPE_HOSTED_APP); | 127 AssertType(manifest.get(), Extension::TYPE_HOSTED_APP); |
129 manifest->value()->Remove(keys::kWebURLs, NULL); | 128 manifest->value()->Remove(keys::kWebURLs, NULL); |
130 manifest->value()->SetString(keys::kLaunchWebURL, "foo"); | 129 manifest->value()->SetString(keys::kLaunchWebURL, "foo"); |
131 AssertType(manifest.get(), Extension::TYPE_HOSTED_APP); | 130 AssertType(manifest.get(), Extension::TYPE_HOSTED_APP); |
132 manifest->value()->Remove(keys::kLaunchWebURL, NULL); | 131 manifest->value()->Remove(keys::kLaunchWebURL, NULL); |
133 }; | 132 }; |
134 | 133 |
135 // Verifies that the various getters filter unknown and restricted keys. | |
Aaron Boodman
2012/04/25 21:48:31
Are there any checks of restricted keys here? It l
Matt Perry
2012/04/25 22:28:19
They were all for unknown keys. I added a new test
| |
136 TEST_F(ManifestTest, Getters) { | |
137 scoped_ptr<DictionaryValue> value(new DictionaryValue()); | |
138 scoped_ptr<Manifest> manifest( | |
139 new Manifest(Extension::INTERNAL, value.Pass())); | |
140 std::string unknown_key = "asdfaskldjf"; | |
141 | |
142 // Verify that the key filtering works for each of the getters. | |
143 // Get and GetBoolean | |
144 bool expected_bool = true, actual_bool = false; | |
145 manifest->value()->Set(unknown_key, Value::CreateBooleanValue(expected_bool)); | |
146 EXPECT_FALSE(manifest->HasKey(unknown_key)); | |
147 EXPECT_FALSE(manifest->GetBoolean(unknown_key, &actual_bool)); | |
148 EXPECT_FALSE(actual_bool); | |
149 Value* actual_value = NULL; | |
150 EXPECT_FALSE(manifest->Get(unknown_key, &actual_value)); | |
151 EXPECT_TRUE(manifest->value()->Remove(unknown_key, NULL)); | |
152 | |
153 // GetInteger | |
154 int expected_int = 5, actual_int = 0; | |
155 manifest->value()->Set(unknown_key, Value::CreateIntegerValue(expected_int)); | |
156 EXPECT_FALSE(manifest->GetInteger(unknown_key, &actual_int)); | |
157 EXPECT_NE(expected_int, actual_int); | |
158 EXPECT_TRUE(manifest->value()->Remove(unknown_key, NULL)); | |
159 | |
160 // GetString | |
161 std::string expected_str = "hello", actual_str; | |
162 manifest->value()->Set(unknown_key, Value::CreateStringValue(expected_str)); | |
163 EXPECT_FALSE(manifest->GetString(unknown_key, &actual_str)); | |
164 EXPECT_NE(expected_str, actual_str); | |
165 EXPECT_TRUE(manifest->value()->Remove(unknown_key, NULL)); | |
166 | |
167 // GetString (string16) | |
168 string16 expected_str16(UTF8ToUTF16("hello")), actual_str16; | |
169 manifest->value()->Set(unknown_key, Value::CreateStringValue(expected_str16)); | |
170 EXPECT_FALSE(manifest->GetString(unknown_key, &actual_str16)); | |
171 EXPECT_NE(expected_str16, actual_str16); | |
172 EXPECT_TRUE(manifest->value()->Remove(unknown_key, NULL)); | |
173 | |
174 // GetDictionary | |
175 DictionaryValue* expected_dict = new DictionaryValue(); | |
176 DictionaryValue* actual_dict = NULL; | |
177 expected_dict->Set("foo", Value::CreateStringValue("bar")); | |
178 manifest->value()->Set(unknown_key, expected_dict); | |
179 EXPECT_FALSE(manifest->GetDictionary(unknown_key, &actual_dict)); | |
180 EXPECT_EQ(NULL, actual_dict); | |
181 std::string path = unknown_key + ".foo"; | |
182 EXPECT_FALSE(manifest->GetString(path, &actual_str)); | |
183 EXPECT_NE("bar", actual_str); | |
184 EXPECT_TRUE(manifest->value()->Remove(unknown_key, NULL)); | |
185 | |
186 // GetList | |
187 ListValue* expected_list = new ListValue(); | |
188 ListValue* actual_list = NULL; | |
189 expected_list->Append(Value::CreateStringValue("blah")); | |
190 manifest->value()->Set(unknown_key, expected_list); | |
191 EXPECT_FALSE(manifest->GetList(unknown_key, &actual_list)); | |
192 EXPECT_EQ(NULL, actual_list); | |
193 EXPECT_TRUE(manifest->value()->Remove(unknown_key, NULL)); | |
194 } | |
195 | |
196 } // namespace extensions | 134 } // namespace extensions |
OLD | NEW |