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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/json/json_file_value_serializer.h" | 6 #include "base/json/json_file_value_serializer.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
11 #include "chrome/browser/extensions/management_policy.h" | 11 #include "chrome/browser/extensions/management_policy.h" |
12 #include "chrome/browser/extensions/test_extension_system.h" | 12 #include "chrome/browser/extensions/test_extension_system.h" |
13 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" | 13 #include "chrome/browser/ui/webui/extensions/extension_settings_handler.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "content/public/test/test_browser_thread.h" | 17 #include "content/public/test/test_browser_thread.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 using extensions::Extension; | 20 using extensions::Extension; |
| 21 using extensions::Manifest; |
21 | 22 |
22 class ExtensionUITest : public testing::Test { | 23 class ExtensionUITest : public testing::Test { |
23 public: | 24 public: |
24 ExtensionUITest() | 25 ExtensionUITest() |
25 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 26 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
26 file_thread_(content::BrowserThread::FILE, &message_loop_) {} | 27 file_thread_(content::BrowserThread::FILE, &message_loop_) {} |
27 | 28 |
28 protected: | 29 protected: |
29 virtual void SetUp() OVERRIDE { | 30 virtual void SetUp() OVERRIDE { |
30 // Create an ExtensionService and ManagementPolicy to inject into the | 31 // Create an ExtensionService and ManagementPolicy to inject into the |
(...skipping 23 matching lines...) Expand all Loading... |
54 | 55 |
55 JSONFileValueSerializer serializer(path); | 56 JSONFileValueSerializer serializer(path); |
56 value = serializer.Deserialize(NULL, error); | 57 value = serializer.Deserialize(NULL, error); |
57 | 58 |
58 return static_cast<DictionaryValue*>(value); | 59 return static_cast<DictionaryValue*>(value); |
59 } | 60 } |
60 | 61 |
61 DictionaryValue* CreateExtensionDetailViewFromPath( | 62 DictionaryValue* CreateExtensionDetailViewFromPath( |
62 const FilePath& extension_path, | 63 const FilePath& extension_path, |
63 const std::vector<ExtensionPage>& pages, | 64 const std::vector<ExtensionPage>& pages, |
64 Extension::Location location) { | 65 Manifest::Location location) { |
65 std::string error; | 66 std::string error; |
66 | 67 |
67 FilePath manifest_path = extension_path.Append( | 68 FilePath manifest_path = extension_path.Append( |
68 Extension::kManifestFilename); | 69 Extension::kManifestFilename); |
69 scoped_ptr<DictionaryValue> extension_data(DeserializeJSONTestData( | 70 scoped_ptr<DictionaryValue> extension_data(DeserializeJSONTestData( |
70 manifest_path, &error)); | 71 manifest_path, &error)); |
71 EXPECT_EQ("", error); | 72 EXPECT_EQ("", error); |
72 | 73 |
73 scoped_refptr<Extension> extension(Extension::Create( | 74 scoped_refptr<Extension> extension(Extension::Create( |
74 extension_path, location, *extension_data, Extension::REQUIRE_KEY, | 75 extension_path, location, *extension_data, Extension::REQUIRE_KEY, |
(...skipping 10 matching lines...) Expand all Loading... |
85 const FilePath& expected_output_path) { | 86 const FilePath& expected_output_path) { |
86 std::string error; | 87 std::string error; |
87 | 88 |
88 scoped_ptr<DictionaryValue> expected_output_data(DeserializeJSONTestData( | 89 scoped_ptr<DictionaryValue> expected_output_data(DeserializeJSONTestData( |
89 expected_output_path, &error)); | 90 expected_output_path, &error)); |
90 EXPECT_EQ("", error); | 91 EXPECT_EQ("", error); |
91 | 92 |
92 // Produce test output. | 93 // Produce test output. |
93 scoped_ptr<DictionaryValue> actual_output_data( | 94 scoped_ptr<DictionaryValue> actual_output_data( |
94 CreateExtensionDetailViewFromPath( | 95 CreateExtensionDetailViewFromPath( |
95 extension_path, pages, Extension::INVALID)); | 96 extension_path, pages, Manifest::INVALID_LOCATION)); |
96 | 97 |
97 // Compare the outputs. | 98 // Compare the outputs. |
98 // Ignore unknown fields in the actual output data. | 99 // Ignore unknown fields in the actual output data. |
99 std::string paths_details = " - expected (" + | 100 std::string paths_details = " - expected (" + |
100 expected_output_path.MaybeAsASCII() + ") vs. actual (" + | 101 expected_output_path.MaybeAsASCII() + ") vs. actual (" + |
101 extension_path.MaybeAsASCII() + ")"; | 102 extension_path.MaybeAsASCII() + ")"; |
102 for (DictionaryValue::key_iterator key = expected_output_data->begin_keys(); | 103 for (DictionaryValue::key_iterator key = expected_output_data->begin_keys(); |
103 key != expected_output_data->end_keys(); | 104 key != expected_output_data->end_keys(); |
104 ++key) { | 105 ++key) { |
105 Value* expected_value = NULL; | 106 Value* expected_value = NULL; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 expected_output_path = data_test_dir_path.AppendASCII("extensions") | 182 expected_output_path = data_test_dir_path.AppendASCII("extensions") |
182 .AppendASCII("ui") | 183 .AppendASCII("ui") |
183 .AppendASCII("create_extension_detail_value_expected_output") | 184 .AppendASCII("create_extension_detail_value_expected_output") |
184 .AppendASCII("good-extension3.json"); | 185 .AppendASCII("good-extension3.json"); |
185 | 186 |
186 pages.clear(); | 187 pages.clear(); |
187 | 188 |
188 CompareExpectedAndActualOutput(extension_path, pages, expected_output_path); | 189 CompareExpectedAndActualOutput(extension_path, pages, expected_output_path); |
189 } | 190 } |
190 | 191 |
191 // Test that using Extension::LOAD for the extension location triggers the | 192 // Test that using Manifest::LOAD for the extension location triggers the |
192 // correct values in the details, including location, order, and allow_reload. | 193 // correct values in the details, including location, order, and allow_reload. |
193 TEST_F(ExtensionUITest, LocationLoadPropagation) { | 194 TEST_F(ExtensionUITest, LocationLoadPropagation) { |
194 FilePath data_test_dir_path, extension_path; | 195 FilePath data_test_dir_path, extension_path; |
195 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 196 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
196 | 197 |
197 extension_path = data_test_dir_path.AppendASCII("extensions") | 198 extension_path = data_test_dir_path.AppendASCII("extensions") |
198 .AppendASCII("good") | 199 .AppendASCII("good") |
199 .AppendASCII("Extensions") | 200 .AppendASCII("Extensions") |
200 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 201 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
201 .AppendASCII("1.0.0.0"); | 202 .AppendASCII("1.0.0.0"); |
202 | 203 |
203 std::vector<ExtensionPage> pages; | 204 std::vector<ExtensionPage> pages; |
204 | 205 |
205 scoped_ptr<DictionaryValue> extension_details( | 206 scoped_ptr<DictionaryValue> extension_details( |
206 CreateExtensionDetailViewFromPath( | 207 CreateExtensionDetailViewFromPath( |
207 extension_path, pages, Extension::LOAD)); | 208 extension_path, pages, Manifest::LOAD)); |
208 | 209 |
209 bool ui_allow_reload = false; | 210 bool ui_allow_reload = false; |
210 bool ui_is_unpacked = false; | 211 bool ui_is_unpacked = false; |
211 FilePath::StringType ui_path; | 212 FilePath::StringType ui_path; |
212 | 213 |
213 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); | 214 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); |
214 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); | 215 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); |
215 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); | 216 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); |
216 EXPECT_EQ(true, ui_allow_reload); | 217 EXPECT_EQ(true, ui_allow_reload); |
217 EXPECT_EQ(true, ui_is_unpacked); | 218 EXPECT_EQ(true, ui_is_unpacked); |
218 EXPECT_EQ(extension_path, FilePath(ui_path)); | 219 EXPECT_EQ(extension_path, FilePath(ui_path)); |
219 } | 220 } |
220 | 221 |
221 // Test that using Extension::EXTERNAL_PREF for the extension location triggers | 222 // Test that using Manifest::EXTERNAL_PREF for the extension location triggers |
222 // the correct values in the details, including location, order, and | 223 // the correct values in the details, including location, order, and |
223 // allow_reload. Contrast to Extension::LOAD, which has somewhat different | 224 // allow_reload. Contrast to Manifest::LOAD, which has somewhat different |
224 // values. | 225 // values. |
225 TEST_F(ExtensionUITest, LocationExternalPrefPropagation) { | 226 TEST_F(ExtensionUITest, LocationExternalPrefPropagation) { |
226 FilePath data_test_dir_path, extension_path; | 227 FilePath data_test_dir_path, extension_path; |
227 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 228 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
228 | 229 |
229 extension_path = data_test_dir_path.AppendASCII("extensions") | 230 extension_path = data_test_dir_path.AppendASCII("extensions") |
230 .AppendASCII("good") | 231 .AppendASCII("good") |
231 .AppendASCII("Extensions") | 232 .AppendASCII("Extensions") |
232 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 233 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
233 .AppendASCII("1.0.0.0"); | 234 .AppendASCII("1.0.0.0"); |
234 | 235 |
235 std::vector<ExtensionPage> pages; | 236 std::vector<ExtensionPage> pages; |
236 | 237 |
237 scoped_ptr<DictionaryValue> extension_details( | 238 scoped_ptr<DictionaryValue> extension_details( |
238 CreateExtensionDetailViewFromPath( | 239 CreateExtensionDetailViewFromPath( |
239 extension_path, pages, Extension::EXTERNAL_PREF)); | 240 extension_path, pages, Manifest::EXTERNAL_PREF)); |
240 | 241 |
241 bool ui_allow_reload = true; | 242 bool ui_allow_reload = true; |
242 bool ui_is_unpacked = true; | 243 bool ui_is_unpacked = true; |
243 FilePath::StringType ui_path; | 244 FilePath::StringType ui_path; |
244 | 245 |
245 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); | 246 EXPECT_TRUE(extension_details->GetBoolean("allow_reload", &ui_allow_reload)); |
246 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); | 247 EXPECT_TRUE(extension_details->GetBoolean("isUnpacked", &ui_is_unpacked)); |
247 EXPECT_FALSE(extension_details->GetString("path", &ui_path)); | 248 EXPECT_FALSE(extension_details->GetString("path", &ui_path)); |
248 EXPECT_FALSE(ui_allow_reload); | 249 EXPECT_FALSE(ui_allow_reload); |
249 EXPECT_FALSE(ui_is_unpacked); | 250 EXPECT_FALSE(ui_is_unpacked); |
250 } | 251 } |
251 | 252 |
252 // Test that the extension path is correctly propagated into the extension | 253 // Test that the extension path is correctly propagated into the extension |
253 // details. | 254 // details. |
254 TEST_F(ExtensionUITest, PathPropagation) { | 255 TEST_F(ExtensionUITest, PathPropagation) { |
255 FilePath data_test_dir_path, extension_path; | 256 FilePath data_test_dir_path, extension_path; |
256 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); | 257 EXPECT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_test_dir_path)); |
257 | 258 |
258 extension_path = data_test_dir_path.AppendASCII("extensions") | 259 extension_path = data_test_dir_path.AppendASCII("extensions") |
259 .AppendASCII("good") | 260 .AppendASCII("good") |
260 .AppendASCII("Extensions") | 261 .AppendASCII("Extensions") |
261 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 262 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
262 .AppendASCII("1.0.0.0"); | 263 .AppendASCII("1.0.0.0"); |
263 | 264 |
264 std::vector<ExtensionPage> pages; | 265 std::vector<ExtensionPage> pages; |
265 | 266 |
266 scoped_ptr<DictionaryValue> extension_details( | 267 scoped_ptr<DictionaryValue> extension_details( |
267 CreateExtensionDetailViewFromPath( | 268 CreateExtensionDetailViewFromPath( |
268 extension_path, pages, Extension::LOAD)); | 269 extension_path, pages, Manifest::LOAD)); |
269 | 270 |
270 FilePath::StringType ui_path; | 271 FilePath::StringType ui_path; |
271 | 272 |
272 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); | 273 EXPECT_TRUE(extension_details->GetString("path", &ui_path)); |
273 EXPECT_EQ(extension_path, FilePath(ui_path)); | 274 EXPECT_EQ(extension_path, FilePath(ui_path)); |
274 } | 275 } |
OLD | NEW |