Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "chrome/browser/extensions/extension_install_prompt.h" | 8 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 9 #include "content/public/test/test_browser_thread_bundle.h" | 9 #include "content/public/test/test_browser_thread_bundle.h" |
| 10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
| 11 #include "extensions/common/extension_builder.h" | 11 #include "extensions/common/extension_builder.h" |
| 12 #include "extensions/common/feature_switch.h" | |
| 12 #include "extensions/common/permissions/api_permission.h" | 13 #include "extensions/common/permissions/api_permission.h" |
| 13 #include "extensions/common/permissions/api_permission_set.h" | 14 #include "extensions/common/permissions/api_permission_set.h" |
| 14 #include "extensions/common/permissions/manifest_permission_set.h" | 15 #include "extensions/common/permissions/manifest_permission_set.h" |
| 15 #include "extensions/common/permissions/permission_set.h" | 16 #include "extensions/common/permissions/permission_set.h" |
| 16 #include "extensions/common/url_pattern_set.h" | 17 #include "extensions/common/url_pattern_set.h" |
| 17 #include "extensions/common/value_builder.h" | 18 #include "extensions/common/value_builder.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace extensions { | 21 namespace extensions { |
| 21 | 22 |
| 22 void VerifyPromptPermissionsCallback( | 23 void VerifyPromptPermissionsCallback( |
| 23 const base::Closure& quit_closure, | 24 const base::Closure& quit_closure, |
| 25 size_t regular_permissions_count, | |
| 26 size_t withheld_permissions_count, | |
| 24 const ExtensionInstallPrompt::ShowParams& params, | 27 const ExtensionInstallPrompt::ShowParams& params, |
| 25 ExtensionInstallPrompt::Delegate* delegate, | 28 ExtensionInstallPrompt::Delegate* delegate, |
| 26 scoped_refptr<ExtensionInstallPrompt::Prompt> install_prompt) { | 29 scoped_refptr<ExtensionInstallPrompt::Prompt> install_prompt) { |
| 27 ASSERT_TRUE(install_prompt.get()); | 30 ASSERT_TRUE(install_prompt.get()); |
| 28 EXPECT_EQ(1u, install_prompt->GetPermissionCount()); | 31 EXPECT_EQ(regular_permissions_count, |
| 32 install_prompt->GetPermissionCount( | |
| 33 ExtensionInstallPrompt::REGULAR_PERMISSIONS)); | |
| 34 EXPECT_EQ(withheld_permissions_count, | |
| 35 install_prompt->GetPermissionCount( | |
| 36 ExtensionInstallPrompt::WITHHELD_PERMISSIONS)); | |
| 29 quit_closure.Run(); | 37 quit_closure.Run(); |
| 30 } | 38 } |
| 31 | 39 |
| 32 TEST(ExtensionInstallPromptUnittest, PromptShowsPermissionWarnings) { | 40 TEST(ExtensionInstallPromptUnittest, PromptShowsPermissionWarnings) { |
| 33 content::TestBrowserThreadBundle thread_bundle; | 41 content::TestBrowserThreadBundle thread_bundle; |
| 34 APIPermissionSet api_permissions; | 42 APIPermissionSet api_permissions; |
| 35 api_permissions.insert(APIPermission::kTab); | 43 api_permissions.insert(APIPermission::kTab); |
| 36 scoped_refptr<PermissionSet> permission_set = | 44 scoped_refptr<PermissionSet> permission_set = |
| 37 new PermissionSet(api_permissions, | 45 new PermissionSet(api_permissions, |
| 38 ManifestPermissionSet(), | 46 ManifestPermissionSet(), |
| 39 URLPatternSet(), | 47 URLPatternSet(), |
| 40 URLPatternSet()); | 48 URLPatternSet()); |
| 41 scoped_refptr<const Extension> extension = | 49 scoped_refptr<const Extension> extension = |
| 42 ExtensionBuilder().SetManifest( | 50 ExtensionBuilder().SetManifest( |
| 43 DictionaryBuilder().Set("name", "foo") | 51 DictionaryBuilder().Set("name", "foo") |
| 44 .Set("version", "1.0") | 52 .Set("version", "1.0") |
| 45 .Set("manifest_version", 2) | 53 .Set("manifest_version", 2) |
| 46 .Set("description", "Random Ext")).Build(); | 54 .Set("description", "Random Ext")).Build(); |
| 47 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */); | 55 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */); |
| 48 base::RunLoop run_loop; | 56 base::RunLoop run_loop; |
| 49 prompt.set_callback_for_test(base::Bind(&VerifyPromptPermissionsCallback, | 57 prompt.set_callback_for_test(base::Bind(&VerifyPromptPermissionsCallback, |
| 50 run_loop.QuitClosure())); | 58 run_loop.QuitClosure(), |
| 59 1, // regular_permissions_count | |
|
Devlin
2014/09/11 21:18:53
nit 1u and 0u (size_ts).
gpdavis
2014/09/12 00:11:54
Done.
| |
| 60 0)); // withheld_permissions_count | |
| 51 prompt.ConfirmPermissions(NULL, // no delegate | 61 prompt.ConfirmPermissions(NULL, // no delegate |
| 52 extension.get(), | 62 extension.get(), |
| 53 permission_set.get()); | 63 permission_set.get()); |
| 54 run_loop.Run(); | 64 run_loop.Run(); |
| 55 } | 65 } |
| 56 | 66 |
| 67 TEST(ExtensionInstallPromptUnittest, PromptShowsWithheldPermissions) { | |
| 68 content::TestBrowserThreadBundle thread_bundle; | |
| 69 | |
| 70 // Enable consent flag so that <all_hosts> permissions get withheld. | |
| 71 scoped_ptr<FeatureSwitch::ScopedOverride> enable_scripts_switch( | |
|
Devlin
2014/09/11 21:18:53
This doesn't have to be a scoped_ptr (can be alive
gpdavis
2014/09/12 00:11:54
Done.
| |
| 72 new FeatureSwitch::ScopedOverride( | |
| 73 FeatureSwitch::scripts_require_action(), true)); | |
| 74 | |
| 75 ListBuilder permissions; | |
| 76 permissions.Append("http://*/*"); | |
| 77 permissions.Append("http://www.google.com/"); | |
| 78 permissions.Append("tabs"); | |
| 79 scoped_refptr<const Extension> extension = | |
| 80 ExtensionBuilder().SetManifest( | |
| 81 DictionaryBuilder().Set("name", "foo") | |
| 82 .Set("version", "1.0") | |
| 83 .Set("manifest_version", 2) | |
| 84 .Set("description", "Random Ext") | |
| 85 .Set("permissions", permissions)).Build(); | |
| 86 | |
| 87 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */); | |
| 88 base::RunLoop run_loop; | |
| 89 prompt.ConfirmExternalInstall( | |
|
Devlin
2014/09/11 21:18:53
External install's actually not the best candidate
gpdavis
2014/09/12 00:11:53
Well, ConfirmWebstoreInstall just calls ConfirmIns
Devlin
2014/09/12 00:26:45
Probably not, then. :) (Silly me, just looked the
gpdavis
2014/09/12 00:30:57
Sounds good!
| |
| 90 NULL, | |
| 91 extension.get(), | |
| 92 base::Bind(&VerifyPromptPermissionsCallback, | |
| 93 run_loop.QuitClosure(), | |
| 94 2, // regular_permissions_count | |
|
Devlin
2014/09/11 21:18:53
We should mention in a comment what the withheld/r
gpdavis
2014/09/12 00:11:54
Done.
| |
| 95 1), // withheld_permissions_count | |
| 96 new ExtensionInstallPrompt::Prompt( | |
| 97 ExtensionInstallPrompt::PERMISSIONS_PROMPT)); | |
| 98 run_loop.Run(); | |
| 99 } | |
| 100 | |
| 57 } // namespace extensions | 101 } // namespace extensions |
| OLD | NEW |