[email protected] | bebe1d0 | 2012-08-02 20:17:09 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "chrome/browser/extensions/convert_web_app.h" |
| 6 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 9 | #include <memory> |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
thestig | 18dfb7a5 | 2014-08-26 10:44:04 | [diff] [blame] | 14 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 15 | #include "base/files/scoped_temp_dir.h" |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 16 | #include "base/path_service.h" |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame^] | 17 | #include "base/stl_util.h" |
[email protected] | 00e7bef | 2013-06-10 20:35:17 | [diff] [blame] | 18 | #include "base/strings/stringprintf.h" |
[email protected] | 112158af | 2013-06-07 23:46:18 | [diff] [blame] | 19 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 41a17c5 | 2013-06-28 00:27:53 | [diff] [blame] | 20 | #include "base/time/time.h" |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 21 | #include "base/version.h" |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 22 | #include "chrome/browser/extensions/bookmark_app_helper.h" |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 23 | #include "chrome/common/chrome_paths.h" |
[email protected] | 6b414c23 | 2013-06-05 07:53:34 | [diff] [blame] | 24 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
[email protected] | 93f5046 | 2013-05-10 04:40:40 | [diff] [blame] | 25 | #include "chrome/common/web_application_info.h" |
[email protected] | e4452d3 | 2013-11-15 23:07:41 | [diff] [blame] | 26 | #include "extensions/common/extension.h" |
[email protected] | 4b790884 | 2014-04-07 23:50:22 | [diff] [blame] | 27 | #include "extensions/common/extension_icon_set.h" |
[email protected] | 993da5e | 2013-03-23 21:25:16 | [diff] [blame] | 28 | #include "extensions/common/extension_resource.h" |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 29 | #include "extensions/common/manifest_constants.h" |
[email protected] | 0db486f | 2014-04-09 19:32:22 | [diff] [blame] | 30 | #include "extensions/common/manifest_handlers/icons_handler.h" |
[email protected] | 5a55f3f | 2013-10-29 01:08:29 | [diff] [blame] | 31 | #include "extensions/common/permissions/permission_set.h" |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 32 | #include "extensions/common/permissions/permissions_data.h" |
[email protected] | 885c0e9 | 2012-11-13 20:27:42 | [diff] [blame] | 33 | #include "extensions/common/url_pattern.h" |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 34 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 35 | #include "ui/gfx/codec/png_codec.h" |
[email protected] | a6483d2 | 2013-07-03 22:11:00 | [diff] [blame] | 36 | #include "url/gurl.h" |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 37 | |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 38 | namespace extensions { |
| 39 | |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 40 | namespace keys = manifest_keys; |
| 41 | |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | // Returns an icon info corresponding to a canned icon. |
| 45 | WebApplicationInfo::IconInfo GetIconInfo(const GURL& url, int size) { |
| 46 | WebApplicationInfo::IconInfo result; |
| 47 | |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 48 | base::FilePath icon_file; |
Avi Drissman | 9098f900 | 2018-05-04 00:11:52 | [diff] [blame] | 49 | if (!base::PathService::Get(chrome::DIR_TEST_DATA, &icon_file)) { |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 50 | ADD_FAILURE() << "Could not get test data directory."; |
| 51 | return result; |
| 52 | } |
| 53 | |
| 54 | icon_file = icon_file.AppendASCII("extensions") |
| 55 | .AppendASCII("convert_web_app") |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 56 | .AppendASCII(base::StringPrintf("%i.png", size)); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 57 | |
| 58 | result.url = url; |
| 59 | result.width = size; |
| 60 | result.height = size; |
| 61 | |
| 62 | std::string icon_data; |
[email protected] | 82f84b9 | 2013-08-30 18:23:50 | [diff] [blame] | 63 | if (!base::ReadFileToString(icon_file, &icon_data)) { |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 64 | ADD_FAILURE() << "Could not read test icon."; |
| 65 | return result; |
| 66 | } |
| 67 | |
[email protected] | da87eec2 | 2013-05-14 09:25:28 | [diff] [blame] | 68 | if (!gfx::PNGCodec::Decode( |
| 69 | reinterpret_cast<const unsigned char*>(icon_data.c_str()), |
| 70 | icon_data.size(), &result.data)) { |
| 71 | ADD_FAILURE() << "Could not decode test icon."; |
| 72 | return result; |
| 73 | } |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 74 | |
| 75 | return result; |
| 76 | } |
| 77 | |
| 78 | base::Time GetTestTime(int year, int month, int day, int hour, int minute, |
| 79 | int second, int millisecond) { |
| 80 | base::Time::Exploded exploded = {0}; |
| 81 | exploded.year = year; |
| 82 | exploded.month = month; |
| 83 | exploded.day_of_month = day; |
| 84 | exploded.hour = hour; |
| 85 | exploded.minute = minute; |
| 86 | exploded.second = second; |
| 87 | exploded.millisecond = millisecond; |
maksim.sisov | b4dbc73d | 2016-07-07 09:17:27 | [diff] [blame] | 88 | base::Time out_time; |
| 89 | EXPECT_TRUE(base::Time::FromUTCExploded(exploded, &out_time)); |
| 90 | return out_time; |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | } // namespace |
| 94 | |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 95 | TEST(ExtensionFromWebApp, GetScopeURLFromBookmarkApp) { |
| 96 | base::ScopedTempDir extensions_dir; |
| 97 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 98 | |
| 99 | base::DictionaryValue manifest; |
| 100 | manifest.SetString(keys::kName, "Test App"); |
| 101 | manifest.SetString(keys::kVersion, "0"); |
| 102 | manifest.SetString(keys::kLaunchWebURL, "http://aaronboodman.com/gearpad/"); |
| 103 | |
| 104 | // Create a "url_handlers" dictionary with one URL handler generated from |
| 105 | // the scope. |
| 106 | // { |
| 107 | // "scope": { |
| 108 | // "matches": [ "http://aaronboodman.com/gearpad/*" ], |
| 109 | // "title": "Test App" |
| 110 | // }, |
| 111 | // } |
| 112 | GURL scope_url = GURL("http://aaronboodman.com/gearpad/"); |
| 113 | manifest.SetDictionary(keys::kUrlHandlers, |
| 114 | CreateURLHandlersForBookmarkApp( |
| 115 | scope_url, base::ASCIIToUTF16("Test App"))); |
| 116 | |
| 117 | std::string error; |
| 118 | scoped_refptr<Extension> bookmark_app = |
| 119 | Extension::Create(extensions_dir.GetPath(), Manifest::INTERNAL, manifest, |
| 120 | Extension::FROM_BOOKMARK, &error); |
| 121 | ASSERT_TRUE(bookmark_app.get()); |
| 122 | |
| 123 | EXPECT_EQ(scope_url, GetScopeURLFromBookmarkApp(bookmark_app.get())); |
| 124 | } |
| 125 | |
| 126 | TEST(ExtensionFromWebApp, GetScopeURLFromBookmarkApp_NoURLHandlers) { |
| 127 | base::ScopedTempDir extensions_dir; |
| 128 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 129 | |
| 130 | base::DictionaryValue manifest; |
| 131 | manifest.SetString(keys::kName, "Test App"); |
| 132 | manifest.SetString(keys::kVersion, "0"); |
| 133 | manifest.SetString(keys::kLaunchWebURL, "http://aaronboodman.com/gearpad/"); |
| 134 | manifest.SetDictionary(keys::kUrlHandlers, |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 135 | std::make_unique<base::DictionaryValue>()); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 136 | |
| 137 | std::string error; |
| 138 | scoped_refptr<Extension> bookmark_app = |
| 139 | Extension::Create(extensions_dir.GetPath(), Manifest::INTERNAL, manifest, |
| 140 | Extension::FROM_BOOKMARK, &error); |
| 141 | ASSERT_TRUE(bookmark_app.get()); |
| 142 | |
| 143 | EXPECT_EQ(GURL(), GetScopeURLFromBookmarkApp(bookmark_app.get())); |
| 144 | } |
| 145 | |
| 146 | TEST(ExtensionFromWebApp, GetScopeURLFromBookmarkApp_WrongURLHandler) { |
| 147 | base::ScopedTempDir extensions_dir; |
| 148 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 149 | |
| 150 | base::DictionaryValue manifest; |
| 151 | manifest.SetString(keys::kName, "Test App"); |
| 152 | manifest.SetString(keys::kVersion, "0"); |
| 153 | manifest.SetString(keys::kLaunchWebURL, "http://aaronboodman.com/gearpad/"); |
| 154 | |
| 155 | // Create a "url_handlers" dictionary with one URL handler not generated |
| 156 | // from the scope. |
| 157 | // { |
| 158 | // "test_url_handler": { |
| 159 | // "matches": [ "http://*.aaronboodman.com/" ], |
| 160 | // "title": "test handler" |
| 161 | // } |
| 162 | // } |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 163 | auto test_matches = std::make_unique<base::ListValue>(); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 164 | test_matches->AppendString("http://*.aaronboodman.com/"); |
| 165 | |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 166 | auto test_handler = std::make_unique<base::DictionaryValue>(); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 167 | test_handler->SetList(keys::kMatches, std::move(test_matches)); |
| 168 | test_handler->SetString(keys::kUrlHandlerTitle, "test handler"); |
| 169 | |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 170 | auto url_handlers = std::make_unique<base::DictionaryValue>(); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 171 | url_handlers->SetDictionary("test_url_handler", std::move(test_handler)); |
| 172 | manifest.SetDictionary(keys::kUrlHandlers, std::move(url_handlers)); |
| 173 | |
| 174 | std::string error; |
| 175 | scoped_refptr<Extension> bookmark_app = |
| 176 | Extension::Create(extensions_dir.GetPath(), Manifest::INTERNAL, manifest, |
| 177 | Extension::FROM_BOOKMARK, &error); |
| 178 | ASSERT_TRUE(bookmark_app.get()); |
| 179 | |
| 180 | EXPECT_EQ(GURL(), GetScopeURLFromBookmarkApp(bookmark_app.get())); |
| 181 | } |
| 182 | |
| 183 | TEST(ExtensionFromWebApp, GetScopeURLFromBookmarkApp_ExtraURLHandler) { |
| 184 | base::ScopedTempDir extensions_dir; |
| 185 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 186 | |
| 187 | base::DictionaryValue manifest; |
| 188 | manifest.SetString(keys::kName, "Test App"); |
| 189 | manifest.SetString(keys::kVersion, "0"); |
| 190 | manifest.SetString(keys::kLaunchWebURL, "http://aaronboodman.com/gearpad/"); |
| 191 | |
| 192 | // Create a "url_handlers" dictionary with two URL handlers. One for |
| 193 | // the scope and and extra one for testing. |
| 194 | // { |
| 195 | // "scope": { |
| 196 | // "matches": [ "http://aaronboodman.com/gearpad/*" ], |
| 197 | // "title": "Test App" |
| 198 | // }, |
| 199 | // "test_url_handler": { |
| 200 | // "matches": [ "http://*.aaronboodman.com/" ], |
| 201 | // "title": "test handler" |
| 202 | // } |
| 203 | // } |
| 204 | GURL scope_url = GURL("http://aaronboodman.com/gearpad/"); |
| 205 | std::unique_ptr<base::DictionaryValue> url_handlers = |
| 206 | CreateURLHandlersForBookmarkApp(scope_url, |
| 207 | base::ASCIIToUTF16("Test App")); |
| 208 | |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 209 | auto test_matches = std::make_unique<base::ListValue>(); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 210 | test_matches->AppendString("http://*.aaronboodman.com/"); |
| 211 | |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 212 | auto test_handler = std::make_unique<base::DictionaryValue>(); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 213 | test_handler->SetList(keys::kMatches, std::move(test_matches)); |
| 214 | test_handler->SetString(keys::kUrlHandlerTitle, "test handler"); |
| 215 | |
| 216 | url_handlers->SetDictionary("test_url_handler", std::move(test_handler)); |
| 217 | manifest.SetDictionary(keys::kUrlHandlers, std::move(url_handlers)); |
| 218 | |
| 219 | std::string error; |
| 220 | scoped_refptr<Extension> bookmark_app = |
| 221 | Extension::Create(extensions_dir.GetPath(), Manifest::INTERNAL, manifest, |
| 222 | Extension::FROM_BOOKMARK, &error); |
| 223 | ASSERT_TRUE(bookmark_app.get()); |
| 224 | |
| 225 | // Check that we can retrieve the scope even if there is an extra |
| 226 | // url handler. |
| 227 | EXPECT_EQ(scope_url, GetScopeURLFromBookmarkApp(bookmark_app.get())); |
| 228 | } |
| 229 | |
[email protected] | d592b1bd | 2013-05-06 06:40:47 | [diff] [blame] | 230 | TEST(ExtensionFromWebApp, GenerateVersion) { |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 231 | EXPECT_EQ("2010.1.1.0", |
| 232 | ConvertTimeToExtensionVersion( |
| 233 | GetTestTime(2010, 1, 1, 0, 0, 0, 0))); |
| 234 | EXPECT_EQ("2010.12.31.22111", |
| 235 | ConvertTimeToExtensionVersion( |
| 236 | GetTestTime(2010, 12, 31, 8, 5, 50, 500))); |
| 237 | EXPECT_EQ("2010.10.1.65535", |
| 238 | ConvertTimeToExtensionVersion( |
| 239 | GetTestTime(2010, 10, 1, 23, 59, 59, 999))); |
| 240 | } |
| 241 | |
[email protected] | d592b1bd | 2013-05-06 06:40:47 | [diff] [blame] | 242 | TEST(ExtensionFromWebApp, Basic) { |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 243 | base::ScopedTempDir extensions_dir; |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 244 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 245 | |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 246 | WebApplicationInfo web_app; |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 247 | web_app.title = base::ASCIIToUTF16("Gearpad"); |
| 248 | web_app.description = |
| 249 | base::ASCIIToUTF16("The best text editor in the universe!"); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 250 | web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 251 | web_app.scope = GURL("http://aaronboodman.com/gearpad/"); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 252 | |
| 253 | const int sizes[] = {16, 48, 128}; |
Avi Drissman | 5f0fb8c | 2018-12-25 23:20:49 | [diff] [blame^] | 254 | for (size_t i = 0; i < base::size(sizes); ++i) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 255 | GURL icon_url( |
| 256 | web_app.app_url.Resolve(base::StringPrintf("%i.png", sizes[i]))); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 257 | web_app.icons.push_back(GetIconInfo(icon_url, sizes[i])); |
| 258 | } |
| 259 | |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 260 | scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 261 | web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), extensions_dir.GetPath(), |
| 262 | Extension::NO_FLAGS, Manifest::INTERNAL); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 263 | ASSERT_TRUE(extension.get()); |
| 264 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 265 | base::ScopedTempDir extension_dir; |
[email protected] | 2d57f5d | 2011-01-13 14:20:12 | [diff] [blame] | 266 | EXPECT_TRUE(extension_dir.Set(extension->path())); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 267 | |
| 268 | EXPECT_TRUE(extension->is_app()); |
| 269 | EXPECT_TRUE(extension->is_hosted_app()); |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 270 | EXPECT_TRUE(extension->from_bookmark()); |
[email protected] | c4f459d | 2012-09-28 04:40:10 | [diff] [blame] | 271 | EXPECT_FALSE(extension->is_legacy_packaged_app()); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 272 | |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 273 | EXPECT_FALSE(extension->was_installed_by_default()); |
| 274 | EXPECT_FALSE(extension->was_installed_by_oem()); |
| 275 | EXPECT_FALSE(extension->from_webstore()); |
| 276 | EXPECT_EQ(Manifest::INTERNAL, extension->location()); |
| 277 | |
[email protected] | f8bbf6b | 2014-01-30 07:23:27 | [diff] [blame] | 278 | EXPECT_EQ("zVvdNZy3Mp7CFU8JVSyXNlDuHdVLbP7fDO3TGVzj/0w=", |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 279 | extension->public_key()); |
[email protected] | f8bbf6b | 2014-01-30 07:23:27 | [diff] [blame] | 280 | EXPECT_EQ("oplhagaaipaimkjlbekcdjkffijdockj", extension->id()); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 281 | EXPECT_EQ("1978.12.11.0", extension->version().GetString()); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 282 | EXPECT_EQ(base::UTF16ToUTF8(web_app.title), extension->name()); |
| 283 | EXPECT_EQ(base::UTF16ToUTF8(web_app.description), extension->description()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 284 | EXPECT_EQ(web_app.app_url, AppLaunchInfo::GetFullLaunchURL(extension.get())); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 285 | EXPECT_EQ(web_app.scope, GetScopeURLFromBookmarkApp(extension.get())); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 286 | EXPECT_EQ(0u, |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 287 | extension->permissions_data()->active_permissions().apis().size()); |
[email protected] | f8bbf6b | 2014-01-30 07:23:27 | [diff] [blame] | 288 | ASSERT_EQ(0u, extension->web_extent().patterns().size()); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 289 | |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 290 | EXPECT_EQ(web_app.icons.size(), |
| 291 | IconsInfo::GetIcons(extension.get()).map().size()); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 292 | for (size_t i = 0; i < web_app.icons.size(); ++i) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 293 | EXPECT_EQ(base::StringPrintf("icons/%i.png", web_app.icons[i].width), |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 294 | IconsInfo::GetIcons(extension.get()).Get( |
[email protected] | 702d8b4 | 2013-02-27 20:55:50 | [diff] [blame] | 295 | web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY)); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 296 | ExtensionResource resource = |
| 297 | IconsInfo::GetIconResource(extension.get(), |
| 298 | web_app.icons[i].width, |
| 299 | ExtensionIconSet::MATCH_EXACTLY); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 300 | ASSERT_TRUE(!resource.empty()); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 301 | EXPECT_TRUE(base::PathExists(resource.GetFilePath())); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 302 | } |
| 303 | } |
| 304 | |
[email protected] | d592b1bd | 2013-05-06 06:40:47 | [diff] [blame] | 305 | TEST(ExtensionFromWebApp, Minimal) { |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 306 | base::ScopedTempDir extensions_dir; |
[email protected] | 171ab92d | 2012-10-19 01:16:34 | [diff] [blame] | 307 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 308 | |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 309 | WebApplicationInfo web_app; |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 310 | web_app.title = base::ASCIIToUTF16("Gearpad"); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 311 | web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 312 | |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 313 | scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 314 | web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), extensions_dir.GetPath(), |
| 315 | Extension::NO_FLAGS, Manifest::INTERNAL); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 316 | ASSERT_TRUE(extension.get()); |
| 317 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 318 | base::ScopedTempDir extension_dir; |
[email protected] | 2d57f5d | 2011-01-13 14:20:12 | [diff] [blame] | 319 | EXPECT_TRUE(extension_dir.Set(extension->path())); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 320 | |
| 321 | EXPECT_TRUE(extension->is_app()); |
| 322 | EXPECT_TRUE(extension->is_hosted_app()); |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 323 | EXPECT_TRUE(extension->from_bookmark()); |
[email protected] | c4f459d | 2012-09-28 04:40:10 | [diff] [blame] | 324 | EXPECT_FALSE(extension->is_legacy_packaged_app()); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 325 | |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 326 | EXPECT_FALSE(extension->was_installed_by_default()); |
| 327 | EXPECT_FALSE(extension->was_installed_by_oem()); |
| 328 | EXPECT_FALSE(extension->from_webstore()); |
| 329 | EXPECT_EQ(Manifest::INTERNAL, extension->location()); |
| 330 | |
[email protected] | f8bbf6b | 2014-01-30 07:23:27 | [diff] [blame] | 331 | EXPECT_EQ("zVvdNZy3Mp7CFU8JVSyXNlDuHdVLbP7fDO3TGVzj/0w=", |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 332 | extension->public_key()); |
[email protected] | f8bbf6b | 2014-01-30 07:23:27 | [diff] [blame] | 333 | EXPECT_EQ("oplhagaaipaimkjlbekcdjkffijdockj", extension->id()); |
Devlin Cronin | 03bf2d2 | 2017-12-20 08:21:05 | [diff] [blame] | 334 | EXPECT_EQ("1978.12.11.0", extension->version().GetString()); |
[email protected] | 0433872 | 2013-12-24 23:18:05 | [diff] [blame] | 335 | EXPECT_EQ(base::UTF16ToUTF8(web_app.title), extension->name()); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 336 | EXPECT_EQ("", extension->description()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 337 | EXPECT_EQ(web_app.app_url, AppLaunchInfo::GetFullLaunchURL(extension.get())); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 338 | EXPECT_TRUE(GetScopeURLFromBookmarkApp(extension.get()).is_empty()); |
[email protected] | dc24976f | 2013-06-02 21:15:09 | [diff] [blame] | 339 | EXPECT_EQ(0u, IconsInfo::GetIcons(extension.get()).map().size()); |
[email protected] | 076ebeda | 2014-06-06 21:47:26 | [diff] [blame] | 340 | EXPECT_EQ(0u, |
rdevlin.cronin | d630c30 | 2015-09-30 20:19:33 | [diff] [blame] | 341 | extension->permissions_data()->active_permissions().apis().size()); |
[email protected] | f8bbf6b | 2014-01-30 07:23:27 | [diff] [blame] | 342 | ASSERT_EQ(0u, extension->web_extent().patterns().size()); |
[email protected] | 5ba5dab | 2010-11-18 02:31:04 | [diff] [blame] | 343 | } |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 344 | |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 345 | TEST(ExtensionFromWebApp, ExtraInstallationFlags) { |
| 346 | base::ScopedTempDir extensions_dir; |
| 347 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 348 | |
| 349 | WebApplicationInfo web_app; |
| 350 | web_app.title = base::ASCIIToUTF16("Gearpad"); |
| 351 | web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 352 | |
| 353 | scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
| 354 | web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), extensions_dir.GetPath(), |
| 355 | Extension::FROM_WEBSTORE | Extension::WAS_INSTALLED_BY_OEM, |
| 356 | Manifest::INTERNAL); |
| 357 | ASSERT_TRUE(extension.get()); |
| 358 | |
| 359 | EXPECT_TRUE(extension->is_app()); |
| 360 | EXPECT_TRUE(extension->is_hosted_app()); |
| 361 | EXPECT_TRUE(extension->from_bookmark()); |
| 362 | EXPECT_FALSE(extension->is_legacy_packaged_app()); |
| 363 | |
| 364 | EXPECT_TRUE(extension->was_installed_by_oem()); |
| 365 | EXPECT_TRUE(extension->from_webstore()); |
| 366 | EXPECT_FALSE(extension->was_installed_by_default()); |
| 367 | EXPECT_EQ(Manifest::INTERNAL, extension->location()); |
| 368 | } |
| 369 | |
| 370 | TEST(ExtensionFromWebApp, ExternalPolicyLocation) { |
| 371 | base::ScopedTempDir extensions_dir; |
| 372 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 373 | |
| 374 | WebApplicationInfo web_app; |
| 375 | web_app.title = base::ASCIIToUTF16("Gearpad"); |
| 376 | web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 377 | |
| 378 | scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
| 379 | web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), extensions_dir.GetPath(), |
| 380 | Extension::NO_FLAGS, Manifest::EXTERNAL_POLICY); |
| 381 | ASSERT_TRUE(extension.get()); |
| 382 | |
| 383 | EXPECT_TRUE(extension->is_app()); |
| 384 | EXPECT_TRUE(extension->is_hosted_app()); |
| 385 | EXPECT_TRUE(extension->from_bookmark()); |
| 386 | EXPECT_FALSE(extension->is_legacy_packaged_app()); |
| 387 | |
| 388 | EXPECT_EQ(Manifest::EXTERNAL_POLICY, extension->location()); |
| 389 | } |
| 390 | |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 391 | // Tests that a scope not ending in "/" works correctly. |
| 392 | // The tested behavior is unexpected but is working correctly according |
| 393 | // to the Web Manifest spec. https://github.com/w3c/manifest/issues/554 |
| 394 | TEST(ExtensionFromWebApp, ScopeDoesNotEndInSlash) { |
| 395 | base::ScopedTempDir extensions_dir; |
| 396 | ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 397 | |
| 398 | WebApplicationInfo web_app; |
| 399 | web_app.title = base::ASCIIToUTF16("Gearpad"); |
| 400 | web_app.description = |
| 401 | base::ASCIIToUTF16("The best text editor in the universe!"); |
| 402 | web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 403 | web_app.scope = GURL("http://aaronboodman.com/gear"); |
| 404 | |
| 405 | scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
Giovanni Ortuño Urquidi | 1e567fd | 2018-08-13 07:04:56 | [diff] [blame] | 406 | web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), extensions_dir.GetPath(), |
| 407 | Extension::NO_FLAGS, Manifest::INTERNAL); |
Giovanni Ortuño Urquidi | e7e79d45 | 2017-08-03 10:16:15 | [diff] [blame] | 408 | ASSERT_TRUE(extension.get()); |
| 409 | EXPECT_EQ(web_app.scope, GetScopeURLFromBookmarkApp(extension.get())); |
| 410 | } |
| 411 | |
[email protected] | b1912d59 | 2012-08-17 22:29:38 | [diff] [blame] | 412 | } // namespace extensions |