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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/extensions/extension_install_prompt.h" | 10 #include "chrome/browser/extensions/extension_install_prompt.h" |
| 11 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" | 11 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
| 12 #include "chrome/browser/extensions/extension_service_test_with_install.h" | |
| 13 #include "chrome/browser/extensions/extension_util.h" | |
| 12 #include "chrome/test/base/testing_profile.h" | 14 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 14 #include "content/public/test/test_web_contents_factory.h" | 16 #include "content/public/test/test_web_contents_factory.h" |
| 17 #include "extensions/browser/image_loader.h" | |
| 18 #include "extensions/common/constants.h" | |
| 15 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/extension_builder.h" | 20 #include "extensions/common/extension_builder.h" |
| 17 #include "extensions/common/feature_switch.h" | 21 #include "extensions/common/feature_switch.h" |
| 22 #include "extensions/common/manifest_handlers/icons_handler.h" | |
| 18 #include "extensions/common/permissions/api_permission.h" | 23 #include "extensions/common/permissions/api_permission.h" |
| 19 #include "extensions/common/permissions/api_permission_set.h" | 24 #include "extensions/common/permissions/api_permission_set.h" |
| 20 #include "extensions/common/permissions/manifest_permission_set.h" | 25 #include "extensions/common/permissions/manifest_permission_set.h" |
| 21 #include "extensions/common/permissions/permission_set.h" | 26 #include "extensions/common/permissions/permission_set.h" |
| 22 #include "extensions/common/url_pattern_set.h" | 27 #include "extensions/common/url_pattern_set.h" |
| 23 #include "extensions/common/value_builder.h" | 28 #include "extensions/common/value_builder.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/gfx/skia_util.h" | |
| 25 | 31 |
| 26 namespace extensions { | 32 namespace extensions { |
| 27 | 33 |
| 28 namespace { | 34 namespace { |
| 29 | 35 |
| 36 void VerifyPromptIconCallback( | |
| 37 const base::Closure& quit_closure, | |
| 38 const SkBitmap& expected_bitmap, | |
| 39 ExtensionInstallPromptShowParams* params, | |
| 40 ExtensionInstallPrompt::Delegate* delegate, | |
| 41 scoped_ptr<ExtensionInstallPrompt::Prompt> prompt) { | |
| 42 EXPECT_TRUE(gfx::BitmapsAreEqual(prompt->icon().AsBitmap(), expected_bitmap)); | |
| 43 quit_closure.Run(); | |
| 44 } | |
| 45 | |
| 30 void VerifyPromptPermissionsCallback( | 46 void VerifyPromptPermissionsCallback( |
| 31 const base::Closure& quit_closure, | 47 const base::Closure& quit_closure, |
| 32 size_t regular_permissions_count, | 48 size_t regular_permissions_count, |
| 33 size_t withheld_permissions_count, | 49 size_t withheld_permissions_count, |
| 34 ExtensionInstallPromptShowParams* params, | 50 ExtensionInstallPromptShowParams* params, |
| 35 ExtensionInstallPrompt::Delegate* delegate, | 51 ExtensionInstallPrompt::Delegate* delegate, |
| 36 scoped_ptr<ExtensionInstallPrompt::Prompt> install_prompt) { | 52 scoped_ptr<ExtensionInstallPrompt::Prompt> install_prompt) { |
| 37 ASSERT_TRUE(install_prompt.get()); | 53 ASSERT_TRUE(install_prompt.get()); |
| 38 EXPECT_EQ(regular_permissions_count, | 54 EXPECT_EQ(regular_permissions_count, |
| 39 install_prompt->GetPermissionCount( | 55 install_prompt->GetPermissionCount( |
| 40 ExtensionInstallPrompt::REGULAR_PERMISSIONS)); | 56 ExtensionInstallPrompt::REGULAR_PERMISSIONS)); |
| 41 EXPECT_EQ(withheld_permissions_count, | 57 EXPECT_EQ(withheld_permissions_count, |
| 42 install_prompt->GetPermissionCount( | 58 install_prompt->GetPermissionCount( |
| 43 ExtensionInstallPrompt::WITHHELD_PERMISSIONS)); | 59 ExtensionInstallPrompt::WITHHELD_PERMISSIONS)); |
| 44 quit_closure.Run(); | 60 quit_closure.Run(); |
| 45 } | 61 } |
| 46 | 62 |
| 63 void SetImage(gfx::Image* image_out, | |
| 64 const base::Closure& quit_closure, | |
| 65 const gfx::Image& image_in) { | |
| 66 *image_out = image_in; | |
| 67 quit_closure.Run(); | |
| 68 } | |
| 69 | |
| 47 class ExtensionInstallPromptUnitTest : public testing::Test { | 70 class ExtensionInstallPromptUnitTest : public testing::Test { |
| 48 public: | 71 public: |
| 49 ExtensionInstallPromptUnitTest() {} | 72 ExtensionInstallPromptUnitTest() {} |
| 50 ~ExtensionInstallPromptUnitTest() override {} | 73 ~ExtensionInstallPromptUnitTest() override {} |
| 51 | 74 |
| 52 // testing::Test: | 75 // testing::Test: |
| 53 void SetUp() override { | 76 void SetUp() override { |
| 54 profile_.reset(new TestingProfile()); | 77 profile_.reset(new TestingProfile()); |
| 55 } | 78 } |
| 56 void TearDown() override { | 79 void TearDown() override { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 sub_prompt->set_delegated_username("Username"); | 177 sub_prompt->set_delegated_username("Username"); |
| 155 prompt.ShowDialog( | 178 prompt.ShowDialog( |
| 156 nullptr, // no delegate | 179 nullptr, // no delegate |
| 157 extension.get(), nullptr, sub_prompt.Pass(), | 180 extension.get(), nullptr, sub_prompt.Pass(), |
| 158 base::Bind(&VerifyPromptPermissionsCallback, run_loop.QuitClosure(), | 181 base::Bind(&VerifyPromptPermissionsCallback, run_loop.QuitClosure(), |
| 159 2u, // |regular_permissions_count|. | 182 2u, // |regular_permissions_count|. |
| 160 0u)); // |withheld_permissions_count|. | 183 0u)); // |withheld_permissions_count|. |
| 161 run_loop.Run(); | 184 run_loop.Run(); |
| 162 } | 185 } |
| 163 | 186 |
| 187 using ExtensionInstallPromptTestWithService = ExtensionServiceTestWithInstall; | |
| 188 | |
| 189 TEST_F(ExtensionInstallPromptTestWithService, ExtensionInstallPromptIconsTest) { | |
| 190 InitializeEmptyExtensionService(); | |
| 191 | |
| 192 const Extension* extension = PackAndInstallCRX( | |
| 193 data_dir().AppendASCII("simple_with_icon"), INSTALL_NEW); | |
| 194 ASSERT_TRUE(extension); | |
| 195 | |
| 196 std::vector<ImageLoader::ImageRepresentation> image_rep( | |
|
Devlin
2015/12/17 22:21:14
What a pain to look up an image! Maybe that's nex
asargent_no_longer_on_chrome
2015/12/17 22:40:40
Hmm, I guess it could be marginally better if you
Devlin
2015/12/21 17:07:33
Or it may be nice to have image loader do more of
| |
| 197 1, ImageLoader::ImageRepresentation( | |
| 198 IconsInfo::GetIconResource(extension, | |
| 199 extension_misc::EXTENSION_ICON_LARGE, | |
| 200 ExtensionIconSet::MATCH_BIGGER), | |
| 201 ImageLoader::ImageRepresentation::NEVER_RESIZE, gfx::Size(), | |
| 202 ui::SCALE_FACTOR_100P)); | |
| 203 base::RunLoop image_loop; | |
| 204 gfx::Image image; | |
| 205 ImageLoader::Get(browser_context()) | |
| 206 ->LoadImagesAsync( | |
| 207 extension, image_rep, | |
| 208 base::Bind(&SetImage, &image, image_loop.QuitClosure())); | |
| 209 image_loop.Run(); | |
| 210 ASSERT_FALSE(image.IsEmpty()); | |
| 211 content::TestWebContentsFactory factory; | |
| 212 content::WebContents* web_contents = | |
| 213 factory.CreateWebContents(browser_context()); | |
| 214 { | |
| 215 ExtensionInstallPrompt prompt(web_contents); | |
| 216 base::RunLoop run_loop; | |
| 217 prompt.ShowDialog(nullptr, // No delegate. | |
| 218 extension, | |
| 219 nullptr, // Force an icon fetch. | |
| 220 base::Bind(&VerifyPromptIconCallback, | |
| 221 run_loop.QuitClosure(), image.AsBitmap())); | |
| 222 run_loop.Run(); | |
| 223 } | |
| 224 | |
| 225 { | |
| 226 ExtensionInstallPrompt prompt(web_contents); | |
| 227 base::RunLoop run_loop; | |
| 228 gfx::ImageSkia app_icon = util::GetDefaultAppIcon(); | |
| 229 prompt.ShowDialog(nullptr, // No delegate. | |
| 230 extension, | |
| 231 app_icon.bitmap(), // Use a different icon. | |
| 232 base::Bind(&VerifyPromptIconCallback, | |
| 233 run_loop.QuitClosure(), *app_icon.bitmap())); | |
| 234 run_loop.Run(); | |
| 235 } | |
| 236 } | |
| 237 | |
| 164 } // namespace extensions | 238 } // namespace extensions |
| OLD | NEW |