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/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 const base::FilePath& path, | 69 const base::FilePath& path, |
70 std::string *error) { | 70 std::string *error) { |
71 base::Value* value; | 71 base::Value* value; |
72 | 72 |
73 JSONFileValueSerializer serializer(path); | 73 JSONFileValueSerializer serializer(path); |
74 value = serializer.Deserialize(NULL, error); | 74 value = serializer.Deserialize(NULL, error); |
75 | 75 |
76 return static_cast<base::DictionaryValue*>(value); | 76 return static_cast<base::DictionaryValue*>(value); |
77 } | 77 } |
78 | 78 |
79 const Extension* CreateExtension(const std::string& name, | 79 const scoped_refptr<const Extension> CreateExtension( |
dcheng
2014/08/26 01:15:28
Note: this return type (and other instances in thi
| |
80 ListBuilder& permissions) { | 80 const std::string& name, |
81 ListBuilder& permissions) { | |
81 const std::string kId = crx_file::id_util::GenerateId(name); | 82 const std::string kId = crx_file::id_util::GenerateId(name); |
82 scoped_refptr<const Extension> extension = | 83 scoped_refptr<const Extension> extension = |
83 ExtensionBuilder().SetManifest( | 84 ExtensionBuilder().SetManifest( |
84 DictionaryBuilder() | 85 DictionaryBuilder() |
85 .Set("name", name) | 86 .Set("name", name) |
86 .Set("description", "an extension") | 87 .Set("description", "an extension") |
87 .Set("manifest_version", 2) | 88 .Set("manifest_version", 2) |
88 .Set("version", "1.0.0") | 89 .Set("version", "1.0.0") |
89 .Set("permissions", permissions)) | 90 .Set("permissions", permissions)) |
90 .SetLocation(Manifest::INTERNAL) | 91 .SetLocation(Manifest::INTERNAL) |
91 .SetID(kId) | 92 .SetID(kId) |
92 .Build(); | 93 .Build(); |
93 | 94 |
94 ExtensionRegistry::Get(profile())->AddEnabled(extension); | 95 ExtensionRegistry::Get(profile())->AddEnabled(extension); |
95 PermissionsUpdater(profile()).InitializePermissions(extension); | 96 PermissionsUpdater(profile()).InitializePermissions(extension.get()); |
96 return extension; | 97 return extension; |
97 } | 98 } |
98 | 99 |
99 base::DictionaryValue* CreateExtensionDetailViewFromPath( | 100 base::DictionaryValue* CreateExtensionDetailViewFromPath( |
100 const base::FilePath& extension_path, | 101 const base::FilePath& extension_path, |
101 const std::vector<ExtensionPage>& pages, | 102 const std::vector<ExtensionPage>& pages, |
102 Manifest::Location location) { | 103 Manifest::Location location) { |
103 std::string error; | 104 std::string error; |
104 | 105 |
105 base::FilePath manifest_path = extension_path.Append(kManifestFilename); | 106 base::FilePath manifest_path = extension_path.Append(kManifestFilename); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 } | 314 } |
314 | 315 |
315 // Test that the all_urls checkbox only shows up for extensions that want all | 316 // Test that the all_urls checkbox only shows up for extensions that want all |
316 // urls, and only when the switch is on. | 317 // urls, and only when the switch is on. |
317 TEST_F(ExtensionUITest, ExtensionUIAllUrlsCheckbox) { | 318 TEST_F(ExtensionUITest, ExtensionUIAllUrlsCheckbox) { |
318 // Start with the switch enabled. | 319 // Start with the switch enabled. |
319 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( | 320 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( |
320 new FeatureSwitch::ScopedOverride( | 321 new FeatureSwitch::ScopedOverride( |
321 FeatureSwitch::scripts_require_action(), true)); | 322 FeatureSwitch::scripts_require_action(), true)); |
322 // Two extensions - one with all urls, one without. | 323 // Two extensions - one with all urls, one without. |
323 const Extension* all_urls_extension = | 324 scoped_refptr<const Extension> all_urls_extension = CreateExtension( |
dcheng
2014/08/26 01:15:27
Note: this variable type (and other instances in t
| |
324 CreateExtension("all_urls", | 325 "all_urls", ListBuilder().Append(kAllHostsPermission).Pass()); |
325 ListBuilder().Append(kAllHostsPermission).Pass()); | 326 scoped_refptr<const Extension> no_urls_extension = |
326 const Extension* no_urls_extension = | |
327 CreateExtension("no urls", ListBuilder().Pass()); | 327 CreateExtension("no urls", ListBuilder().Pass()); |
328 | 328 |
329 scoped_ptr<base::DictionaryValue> value( | 329 scoped_ptr<base::DictionaryValue> value(handler()->CreateExtensionDetailValue( |
330 handler()->CreateExtensionDetailValue( | 330 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); |
331 all_urls_extension, std::vector<ExtensionPage>(), NULL)); | |
332 bool result = false; | 331 bool result = false; |
333 const std::string kWantsAllUrls = "wantsAllUrls"; | 332 const std::string kWantsAllUrls = "wantsAllUrls"; |
334 const std::string kAllowAllUrls = "allowAllUrls"; | 333 const std::string kAllowAllUrls = "allowAllUrls"; |
335 | 334 |
336 // The extension should want all urls, but not currently have it. | 335 // The extension should want all urls, but not currently have it. |
337 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); | 336 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); |
338 EXPECT_TRUE(result); | 337 EXPECT_TRUE(result); |
339 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 338 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
340 EXPECT_FALSE(result); | 339 EXPECT_FALSE(result); |
341 | 340 |
342 // Give the extension all urls. | 341 // Give the extension all urls. |
343 util::SetAllowedScriptingOnAllUrls( | 342 util::SetAllowedScriptingOnAllUrls( |
344 all_urls_extension->id(), profile(), true); | 343 all_urls_extension->id(), profile(), true); |
345 | 344 |
346 // Now the extension should both want and have all urls. | 345 // Now the extension should both want and have all urls. |
347 value.reset(handler()->CreateExtensionDetailValue( | 346 value.reset(handler()->CreateExtensionDetailValue( |
348 all_urls_extension, std::vector<ExtensionPage>(), NULL)); | 347 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); |
349 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); | 348 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); |
350 EXPECT_TRUE(result); | 349 EXPECT_TRUE(result); |
351 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 350 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
352 EXPECT_TRUE(result); | 351 EXPECT_TRUE(result); |
353 | 352 |
354 // The other extension should neither want nor have all urls. | 353 // The other extension should neither want nor have all urls. |
355 value.reset(handler()->CreateExtensionDetailValue( | 354 value.reset(handler()->CreateExtensionDetailValue( |
356 no_urls_extension, std::vector<ExtensionPage>(), NULL)); | 355 no_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); |
357 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); | 356 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); |
358 EXPECT_FALSE(result); | 357 EXPECT_FALSE(result); |
359 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 358 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
360 EXPECT_FALSE(result); | 359 EXPECT_FALSE(result); |
361 | 360 |
362 // Turn off the switch and load another extension (so permissions are | 361 // Turn off the switch and load another extension (so permissions are |
363 // re-initialized). | 362 // re-initialized). |
364 enable_scripts_switch.reset(); | 363 enable_scripts_switch.reset(); |
365 | 364 |
366 // Even though the extension has the all urls preference, the checkbox | 365 // Even though the extension has the all urls preference, the checkbox |
367 // shouldn't show up with the switch off. | 366 // shouldn't show up with the switch off. |
368 value.reset(handler()->CreateExtensionDetailValue( | 367 value.reset(handler()->CreateExtensionDetailValue( |
369 all_urls_extension, std::vector<ExtensionPage>(), NULL)); | 368 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); |
370 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); | 369 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); |
371 EXPECT_FALSE(result); | 370 EXPECT_FALSE(result); |
372 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 371 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
373 EXPECT_TRUE(result); | 372 EXPECT_TRUE(result); |
374 | 373 |
375 // Load another extension with all urls (so permissions get re-init'd). | 374 // Load another extension with all urls (so permissions get re-init'd). |
376 all_urls_extension = CreateExtension( | 375 all_urls_extension = CreateExtension( |
377 "all_urls_II", ListBuilder().Append(kAllHostsPermission).Pass()); | 376 "all_urls_II", ListBuilder().Append(kAllHostsPermission).Pass()); |
378 | 377 |
379 // Even though the extension has all_urls permission, the checkbox shouldn't | 378 // Even though the extension has all_urls permission, the checkbox shouldn't |
380 // show up without the switch. | 379 // show up without the switch. |
381 value.reset(handler()->CreateExtensionDetailValue( | 380 value.reset(handler()->CreateExtensionDetailValue( |
382 all_urls_extension, std::vector<ExtensionPage>(), NULL)); | 381 all_urls_extension.get(), std::vector<ExtensionPage>(), NULL)); |
383 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); | 382 EXPECT_TRUE(value->GetBoolean(kWantsAllUrls, &result)); |
384 EXPECT_FALSE(result); | 383 EXPECT_FALSE(result); |
385 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); | 384 EXPECT_TRUE(value->GetBoolean(kAllowAllUrls, &result)); |
386 EXPECT_FALSE(result); | 385 EXPECT_FALSE(result); |
387 } | 386 } |
388 | 387 |
389 } // namespace extensions | 388 } // namespace extensions |
OLD | NEW |