OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 extension_id, | 77 extension_id, |
78 base::Bind(&ExtensionInfoGeneratorUnitTest::OnInfosGenerated, | 78 base::Bind(&ExtensionInfoGeneratorUnitTest::OnInfosGenerated, |
79 base::Unretained(this), | 79 base::Unretained(this), |
80 base::Unretained(&info))); | 80 base::Unretained(&info))); |
81 run_loop.Run(); | 81 run_loop.Run(); |
82 return make_scoped_ptr(info.release()); | 82 return make_scoped_ptr(info.release()); |
83 } | 83 } |
84 | 84 |
85 const scoped_refptr<const Extension> CreateExtension( | 85 const scoped_refptr<const Extension> CreateExtension( |
86 const std::string& name, | 86 const std::string& name, |
87 ListBuilder permissions) { | 87 scoped_ptr<base::ListValue> permissions) { |
88 const std::string kId = crx_file::id_util::GenerateId(name); | 88 const std::string kId = crx_file::id_util::GenerateId(name); |
89 scoped_refptr<const Extension> extension = | 89 scoped_refptr<const Extension> extension = |
90 ExtensionBuilder() | 90 ExtensionBuilder() |
91 .SetManifest( | 91 .SetManifest(DictionaryBuilder() |
92 std::move(DictionaryBuilder() | 92 .Set("name", name) |
93 .Set("name", name) | 93 .Set("description", "an extension") |
94 .Set("description", "an extension") | 94 .Set("manifest_version", 2) |
95 .Set("manifest_version", 2) | 95 .Set("version", "1.0.0") |
96 .Set("version", "1.0.0") | 96 .Set("permissions", std::move(permissions)) |
97 .Set("permissions", std::move(permissions)))) | 97 .Build()) |
98 .SetLocation(Manifest::INTERNAL) | 98 .SetLocation(Manifest::INTERNAL) |
99 .SetID(kId) | 99 .SetID(kId) |
100 .Build(); | 100 .Build(); |
101 | 101 |
102 ExtensionRegistry::Get(profile())->AddEnabled(extension); | 102 ExtensionRegistry::Get(profile())->AddEnabled(extension); |
103 PermissionsUpdater(profile()).InitializePermissions(extension.get()); | 103 PermissionsUpdater(profile()).InitializePermissions(extension.get()); |
104 return extension; | 104 return extension; |
105 } | 105 } |
106 | 106 |
107 scoped_ptr<developer::ExtensionInfo> CreateExtensionInfoFromPath( | 107 scoped_ptr<developer::ExtensionInfo> CreateExtensionInfoFromPath( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 | 180 |
181 const char kName[] = "extension name"; | 181 const char kName[] = "extension name"; |
182 const char kVersion[] = "1.0.0.1"; | 182 const char kVersion[] = "1.0.0.1"; |
183 std::string id = crx_file::id_util::GenerateId("alpha"); | 183 std::string id = crx_file::id_util::GenerateId("alpha"); |
184 scoped_ptr<base::DictionaryValue> manifest = | 184 scoped_ptr<base::DictionaryValue> manifest = |
185 DictionaryBuilder() | 185 DictionaryBuilder() |
186 .Set("name", kName) | 186 .Set("name", kName) |
187 .Set("version", kVersion) | 187 .Set("version", kVersion) |
188 .Set("manifest_version", 2) | 188 .Set("manifest_version", 2) |
189 .Set("description", "an extension") | 189 .Set("description", "an extension") |
190 .Set("permissions", std::move(ListBuilder().Append("file://*/*"))) | 190 .Set("permissions", ListBuilder().Append("file://*/*").Build()) |
191 .Build(); | 191 .Build(); |
192 scoped_ptr<base::DictionaryValue> manifest_copy(manifest->DeepCopy()); | 192 scoped_ptr<base::DictionaryValue> manifest_copy(manifest->DeepCopy()); |
193 scoped_refptr<const Extension> extension = | 193 scoped_refptr<const Extension> extension = |
194 ExtensionBuilder() | 194 ExtensionBuilder() |
195 .SetManifest(std::move(manifest)) | 195 .SetManifest(std::move(manifest)) |
196 .SetLocation(Manifest::UNPACKED) | 196 .SetLocation(Manifest::UNPACKED) |
197 .SetPath(data_dir()) | 197 .SetPath(data_dir()) |
198 .SetID(id) | 198 .SetID(id) |
199 .Build(); | 199 .Build(); |
200 service()->AddExtension(extension.get()); | 200 service()->AddExtension(extension.get()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 346 |
347 // Test that the all_urls checkbox only shows up for extensions that want all | 347 // Test that the all_urls checkbox only shows up for extensions that want all |
348 // urls, and only when the switch is on. | 348 // urls, and only when the switch is on. |
349 TEST_F(ExtensionInfoGeneratorUnitTest, ExtensionInfoRunOnAllUrls) { | 349 TEST_F(ExtensionInfoGeneratorUnitTest, ExtensionInfoRunOnAllUrls) { |
350 // Start with the switch enabled. | 350 // Start with the switch enabled. |
351 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( | 351 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( |
352 new FeatureSwitch::ScopedOverride( | 352 new FeatureSwitch::ScopedOverride( |
353 FeatureSwitch::scripts_require_action(), true)); | 353 FeatureSwitch::scripts_require_action(), true)); |
354 // Two extensions - one with all urls, one without. | 354 // Two extensions - one with all urls, one without. |
355 scoped_refptr<const Extension> all_urls_extension = CreateExtension( | 355 scoped_refptr<const Extension> all_urls_extension = CreateExtension( |
356 "all_urls", std::move(ListBuilder().Append(kAllHostsPermission))); | 356 "all_urls", ListBuilder().Append(kAllHostsPermission).Build()); |
357 scoped_refptr<const Extension> no_urls_extension = | 357 scoped_refptr<const Extension> no_urls_extension = |
358 CreateExtension("no urls", ListBuilder()); | 358 CreateExtension("no urls", ListBuilder().Build()); |
359 | 359 |
360 scoped_ptr<developer::ExtensionInfo> info = | 360 scoped_ptr<developer::ExtensionInfo> info = |
361 GenerateExtensionInfo(all_urls_extension->id()); | 361 GenerateExtensionInfo(all_urls_extension->id()); |
362 | 362 |
363 // The extension should want all urls, but not currently have it. | 363 // The extension should want all urls, but not currently have it. |
364 EXPECT_TRUE(info->run_on_all_urls.is_enabled); | 364 EXPECT_TRUE(info->run_on_all_urls.is_enabled); |
365 EXPECT_FALSE(info->run_on_all_urls.is_active); | 365 EXPECT_FALSE(info->run_on_all_urls.is_active); |
366 | 366 |
367 // Give the extension all urls. | 367 // Give the extension all urls. |
368 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); | 368 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); |
(...skipping 24 matching lines...) Expand all Loading... |
393 | 393 |
394 // If we grant the extension all urls, then the checkbox should still be | 394 // If we grant the extension all urls, then the checkbox should still be |
395 // there, since it has an explicitly-set user preference. | 395 // there, since it has an explicitly-set user preference. |
396 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); | 396 util::SetAllowedScriptingOnAllUrls(all_urls_extension->id(), profile(), true); |
397 info = GenerateExtensionInfo(all_urls_extension->id()); | 397 info = GenerateExtensionInfo(all_urls_extension->id()); |
398 EXPECT_TRUE(info->run_on_all_urls.is_enabled); | 398 EXPECT_TRUE(info->run_on_all_urls.is_enabled); |
399 EXPECT_TRUE(info->run_on_all_urls.is_active); | 399 EXPECT_TRUE(info->run_on_all_urls.is_active); |
400 | 400 |
401 // Load another extension with all urls (so permissions get re-init'd). | 401 // Load another extension with all urls (so permissions get re-init'd). |
402 all_urls_extension = CreateExtension( | 402 all_urls_extension = CreateExtension( |
403 "all_urls_II", std::move(ListBuilder().Append(kAllHostsPermission))); | 403 "all_urls_II", ListBuilder().Append(kAllHostsPermission).Build()); |
404 | 404 |
405 // Even though the extension has all_urls permission, the checkbox shouldn't | 405 // Even though the extension has all_urls permission, the checkbox shouldn't |
406 // show up without the switch. | 406 // show up without the switch. |
407 info = GenerateExtensionInfo(all_urls_extension->id()); | 407 info = GenerateExtensionInfo(all_urls_extension->id()); |
408 EXPECT_FALSE(info->run_on_all_urls.is_enabled); | 408 EXPECT_FALSE(info->run_on_all_urls.is_enabled); |
409 EXPECT_TRUE(info->run_on_all_urls.is_active); | 409 EXPECT_TRUE(info->run_on_all_urls.is_active); |
410 } | 410 } |
411 | 411 |
412 } // namespace extensions | 412 } // namespace extensions |
OLD | NEW |