| 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_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.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_unittest.h" | |
| 22 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" | 21 #include "chrome/common/extensions/manifest_handlers/icons_handler.h" |
| 23 #include "chrome/common/extensions/permissions/permission_set.h" | 22 #include "chrome/common/extensions/permissions/permission_set.h" |
| 24 #include "chrome/common/web_apps.h" | 23 #include "chrome/common/web_apps.h" |
| 25 #include "extensions/common/extension_resource.h" | 24 #include "extensions/common/extension_resource.h" |
| 26 #include "extensions/common/url_pattern.h" | 25 #include "extensions/common/url_pattern.h" |
| 27 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 29 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
| 30 #include "webkit/glue/image_decoder.h" | 29 #include "webkit/glue/image_decoder.h" |
| 31 | 30 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 exploded.day_of_month = day; | 73 exploded.day_of_month = day; |
| 75 exploded.hour = hour; | 74 exploded.hour = hour; |
| 76 exploded.minute = minute; | 75 exploded.minute = minute; |
| 77 exploded.second = second; | 76 exploded.second = second; |
| 78 exploded.millisecond = millisecond; | 77 exploded.millisecond = millisecond; |
| 79 return base::Time::FromUTCExploded(exploded); | 78 return base::Time::FromUTCExploded(exploded); |
| 80 } | 79 } |
| 81 | 80 |
| 82 } // namespace | 81 } // namespace |
| 83 | 82 |
| 84 class ExtensionFromWebApp : public ExtensionTest { | 83 TEST(ExtensionFromWebApp, GenerateVersion) { |
| 85 protected: | |
| 86 virtual void SetUp() OVERRIDE { | |
| 87 ExtensionTest::SetUp(); | |
| 88 (new IconsHandler)->Register(); | |
| 89 } | |
| 90 }; | |
| 91 | |
| 92 TEST_F(ExtensionFromWebApp, GenerateVersion) { | |
| 93 EXPECT_EQ("2010.1.1.0", | 84 EXPECT_EQ("2010.1.1.0", |
| 94 ConvertTimeToExtensionVersion( | 85 ConvertTimeToExtensionVersion( |
| 95 GetTestTime(2010, 1, 1, 0, 0, 0, 0))); | 86 GetTestTime(2010, 1, 1, 0, 0, 0, 0))); |
| 96 EXPECT_EQ("2010.12.31.22111", | 87 EXPECT_EQ("2010.12.31.22111", |
| 97 ConvertTimeToExtensionVersion( | 88 ConvertTimeToExtensionVersion( |
| 98 GetTestTime(2010, 12, 31, 8, 5, 50, 500))); | 89 GetTestTime(2010, 12, 31, 8, 5, 50, 500))); |
| 99 EXPECT_EQ("2010.10.1.65535", | 90 EXPECT_EQ("2010.10.1.65535", |
| 100 ConvertTimeToExtensionVersion( | 91 ConvertTimeToExtensionVersion( |
| 101 GetTestTime(2010, 10, 1, 23, 59, 59, 999))); | 92 GetTestTime(2010, 10, 1, 23, 59, 59, 999))); |
| 102 } | 93 } |
| 103 | 94 |
| 104 TEST_F(ExtensionFromWebApp, Basic) { | 95 TEST(ExtensionFromWebApp, Basic) { |
| 105 base::ScopedTempDir extensions_dir; | 96 base::ScopedTempDir extensions_dir; |
| 106 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); | 97 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 107 | 98 |
| 108 WebApplicationInfo web_app; | 99 WebApplicationInfo web_app; |
| 109 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); | 100 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); |
| 110 web_app.title = ASCIIToUTF16("Gearpad"); | 101 web_app.title = ASCIIToUTF16("Gearpad"); |
| 111 web_app.description = ASCIIToUTF16("The best text editor in the universe!"); | 102 web_app.description = ASCIIToUTF16("The best text editor in the universe!"); |
| 112 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); | 103 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 113 web_app.permissions.push_back("geolocation"); | 104 web_app.permissions.push_back("geolocation"); |
| 114 web_app.permissions.push_back("notifications"); | 105 web_app.permissions.push_back("notifications"); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 EXPECT_EQ(base::StringPrintf("icons/%i.png", web_app.icons[i].width), | 143 EXPECT_EQ(base::StringPrintf("icons/%i.png", web_app.icons[i].width), |
| 153 IconsInfo::GetIcons(extension).Get( | 144 IconsInfo::GetIcons(extension).Get( |
| 154 web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY)); | 145 web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY)); |
| 155 ExtensionResource resource = IconsInfo::GetIconResource( | 146 ExtensionResource resource = IconsInfo::GetIconResource( |
| 156 extension, web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY); | 147 extension, web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY); |
| 157 ASSERT_TRUE(!resource.empty()); | 148 ASSERT_TRUE(!resource.empty()); |
| 158 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); | 149 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); |
| 159 } | 150 } |
| 160 } | 151 } |
| 161 | 152 |
| 162 TEST_F(ExtensionFromWebApp, Minimal) { | 153 TEST(ExtensionFromWebApp, Minimal) { |
| 163 base::ScopedTempDir extensions_dir; | 154 base::ScopedTempDir extensions_dir; |
| 164 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); | 155 ASSERT_TRUE(extensions_dir.CreateUniqueTempDir()); |
| 165 | 156 |
| 166 WebApplicationInfo web_app; | 157 WebApplicationInfo web_app; |
| 167 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); | 158 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); |
| 168 web_app.title = ASCIIToUTF16("Gearpad"); | 159 web_app.title = ASCIIToUTF16("Gearpad"); |
| 169 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); | 160 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
| 170 | 161 |
| 171 scoped_refptr<Extension> extension = ConvertWebAppToExtension( | 162 scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
| 172 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), | 163 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 188 EXPECT_EQ("", extension->description()); | 179 EXPECT_EQ("", extension->description()); |
| 189 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); | 180 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); |
| 190 EXPECT_EQ(0u, IconsInfo::GetIcons(extension).map().size()); | 181 EXPECT_EQ(0u, IconsInfo::GetIcons(extension).map().size()); |
| 191 EXPECT_EQ(0u, extension->GetActivePermissions()->apis().size()); | 182 EXPECT_EQ(0u, extension->GetActivePermissions()->apis().size()); |
| 192 ASSERT_EQ(1u, extension->web_extent().patterns().size()); | 183 ASSERT_EQ(1u, extension->web_extent().patterns().size()); |
| 193 EXPECT_EQ("*://aaronboodman.com/*", | 184 EXPECT_EQ("*://aaronboodman.com/*", |
| 194 extension->web_extent().patterns().begin()->GetAsString()); | 185 extension->web_extent().patterns().begin()->GetAsString()); |
| 195 } | 186 } |
| 196 | 187 |
| 197 } // namespace extensions | 188 } // namespace extensions |
| OLD | NEW |