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 "chrome/browser/extensions/bookmark_app_helper.h" | 5 #include "chrome/browser/extensions/bookmark_app_helper.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_service_test_base.h" | 9 #include "chrome/browser/extensions/extension_service_test_base.h" |
10 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 10 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
12 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
14 #include "content/public/test/web_contents_tester.h" | 14 #include "content/public/test/web_contents_tester.h" |
15 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
16 #include "extensions/common/constants.h" | 16 #include "extensions/common/constants.h" |
17 #include "extensions/common/extension_icon_set.h" | 17 #include "extensions/common/extension_icon_set.h" |
18 #include "extensions/common/manifest_handlers/icons_handler.h" | 18 #include "extensions/common/manifest_handlers/icons_handler.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/gfx/skia_util.h" | 21 #include "ui/gfx/skia_util.h" |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const char kAppUrl[] = "http://www.chromium.org"; | 25 const char kAppUrl[] = "http://www.chromium.org"; |
26 const char kAppTitle[] = "Test title"; | 26 const char kAppTitle[] = "Test title"; |
27 const char kAppShortName[] = "Test short name"; | |
27 const char kAlternativeAppTitle[] = "Different test title"; | 28 const char kAlternativeAppTitle[] = "Different test title"; |
28 const char kAppDescription[] = "Test description"; | 29 const char kAppDescription[] = "Test description"; |
29 | 30 |
30 const int kIconSizeTiny = extension_misc::EXTENSION_ICON_BITTY; | 31 const int kIconSizeTiny = extension_misc::EXTENSION_ICON_BITTY; |
31 const int kIconSizeSmall = extension_misc::EXTENSION_ICON_SMALL; | 32 const int kIconSizeSmall = extension_misc::EXTENSION_ICON_SMALL; |
32 const int kIconSizeMedium = extension_misc::EXTENSION_ICON_MEDIUM; | 33 const int kIconSizeMedium = extension_misc::EXTENSION_ICON_MEDIUM; |
33 const int kIconSizeLarge = extension_misc::EXTENSION_ICON_LARGE; | 34 const int kIconSizeLarge = extension_misc::EXTENSION_ICON_LARGE; |
34 | 35 |
35 class BookmarkAppHelperTest : public testing::Test { | 36 class BookmarkAppHelperTest : public testing::Test { |
36 public: | 37 public: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 content::WebContents* contents) | 123 content::WebContents* contents) |
123 : BookmarkAppHelper(service, web_app_info, contents) {} | 124 : BookmarkAppHelper(service, web_app_info, contents) {} |
124 | 125 |
125 virtual ~TestBookmarkAppHelper() {} | 126 virtual ~TestBookmarkAppHelper() {} |
126 | 127 |
127 void CreationComplete(const extensions::Extension* extension, | 128 void CreationComplete(const extensions::Extension* extension, |
128 const WebApplicationInfo& web_app_info) { | 129 const WebApplicationInfo& web_app_info) { |
129 extension_ = extension; | 130 extension_ = extension; |
130 } | 131 } |
131 | 132 |
133 void CompleteGetManifest(const content::Manifest& manifest) { | |
134 BookmarkAppHelper::OnDidGetManifest(manifest); | |
135 } | |
136 | |
132 void CompleteIconDownload( | 137 void CompleteIconDownload( |
133 bool success, | 138 bool success, |
134 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) { | 139 const std::map<GURL, std::vector<SkBitmap> >& bitmaps) { |
135 BookmarkAppHelper::OnIconsDownloaded(success, bitmaps); | 140 BookmarkAppHelper::OnIconsDownloaded(success, bitmaps); |
136 } | 141 } |
137 | 142 |
138 const Extension* extension() { return extension_; } | 143 const Extension* extension() { return extension_; } |
139 | 144 |
140 private: | 145 private: |
141 const Extension* extension_; | 146 const Extension* extension_; |
(...skipping 26 matching lines...) Expand all Loading... | |
168 EXPECT_EQ(1u, service_->extensions()->size()); | 173 EXPECT_EQ(1u, service_->extensions()->size()); |
169 EXPECT_TRUE(extension->from_bookmark()); | 174 EXPECT_TRUE(extension->from_bookmark()); |
170 EXPECT_EQ(kAppTitle, extension->name()); | 175 EXPECT_EQ(kAppTitle, extension->name()); |
171 EXPECT_EQ(kAppDescription, extension->description()); | 176 EXPECT_EQ(kAppDescription, extension->description()); |
172 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); | 177 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); |
173 EXPECT_FALSE( | 178 EXPECT_FALSE( |
174 IconsInfo::GetIconResource( | 179 IconsInfo::GetIconResource( |
175 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY).empty()); | 180 extension, kIconSizeSmall, ExtensionIconSet::MATCH_EXACTLY).empty()); |
176 } | 181 } |
177 | 182 |
183 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppWithManifest) { | |
184 WebApplicationInfo web_app_info; | |
calamity
2014/10/23 02:46:24
Maybe also supply a url and name here to ensure th
benwells
2014/10/23 03:50:09
OK, I did this in the UpdateWebAppInfoFromManifest
| |
185 | |
186 scoped_ptr<content::WebContents> contents( | |
187 content::WebContentsTester::CreateTestWebContents(profile_.get(), NULL)); | |
188 TestBookmarkAppHelper helper(service_, web_app_info, contents.get()); | |
189 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, | |
190 base::Unretained(&helper))); | |
191 | |
192 content::Manifest manifest; | |
193 manifest.start_url = GURL(kAppUrl); | |
194 manifest.name = base::NullableString16(base::UTF8ToUTF16(kAppTitle), false); | |
195 helper.CompleteGetManifest(manifest); | |
196 | |
197 std::map<GURL, std::vector<SkBitmap> > icon_map; | |
198 helper.CompleteIconDownload(true, icon_map); | |
199 | |
200 base::RunLoop().RunUntilIdle(); | |
201 EXPECT_TRUE(helper.extension()); | |
202 const Extension* extension = | |
203 service_->GetInstalledExtension(helper.extension()->id()); | |
204 EXPECT_TRUE(extension); | |
205 EXPECT_EQ(1u, service_->extensions()->size()); | |
206 EXPECT_TRUE(extension->from_bookmark()); | |
207 EXPECT_EQ(kAppTitle, extension->name()); | |
208 EXPECT_EQ(GURL(kAppUrl), AppLaunchInfo::GetLaunchWebURL(extension)); | |
209 } | |
210 | |
178 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppNoContents) { | 211 TEST_F(BookmarkAppHelperExtensionServiceTest, CreateBookmarkAppNoContents) { |
179 WebApplicationInfo web_app_info; | 212 WebApplicationInfo web_app_info; |
180 web_app_info.app_url = GURL(kAppUrl); | 213 web_app_info.app_url = GURL(kAppUrl); |
181 web_app_info.title = base::UTF8ToUTF16(kAppTitle); | 214 web_app_info.title = base::UTF8ToUTF16(kAppTitle); |
182 web_app_info.description = base::UTF8ToUTF16(kAppDescription); | 215 web_app_info.description = base::UTF8ToUTF16(kAppDescription); |
183 web_app_info.icons.push_back( | 216 web_app_info.icons.push_back( |
184 CreateIconInfoWithBitmap(kIconSizeTiny, SK_ColorRED)); | 217 CreateIconInfoWithBitmap(kIconSizeTiny, SK_ColorRED)); |
185 | 218 |
186 TestBookmarkAppHelper helper(service_, web_app_info, NULL); | 219 TestBookmarkAppHelper helper(service_, web_app_info, NULL); |
187 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, | 220 helper.Create(base::Bind(&TestBookmarkAppHelper::CreationComplete, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 EXPECT_EQ(1u, registry()->enabled_extensions().size()); | 312 EXPECT_EQ(1u, registry()->enabled_extensions().size()); |
280 base::RunLoop run_loop; | 313 base::RunLoop run_loop; |
281 extensions::GetWebApplicationInfoFromApp( | 314 extensions::GetWebApplicationInfoFromApp( |
282 profile_.get(), | 315 profile_.get(), |
283 service_->extensions()->begin()->get(), | 316 service_->extensions()->begin()->get(), |
284 base::Bind( | 317 base::Bind( |
285 &ValidateWebApplicationInfo, run_loop.QuitClosure(), web_app_info)); | 318 &ValidateWebApplicationInfo, run_loop.QuitClosure(), web_app_info)); |
286 run_loop.Run(); | 319 run_loop.Run(); |
287 } | 320 } |
288 | 321 |
322 TEST_F(BookmarkAppHelperTest, UpdateWebAppInfoFromManifest) { | |
323 WebApplicationInfo web_app_info; | |
324 content::Manifest manifest; | |
325 manifest.start_url = GURL(kAppUrl); | |
326 manifest.short_name = base::NullableString16(base::UTF8ToUTF16(kAppShortName), | |
327 false); | |
328 | |
329 BookmarkAppHelper::UpdateWebAppInfoFromManifest(manifest, &web_app_info); | |
330 EXPECT_EQ(base::UTF8ToUTF16(kAppShortName), web_app_info.title); | |
331 EXPECT_EQ(GURL(kAppUrl), web_app_info.app_url); | |
332 | |
333 // Test that |manifest.name| takes priority over |manifest.short_name| | |
334 manifest.name = base::NullableString16(base::UTF8ToUTF16(kAppTitle), false); | |
335 BookmarkAppHelper::UpdateWebAppInfoFromManifest(manifest, &web_app_info); | |
336 EXPECT_EQ(base::UTF8ToUTF16(kAppTitle), web_app_info.title); | |
337 } | |
338 | |
289 TEST_F(BookmarkAppHelperTest, ConstrainBitmapsToSizes) { | 339 TEST_F(BookmarkAppHelperTest, ConstrainBitmapsToSizes) { |
290 std::set<int> desired_sizes; | 340 std::set<int> desired_sizes; |
291 desired_sizes.insert(16); | 341 desired_sizes.insert(16); |
292 desired_sizes.insert(32); | 342 desired_sizes.insert(32); |
293 desired_sizes.insert(128); | 343 desired_sizes.insert(128); |
294 desired_sizes.insert(256); | 344 desired_sizes.insert(256); |
295 | 345 |
296 { | 346 { |
297 std::vector<SkBitmap> bitmaps; | 347 std::vector<SkBitmap> bitmaps; |
298 bitmaps.push_back(CreateSquareBitmapWithColor(16, SK_ColorRED)); | 348 bitmaps.push_back(CreateSquareBitmapWithColor(16, SK_ColorRED)); |
(...skipping 27 matching lines...) Expand all Loading... | |
326 } | 376 } |
327 | 377 |
328 TEST_F(BookmarkAppHelperTest, IsValidBookmarkAppUrl) { | 378 TEST_F(BookmarkAppHelperTest, IsValidBookmarkAppUrl) { |
329 EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("https://www.chromium.org"))); | 379 EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("https://www.chromium.org"))); |
330 EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("http://www.chromium.org/path"))); | 380 EXPECT_TRUE(IsValidBookmarkAppUrl(GURL("http://www.chromium.org/path"))); |
331 EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("ftp://www.chromium.org"))); | 381 EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("ftp://www.chromium.org"))); |
332 EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("chrome://flags"))); | 382 EXPECT_FALSE(IsValidBookmarkAppUrl(GURL("chrome://flags"))); |
333 } | 383 } |
334 | 384 |
335 } // namespace extensions | 385 } // namespace extensions |
OLD | NEW |