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 "chrome/browser/extensions/extension_install_prompt_show_params.h" | 9 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 new PermissionSet(api_permissions, | 46 new PermissionSet(api_permissions, |
47 ManifestPermissionSet(), | 47 ManifestPermissionSet(), |
48 URLPatternSet(), | 48 URLPatternSet(), |
49 URLPatternSet()); | 49 URLPatternSet()); |
50 scoped_refptr<const Extension> extension = | 50 scoped_refptr<const Extension> extension = |
51 ExtensionBuilder().SetManifest( | 51 ExtensionBuilder().SetManifest( |
52 DictionaryBuilder().Set("name", "foo") | 52 DictionaryBuilder().Set("name", "foo") |
53 .Set("version", "1.0") | 53 .Set("version", "1.0") |
54 .Set("manifest_version", 2) | 54 .Set("manifest_version", 2) |
55 .Set("description", "Random Ext")).Build(); | 55 .Set("description", "Random Ext")).Build(); |
56 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */); | 56 ExtensionInstallPrompt prompt(nullptr /* no web contents in this test */); |
57 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
58 prompt.set_callback_for_test( | 58 prompt.set_callback_for_test( |
59 base::Bind(&VerifyPromptPermissionsCallback, | 59 base::Bind(&VerifyPromptPermissionsCallback, |
60 run_loop.QuitClosure(), | 60 run_loop.QuitClosure(), |
61 1u, // |regular_permissions_count|. | 61 1u, // |regular_permissions_count|. |
62 0u)); // |withheld_permissions_count|. | 62 0u)); // |withheld_permissions_count|. |
63 prompt.ConfirmPermissions(NULL, // no delegate | 63 prompt.ConfirmPermissions(nullptr, // no delegate |
64 extension.get(), | 64 extension.get(), |
65 permission_set.get()); | 65 permission_set.get()); |
66 run_loop.Run(); | 66 run_loop.Run(); |
67 } | 67 } |
68 | 68 |
69 TEST(ExtensionInstallPromptUnittest, PromptShowsWithheldPermissions) { | 69 TEST(ExtensionInstallPromptUnittest, PromptShowsWithheldPermissions) { |
70 content::TestBrowserThreadBundle thread_bundle; | 70 content::TestBrowserThreadBundle thread_bundle; |
71 | 71 |
72 // Enable consent flag so that <all_hosts> permissions get withheld. | 72 // Enable consent flag so that <all_hosts> permissions get withheld. |
73 FeatureSwitch::ScopedOverride enable_scripts_switch( | 73 FeatureSwitch::ScopedOverride enable_scripts_switch( |
74 FeatureSwitch::scripts_require_action(), true); | 74 FeatureSwitch::scripts_require_action(), true); |
75 | 75 |
76 ListBuilder permissions; | 76 ListBuilder permissions; |
77 permissions.Append("http://*/*"); | 77 permissions.Append("http://*/*"); |
78 permissions.Append("http://www.google.com/"); | 78 permissions.Append("http://www.google.com/"); |
79 permissions.Append("tabs"); | 79 permissions.Append("tabs"); |
80 scoped_refptr<const Extension> extension = | 80 scoped_refptr<const Extension> extension = |
81 ExtensionBuilder().SetManifest( | 81 ExtensionBuilder().SetManifest( |
82 DictionaryBuilder().Set("name", "foo") | 82 DictionaryBuilder().Set("name", "foo") |
83 .Set("version", "1.0") | 83 .Set("version", "1.0") |
84 .Set("manifest_version", 2) | 84 .Set("manifest_version", 2) |
85 .Set("description", "Random Ext") | 85 .Set("description", "Random Ext") |
86 .Set("permissions", permissions)).Build(); | 86 .Set("permissions", permissions)).Build(); |
87 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */); | 87 ExtensionInstallPrompt prompt(nullptr /* no web contents in this test */); |
88 base::RunLoop run_loop; | 88 base::RunLoop run_loop; |
89 | 89 |
90 // We expect <all_hosts> to be withheld, but http://www.google.com/ and tabs | 90 // We expect <all_hosts> to be withheld, but http://www.google.com/ and tabs |
91 // permissions should be granted as regular permissions. | 91 // permissions should be granted as regular permissions. |
92 prompt.ConfirmInstall( | 92 prompt.ConfirmInstall( |
93 NULL, | 93 nullptr, |
94 extension.get(), | 94 extension.get(), |
95 base::Bind(&VerifyPromptPermissionsCallback, | 95 base::Bind(&VerifyPromptPermissionsCallback, |
96 run_loop.QuitClosure(), | 96 run_loop.QuitClosure(), |
97 2u, // |regular_permissions_count|. | 97 2u, // |regular_permissions_count|. |
98 1u)); // |withheld_permissions_count|. | 98 1u)); // |withheld_permissions_count|. |
99 run_loop.Run(); | 99 run_loop.Run(); |
100 } | 100 } |
101 | 101 |
102 TEST(ExtensionInstallPromptUnittest, DelegatedPromptShowsOptionalPermissions) { | |
103 content::TestBrowserThreadBundle thread_bundle; | |
104 ListBuilder required_permissions; | |
105 required_permissions.Append("tabs"); | |
106 ListBuilder optional_permissions; | |
107 optional_permissions.Append("location"); | |
not at google - send to devlin
2015/03/03 17:33:26
Could you inline all of these (I don't know why th
Marc Treib
2015/03/04 10:33:43
Done, also in the previous test.
| |
108 scoped_refptr<const Extension> extension = | |
109 ExtensionBuilder().SetManifest( | |
110 DictionaryBuilder().Set("name", "foo") | |
111 .Set("version", "1.0") | |
112 .Set("manifest_version", 2) | |
113 .Set("description", "Random Ext") | |
114 .Set("permissions", required_permissions) | |
not at google - send to devlin
2015/03/03 17:33:26
E.g.
.Set("permissions",
ListBuilder().Appe
Marc Treib
2015/03/04 10:33:43
Done.
| |
115 .Set("optional_permissions", | |
116 optional_permissions)).Build(); | |
117 ExtensionInstallPrompt prompt(nullptr /* no web contents in this test */); | |
118 base::RunLoop run_loop; | |
119 prompt.set_callback_for_test( | |
120 base::Bind(&VerifyPromptPermissionsCallback, | |
121 run_loop.QuitClosure(), | |
122 2u, // |regular_permissions_count|. | |
123 0u)); // |withheld_permissions_count|. | |
124 prompt.ConfirmPermissionsForDelegatedInstall(nullptr, // no delegate | |
125 extension.get(), | |
126 "Username", | |
127 nullptr); // no icon | |
128 run_loop.Run(); | |
129 } | |
130 | |
102 } // namespace extensions | 131 } // namespace extensions |
OLD | NEW |