| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/convert_web_app.h" | 5 #include "chrome/browser/extensions/convert_web_app.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/scoped_temp_dir.h" | 13 #include "base/scoped_temp_dir.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "base/version.h" | 17 #include "base/version.h" |
| 18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
| 19 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_icon_set.h" | 20 #include "chrome/common/extensions/extension_icon_set.h" |
| 21 #include "chrome/common/extensions/extension_resource.h" | 21 #include "chrome/common/extensions/extension_resource.h" |
| 22 #include "chrome/common/extensions/url_pattern.h" | 22 #include "chrome/common/extensions/url_pattern.h" |
| 23 #include "chrome/common/web_apps.h" |
| 23 #include "gfx/codec/png_codec.h" | 24 #include "gfx/codec/png_codec.h" |
| 24 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "webkit/glue/dom_operations.h" | |
| 27 #include "webkit/glue/image_decoder.h" | 27 #include "webkit/glue/image_decoder.h" |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Returns an icon info corresponding to a canned icon. | 31 // Returns an icon info corresponding to a canned icon. |
| 32 webkit_glue::WebApplicationInfo::IconInfo GetIconInfo(const GURL& url, | 32 WebApplicationInfo::IconInfo GetIconInfo(const GURL& url, int size) { |
| 33 int size) { | 33 WebApplicationInfo::IconInfo result; |
| 34 webkit_glue::WebApplicationInfo::IconInfo result; | |
| 35 | 34 |
| 36 FilePath icon_file; | 35 FilePath icon_file; |
| 37 if (!PathService::Get(chrome::DIR_TEST_DATA, &icon_file)) { | 36 if (!PathService::Get(chrome::DIR_TEST_DATA, &icon_file)) { |
| 38 ADD_FAILURE() << "Could not get test data directory."; | 37 ADD_FAILURE() << "Could not get test data directory."; |
| 39 return result; | 38 return result; |
| 40 } | 39 } |
| 41 | 40 |
| 42 icon_file = icon_file.AppendASCII("extensions") | 41 icon_file = icon_file.AppendASCII("extensions") |
| 43 .AppendASCII("convert_web_app") | 42 .AppendASCII("convert_web_app") |
| 44 .AppendASCII(StringPrintf("%i.png", size)); | 43 .AppendASCII(StringPrintf("%i.png", size)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 GetTestTime(2010, 1, 1, 0, 0, 0, 0))); | 83 GetTestTime(2010, 1, 1, 0, 0, 0, 0))); |
| 85 EXPECT_EQ("2010.12.31.22111", | 84 EXPECT_EQ("2010.12.31.22111", |
| 86 ConvertTimeToExtensionVersion( | 85 ConvertTimeToExtensionVersion( |
| 87 GetTestTime(2010, 12, 31, 8, 5, 50, 500))); | 86 GetTestTime(2010, 12, 31, 8, 5, 50, 500))); |
| 88 EXPECT_EQ("2010.10.1.65535", | 87 EXPECT_EQ("2010.10.1.65535", |
| 89 ConvertTimeToExtensionVersion( | 88 ConvertTimeToExtensionVersion( |
| 90 GetTestTime(2010, 10, 1, 23, 59, 59, 999))); | 89 GetTestTime(2010, 10, 1, 23, 59, 59, 999))); |
| 91 } | 90 } |
| 92 | 91 |
| 93 TEST(ExtensionFromWebApp, Basic) { | 92 TEST(ExtensionFromWebApp, Basic) { |
| 94 webkit_glue::WebApplicationInfo web_app; | 93 WebApplicationInfo web_app; |
| 95 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); | 94 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); |
| 96 web_app.title = ASCIIToUTF16("Gearpad"); | 95 web_app.title = ASCIIToUTF16("Gearpad"); |
| 97 web_app.description = ASCIIToUTF16("The best text editor in the universe!"); | 96 web_app.description = ASCIIToUTF16("The best text editor in the universe!"); |
| 98 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); | 97 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 99 web_app.permissions.push_back("geolocation"); | 98 web_app.privileges.push_back("geolocation"); |
| 100 web_app.permissions.push_back("notifications"); | 99 web_app.privileges.push_back("notifications"); |
| 101 web_app.urls.push_back(GURL("http://aaronboodman.com/gearpad/")); | 100 web_app.urls.push_back(GURL("http://aaronboodman.com/gearpad/")); |
| 102 | 101 |
| 103 const int sizes[] = {16, 48, 128}; | 102 const int sizes[] = {16, 48, 128}; |
| 104 for (size_t i = 0; i < arraysize(sizes); ++i) { | 103 for (size_t i = 0; i < arraysize(sizes); ++i) { |
| 105 GURL icon_url(web_app.app_url.Resolve(StringPrintf("%i.png", sizes[i]))); | 104 GURL icon_url(web_app.app_url.Resolve(StringPrintf("%i.png", sizes[i]))); |
| 106 web_app.icons.push_back(GetIconInfo(icon_url, sizes[i])); | 105 web_app.icons.push_back(GetIconInfo(icon_url, sizes[i])); |
| 107 } | 106 } |
| 108 | 107 |
| 109 scoped_refptr<Extension> extension = ConvertWebAppToExtension( | 108 scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
| 110 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); | 109 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 137 extension->icons().Get(web_app.icons[i].width, | 136 extension->icons().Get(web_app.icons[i].width, |
| 138 ExtensionIconSet::MATCH_EXACTLY)); | 137 ExtensionIconSet::MATCH_EXACTLY)); |
| 139 ExtensionResource resource = extension->GetIconResource( | 138 ExtensionResource resource = extension->GetIconResource( |
| 140 web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY); | 139 web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY); |
| 141 ASSERT_TRUE(!resource.empty()); | 140 ASSERT_TRUE(!resource.empty()); |
| 142 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); | 141 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); |
| 143 } | 142 } |
| 144 } | 143 } |
| 145 | 144 |
| 146 TEST(ExtensionFromWebApp, Minimal) { | 145 TEST(ExtensionFromWebApp, Minimal) { |
| 147 webkit_glue::WebApplicationInfo web_app; | 146 WebApplicationInfo web_app; |
| 148 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); | 147 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); |
| 149 web_app.title = ASCIIToUTF16("Gearpad"); | 148 web_app.title = ASCIIToUTF16("Gearpad"); |
| 150 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); | 149 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 151 | 150 |
| 152 scoped_refptr<Extension> extension = ConvertWebAppToExtension( | 151 scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
| 153 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); | 152 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); |
| 154 ASSERT_TRUE(extension.get()); | 153 ASSERT_TRUE(extension.get()); |
| 155 | 154 |
| 156 ScopedTempDir extension_dir; | 155 ScopedTempDir extension_dir; |
| 157 extension_dir.Set(extension->path()); | 156 extension_dir.Set(extension->path()); |
| 158 | 157 |
| 159 EXPECT_TRUE(extension->is_app()); | 158 EXPECT_TRUE(extension->is_app()); |
| 160 EXPECT_TRUE(extension->is_hosted_app()); | 159 EXPECT_TRUE(extension->is_hosted_app()); |
| 161 EXPECT_FALSE(extension->is_packaged_app()); | 160 EXPECT_FALSE(extension->is_packaged_app()); |
| 162 | 161 |
| 163 EXPECT_EQ("lJqm1+jncOHClAuwif1QxNJKfeV9Fbl9IBZx7FkNwkA=", | 162 EXPECT_EQ("lJqm1+jncOHClAuwif1QxNJKfeV9Fbl9IBZx7FkNwkA=", |
| 164 extension->public_key()); | 163 extension->public_key()); |
| 165 EXPECT_EQ("ncnbaadanljoanockmphfdkimpdedemj", extension->id()); | 164 EXPECT_EQ("ncnbaadanljoanockmphfdkimpdedemj", extension->id()); |
| 166 EXPECT_EQ("1978.12.11.0", extension->version()->GetString()); | 165 EXPECT_EQ("1978.12.11.0", extension->version()->GetString()); |
| 167 EXPECT_EQ(UTF16ToUTF8(web_app.title), extension->name()); | 166 EXPECT_EQ(UTF16ToUTF8(web_app.title), extension->name()); |
| 168 EXPECT_EQ("", extension->description()); | 167 EXPECT_EQ("", extension->description()); |
| 169 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); | 168 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); |
| 170 EXPECT_EQ(0u, extension->icons().map().size()); | 169 EXPECT_EQ(0u, extension->icons().map().size()); |
| 171 EXPECT_EQ(0u, extension->api_permissions().size()); | 170 EXPECT_EQ(0u, extension->api_permissions().size()); |
| 172 ASSERT_EQ(1u, extension->web_extent().patterns().size()); | 171 ASSERT_EQ(1u, extension->web_extent().patterns().size()); |
| 173 EXPECT_EQ("*://aaronboodman.com/*", | 172 EXPECT_EQ("*://aaronboodman.com/*", |
| 174 extension->web_extent().patterns()[0].GetAsString()); | 173 extension->web_extent().patterns()[0].GetAsString()); |
| 175 } | 174 } |
| OLD | NEW |