| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } // namespace | 96 } // namespace |
| 97 | 97 |
| 98 TEST_F(ExtensionInstallPromptUnitTest, PromptShowsPermissionWarnings) { | 98 TEST_F(ExtensionInstallPromptUnitTest, PromptShowsPermissionWarnings) { |
| 99 APIPermissionSet api_permissions; | 99 APIPermissionSet api_permissions; |
| 100 api_permissions.insert(APIPermission::kTab); | 100 api_permissions.insert(APIPermission::kTab); |
| 101 scoped_ptr<const PermissionSet> permission_set( | 101 scoped_ptr<const PermissionSet> permission_set( |
| 102 new PermissionSet(api_permissions, ManifestPermissionSet(), | 102 new PermissionSet(api_permissions, ManifestPermissionSet(), |
| 103 URLPatternSet(), URLPatternSet())); | 103 URLPatternSet(), URLPatternSet())); |
| 104 scoped_refptr<const Extension> extension = | 104 scoped_refptr<const Extension> extension = |
| 105 ExtensionBuilder() | 105 ExtensionBuilder() |
| 106 .SetManifest(std::move(DictionaryBuilder() | 106 .SetManifest(DictionaryBuilder() |
| 107 .Set("name", "foo") | 107 .Set("name", "foo") |
| 108 .Set("version", "1.0") | 108 .Set("version", "1.0") |
| 109 .Set("manifest_version", 2) | 109 .Set("manifest_version", 2) |
| 110 .Set("description", "Random Ext"))) | 110 .Set("description", "Random Ext") |
| 111 .Build()) |
| 111 .Build(); | 112 .Build(); |
| 112 | 113 |
| 113 content::TestWebContentsFactory factory; | 114 content::TestWebContentsFactory factory; |
| 114 ExtensionInstallPrompt prompt(factory.CreateWebContents(profile())); | 115 ExtensionInstallPrompt prompt(factory.CreateWebContents(profile())); |
| 115 base::RunLoop run_loop; | 116 base::RunLoop run_loop; |
| 116 prompt.ShowDialog( | 117 prompt.ShowDialog( |
| 117 ExtensionInstallPrompt::DoneCallback(), extension.get(), nullptr, | 118 ExtensionInstallPrompt::DoneCallback(), extension.get(), nullptr, |
| 118 make_scoped_ptr(new ExtensionInstallPrompt::Prompt( | 119 make_scoped_ptr(new ExtensionInstallPrompt::Prompt( |
| 119 ExtensionInstallPrompt::PERMISSIONS_PROMPT)), | 120 ExtensionInstallPrompt::PERMISSIONS_PROMPT)), |
| 120 std::move(permission_set), | 121 std::move(permission_set), |
| 121 base::Bind(&VerifyPromptPermissionsCallback, run_loop.QuitClosure(), | 122 base::Bind(&VerifyPromptPermissionsCallback, run_loop.QuitClosure(), |
| 122 1u, // |regular_permissions_count|. | 123 1u, // |regular_permissions_count|. |
| 123 0u)); // |withheld_permissions_count|. | 124 0u)); // |withheld_permissions_count|. |
| 124 run_loop.Run(); | 125 run_loop.Run(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 TEST_F(ExtensionInstallPromptUnitTest, PromptShowsWithheldPermissions) { | 128 TEST_F(ExtensionInstallPromptUnitTest, PromptShowsWithheldPermissions) { |
| 128 // Enable consent flag so that <all_hosts> permissions get withheld. | 129 // Enable consent flag so that <all_hosts> permissions get withheld. |
| 129 FeatureSwitch::ScopedOverride enable_scripts_switch( | 130 FeatureSwitch::ScopedOverride enable_scripts_switch( |
| 130 FeatureSwitch::scripts_require_action(), true); | 131 FeatureSwitch::scripts_require_action(), true); |
| 131 | 132 |
| 132 scoped_refptr<const Extension> extension = | 133 scoped_refptr<const Extension> extension = |
| 133 ExtensionBuilder() | 134 ExtensionBuilder() |
| 134 .SetManifest( | 135 .SetManifest( |
| 135 std::move(DictionaryBuilder() | 136 DictionaryBuilder() |
| 136 .Set("name", "foo") | 137 .Set("name", "foo") |
| 137 .Set("version", "1.0") | 138 .Set("version", "1.0") |
| 138 .Set("manifest_version", 2) | 139 .Set("manifest_version", 2) |
| 139 .Set("description", "Random Ext") | 140 .Set("description", "Random Ext") |
| 140 .Set("permissions", | 141 .Set("permissions", ListBuilder() |
| 141 std::move(ListBuilder() | 142 .Append("http://*/*") |
| 142 .Append("http://*/*") | 143 .Append("http://www.google.com/") |
| 143 .Append("http://www.google.com/") | 144 .Append("tabs") |
| 144 .Append("tabs"))))) | 145 .Build()) |
| 146 .Build()) |
| 145 .Build(); | 147 .Build(); |
| 146 | 148 |
| 147 content::TestWebContentsFactory factory; | 149 content::TestWebContentsFactory factory; |
| 148 ExtensionInstallPrompt prompt(factory.CreateWebContents(profile())); | 150 ExtensionInstallPrompt prompt(factory.CreateWebContents(profile())); |
| 149 base::RunLoop run_loop; | 151 base::RunLoop run_loop; |
| 150 | 152 |
| 151 // We expect <all_hosts> to be withheld, but http://www.google.com/ and tabs | 153 // We expect <all_hosts> to be withheld, but http://www.google.com/ and tabs |
| 152 // permissions should be granted as regular permissions. | 154 // permissions should be granted as regular permissions. |
| 153 prompt.ShowDialog( | 155 prompt.ShowDialog( |
| 154 ExtensionInstallPrompt::DoneCallback(), extension.get(), nullptr, | 156 ExtensionInstallPrompt::DoneCallback(), extension.get(), nullptr, |
| 155 base::Bind(&VerifyPromptPermissionsCallback, run_loop.QuitClosure(), | 157 base::Bind(&VerifyPromptPermissionsCallback, run_loop.QuitClosure(), |
| 156 2u, // |regular_permissions_count|. | 158 2u, // |regular_permissions_count|. |
| 157 1u)); // |withheld_permissions_count|. | 159 1u)); // |withheld_permissions_count|. |
| 158 run_loop.Run(); | 160 run_loop.Run(); |
| 159 } | 161 } |
| 160 | 162 |
| 161 TEST_F(ExtensionInstallPromptUnitTest, | 163 TEST_F(ExtensionInstallPromptUnitTest, |
| 162 DelegatedPromptShowsOptionalPermissions) { | 164 DelegatedPromptShowsOptionalPermissions) { |
| 163 scoped_refptr<const Extension> extension = | 165 scoped_refptr<const Extension> extension = |
| 164 ExtensionBuilder() | 166 ExtensionBuilder() |
| 165 .SetManifest(std::move( | 167 .SetManifest(DictionaryBuilder() |
| 166 DictionaryBuilder() | 168 .Set("name", "foo") |
| 167 .Set("name", "foo") | 169 .Set("version", "1.0") |
| 168 .Set("version", "1.0") | 170 .Set("manifest_version", 2) |
| 169 .Set("manifest_version", 2) | 171 .Set("description", "Random Ext") |
| 170 .Set("description", "Random Ext") | 172 .Set("permissions", |
| 171 .Set("permissions", | 173 ListBuilder().Append("clipboardRead").Build()) |
| 172 std::move(ListBuilder().Append("clipboardRead"))) | 174 .Set("optional_permissions", |
| 173 .Set("optional_permissions", | 175 ListBuilder().Append("tabs").Build()) |
| 174 std::move(ListBuilder().Append("tabs"))))) | 176 .Build()) |
| 175 .Build(); | 177 .Build(); |
| 176 | 178 |
| 177 content::TestWebContentsFactory factory; | 179 content::TestWebContentsFactory factory; |
| 178 ExtensionInstallPrompt prompt(factory.CreateWebContents(profile())); | 180 ExtensionInstallPrompt prompt(factory.CreateWebContents(profile())); |
| 179 base::RunLoop run_loop; | 181 base::RunLoop run_loop; |
| 180 | 182 |
| 181 scoped_ptr<ExtensionInstallPrompt::Prompt> sub_prompt( | 183 scoped_ptr<ExtensionInstallPrompt::Prompt> sub_prompt( |
| 182 new ExtensionInstallPrompt::Prompt( | 184 new ExtensionInstallPrompt::Prompt( |
| 183 ExtensionInstallPrompt::DELEGATED_PERMISSIONS_PROMPT)); | 185 ExtensionInstallPrompt::DELEGATED_PERMISSIONS_PROMPT)); |
| 184 sub_prompt->set_delegated_username("Username"); | 186 sub_prompt->set_delegated_username("Username"); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 prompt.ShowDialog(ExtensionInstallPrompt::DoneCallback(), | 238 prompt.ShowDialog(ExtensionInstallPrompt::DoneCallback(), |
| 237 extension, | 239 extension, |
| 238 app_icon.bitmap(), // Use a different icon. | 240 app_icon.bitmap(), // Use a different icon. |
| 239 base::Bind(&VerifyPromptIconCallback, | 241 base::Bind(&VerifyPromptIconCallback, |
| 240 run_loop.QuitClosure(), *app_icon.bitmap())); | 242 run_loop.QuitClosure(), *app_icon.bitmap())); |
| 241 run_loop.Run(); | 243 run_loop.Run(); |
| 242 } | 244 } |
| 243 } | 245 } |
| 244 | 246 |
| 245 } // namespace extensions | 247 } // namespace extensions |
| OLD | NEW |