| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/permissions/permission_set.h" | 22 #include "chrome/common/extensions/permissions/permission_set.h" |
| 23 #include "chrome/common/extensions/url_pattern.h" | 23 #include "chrome/common/extensions/url_pattern.h" |
| 24 #include "chrome/common/web_apps.h" | 24 #include "chrome/common/web_apps.h" |
| 25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "ui/gfx/codec/png_codec.h" | 27 #include "ui/gfx/codec/png_codec.h" |
| 28 #include "webkit/glue/image_decoder.h" | 28 #include "webkit/glue/image_decoder.h" |
| 29 | 29 |
| 30 namespace extensions { |
| 31 |
| 30 namespace { | 32 namespace { |
| 31 | 33 |
| 32 // Returns an icon info corresponding to a canned icon. | 34 // Returns an icon info corresponding to a canned icon. |
| 33 WebApplicationInfo::IconInfo GetIconInfo(const GURL& url, int size) { | 35 WebApplicationInfo::IconInfo GetIconInfo(const GURL& url, int size) { |
| 34 WebApplicationInfo::IconInfo result; | 36 WebApplicationInfo::IconInfo result; |
| 35 | 37 |
| 36 FilePath icon_file; | 38 FilePath icon_file; |
| 37 if (!PathService::Get(chrome::DIR_TEST_DATA, &icon_file)) { | 39 if (!PathService::Get(chrome::DIR_TEST_DATA, &icon_file)) { |
| 38 ADD_FAILURE() << "Could not get test data directory."; | 40 ADD_FAILURE() << "Could not get test data directory."; |
| 39 return result; | 41 return result; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 web_app.permissions.push_back("geolocation"); | 101 web_app.permissions.push_back("geolocation"); |
| 100 web_app.permissions.push_back("notifications"); | 102 web_app.permissions.push_back("notifications"); |
| 101 web_app.urls.push_back(GURL("http://aaronboodman.com/gearpad/")); | 103 web_app.urls.push_back(GURL("http://aaronboodman.com/gearpad/")); |
| 102 | 104 |
| 103 const int sizes[] = {16, 48, 128}; | 105 const int sizes[] = {16, 48, 128}; |
| 104 for (size_t i = 0; i < arraysize(sizes); ++i) { | 106 for (size_t i = 0; i < arraysize(sizes); ++i) { |
| 105 GURL icon_url(web_app.app_url.Resolve(StringPrintf("%i.png", sizes[i]))); | 107 GURL icon_url(web_app.app_url.Resolve(StringPrintf("%i.png", sizes[i]))); |
| 106 web_app.icons.push_back(GetIconInfo(icon_url, sizes[i])); | 108 web_app.icons.push_back(GetIconInfo(icon_url, sizes[i])); |
| 107 } | 109 } |
| 108 | 110 |
| 109 scoped_refptr<extensions::Extension> extension = ConvertWebAppToExtension( | 111 scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
| 110 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); | 112 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); |
| 111 ASSERT_TRUE(extension.get()); | 113 ASSERT_TRUE(extension.get()); |
| 112 | 114 |
| 113 ScopedTempDir extension_dir; | 115 ScopedTempDir extension_dir; |
| 114 EXPECT_TRUE(extension_dir.Set(extension->path())); | 116 EXPECT_TRUE(extension_dir.Set(extension->path())); |
| 115 | 117 |
| 116 EXPECT_TRUE(extension->is_app()); | 118 EXPECT_TRUE(extension->is_app()); |
| 117 EXPECT_TRUE(extension->is_hosted_app()); | 119 EXPECT_TRUE(extension->is_hosted_app()); |
| 118 EXPECT_FALSE(extension->is_packaged_app()); | 120 EXPECT_FALSE(extension->is_packaged_app()); |
| 119 | 121 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 142 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); | 144 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); |
| 143 } | 145 } |
| 144 } | 146 } |
| 145 | 147 |
| 146 TEST(ExtensionFromWebApp, Minimal) { | 148 TEST(ExtensionFromWebApp, Minimal) { |
| 147 WebApplicationInfo web_app; | 149 WebApplicationInfo web_app; |
| 148 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); | 150 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); |
| 149 web_app.title = ASCIIToUTF16("Gearpad"); | 151 web_app.title = ASCIIToUTF16("Gearpad"); |
| 150 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); | 152 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 151 | 153 |
| 152 scoped_refptr<extensions::Extension> extension = ConvertWebAppToExtension( | 154 scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
| 153 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); | 155 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0)); |
| 154 ASSERT_TRUE(extension.get()); | 156 ASSERT_TRUE(extension.get()); |
| 155 | 157 |
| 156 ScopedTempDir extension_dir; | 158 ScopedTempDir extension_dir; |
| 157 EXPECT_TRUE(extension_dir.Set(extension->path())); | 159 EXPECT_TRUE(extension_dir.Set(extension->path())); |
| 158 | 160 |
| 159 EXPECT_TRUE(extension->is_app()); | 161 EXPECT_TRUE(extension->is_app()); |
| 160 EXPECT_TRUE(extension->is_hosted_app()); | 162 EXPECT_TRUE(extension->is_hosted_app()); |
| 161 EXPECT_FALSE(extension->is_packaged_app()); | 163 EXPECT_FALSE(extension->is_packaged_app()); |
| 162 | 164 |
| 163 EXPECT_EQ("lJqm1+jncOHClAuwif1QxNJKfeV9Fbl9IBZx7FkNwkA=", | 165 EXPECT_EQ("lJqm1+jncOHClAuwif1QxNJKfeV9Fbl9IBZx7FkNwkA=", |
| 164 extension->public_key()); | 166 extension->public_key()); |
| 165 EXPECT_EQ("ncnbaadanljoanockmphfdkimpdedemj", extension->id()); | 167 EXPECT_EQ("ncnbaadanljoanockmphfdkimpdedemj", extension->id()); |
| 166 EXPECT_EQ("1978.12.11.0", extension->version()->GetString()); | 168 EXPECT_EQ("1978.12.11.0", extension->version()->GetString()); |
| 167 EXPECT_EQ(UTF16ToUTF8(web_app.title), extension->name()); | 169 EXPECT_EQ(UTF16ToUTF8(web_app.title), extension->name()); |
| 168 EXPECT_EQ("", extension->description()); | 170 EXPECT_EQ("", extension->description()); |
| 169 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); | 171 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); |
| 170 EXPECT_EQ(0u, extension->icons().map().size()); | 172 EXPECT_EQ(0u, extension->icons().map().size()); |
| 171 EXPECT_EQ(0u, extension->GetActivePermissions()->apis().size()); | 173 EXPECT_EQ(0u, extension->GetActivePermissions()->apis().size()); |
| 172 ASSERT_EQ(1u, extension->web_extent().patterns().size()); | 174 ASSERT_EQ(1u, extension->web_extent().patterns().size()); |
| 173 EXPECT_EQ("*://aaronboodman.com/*", | 175 EXPECT_EQ("*://aaronboodman.com/*", |
| 174 extension->web_extent().patterns().begin()->GetAsString()); | 176 extension->web_extent().patterns().begin()->GetAsString()); |
| 175 } | 177 } |
| 178 |
| 179 } // namespace extensions |
| OLD | NEW |