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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 WebApplicationInfo::IconInfo result; | 37 WebApplicationInfo::IconInfo result; |
38 | 38 |
39 base::FilePath icon_file; | 39 base::FilePath icon_file; |
40 if (!PathService::Get(chrome::DIR_TEST_DATA, &icon_file)) { | 40 if (!PathService::Get(chrome::DIR_TEST_DATA, &icon_file)) { |
41 ADD_FAILURE() << "Could not get test data directory."; | 41 ADD_FAILURE() << "Could not get test data directory."; |
42 return result; | 42 return result; |
43 } | 43 } |
44 | 44 |
45 icon_file = icon_file.AppendASCII("extensions") | 45 icon_file = icon_file.AppendASCII("extensions") |
46 .AppendASCII("convert_web_app") | 46 .AppendASCII("convert_web_app") |
47 .AppendASCII(StringPrintf("%i.png", size)); | 47 .AppendASCII(base::StringPrintf("%i.png", size)); |
48 | 48 |
49 result.url = url; | 49 result.url = url; |
50 result.width = size; | 50 result.width = size; |
51 result.height = size; | 51 result.height = size; |
52 | 52 |
53 std::string icon_data; | 53 std::string icon_data; |
54 if (!file_util::ReadFileToString(icon_file, &icon_data)) { | 54 if (!file_util::ReadFileToString(icon_file, &icon_data)) { |
55 ADD_FAILURE() << "Could not read test icon."; | 55 ADD_FAILURE() << "Could not read test icon."; |
56 return result; | 56 return result; |
57 } | 57 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); | 113 web_app.manifest_url = GURL("http://aaronboodman.com/gearpad/manifest.json"); |
114 web_app.title = ASCIIToUTF16("Gearpad"); | 114 web_app.title = ASCIIToUTF16("Gearpad"); |
115 web_app.description = ASCIIToUTF16("The best text editor in the universe!"); | 115 web_app.description = ASCIIToUTF16("The best text editor in the universe!"); |
116 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); | 116 web_app.app_url = GURL("http://aaronboodman.com/gearpad/"); |
117 web_app.permissions.push_back("geolocation"); | 117 web_app.permissions.push_back("geolocation"); |
118 web_app.permissions.push_back("notifications"); | 118 web_app.permissions.push_back("notifications"); |
119 web_app.urls.push_back(GURL("http://aaronboodman.com/gearpad/")); | 119 web_app.urls.push_back(GURL("http://aaronboodman.com/gearpad/")); |
120 | 120 |
121 const int sizes[] = {16, 48, 128}; | 121 const int sizes[] = {16, 48, 128}; |
122 for (size_t i = 0; i < arraysize(sizes); ++i) { | 122 for (size_t i = 0; i < arraysize(sizes); ++i) { |
123 GURL icon_url(web_app.app_url.Resolve(StringPrintf("%i.png", sizes[i]))); | 123 GURL icon_url( |
| 124 web_app.app_url.Resolve(base::StringPrintf("%i.png", sizes[i]))); |
124 web_app.icons.push_back(GetIconInfo(icon_url, sizes[i])); | 125 web_app.icons.push_back(GetIconInfo(icon_url, sizes[i])); |
125 } | 126 } |
126 | 127 |
127 scoped_refptr<Extension> extension = ConvertWebAppToExtension( | 128 scoped_refptr<Extension> extension = ConvertWebAppToExtension( |
128 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), | 129 web_app, GetTestTime(1978, 12, 11, 0, 0, 0, 0), |
129 extensions_dir.path()); | 130 extensions_dir.path()); |
130 ASSERT_TRUE(extension.get()); | 131 ASSERT_TRUE(extension.get()); |
131 | 132 |
132 base::ScopedTempDir extension_dir; | 133 base::ScopedTempDir extension_dir; |
133 EXPECT_TRUE(extension_dir.Set(extension->path())); | 134 EXPECT_TRUE(extension_dir.Set(extension->path())); |
(...skipping 11 matching lines...) Expand all Loading... |
145 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); | 146 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); |
146 EXPECT_EQ(2u, extension->GetActivePermissions()->apis().size()); | 147 EXPECT_EQ(2u, extension->GetActivePermissions()->apis().size()); |
147 EXPECT_TRUE(extension->HasAPIPermission("geolocation")); | 148 EXPECT_TRUE(extension->HasAPIPermission("geolocation")); |
148 EXPECT_TRUE(extension->HasAPIPermission("notifications")); | 149 EXPECT_TRUE(extension->HasAPIPermission("notifications")); |
149 ASSERT_EQ(1u, extension->web_extent().patterns().size()); | 150 ASSERT_EQ(1u, extension->web_extent().patterns().size()); |
150 EXPECT_EQ("http://aaronboodman.com/gearpad/*", | 151 EXPECT_EQ("http://aaronboodman.com/gearpad/*", |
151 extension->web_extent().patterns().begin()->GetAsString()); | 152 extension->web_extent().patterns().begin()->GetAsString()); |
152 | 153 |
153 EXPECT_EQ(web_app.icons.size(), IconsInfo::GetIcons(extension).map().size()); | 154 EXPECT_EQ(web_app.icons.size(), IconsInfo::GetIcons(extension).map().size()); |
154 for (size_t i = 0; i < web_app.icons.size(); ++i) { | 155 for (size_t i = 0; i < web_app.icons.size(); ++i) { |
155 EXPECT_EQ(StringPrintf("icons/%i.png", web_app.icons[i].width), | 156 EXPECT_EQ(base::StringPrintf("icons/%i.png", web_app.icons[i].width), |
156 IconsInfo::GetIcons(extension).Get( | 157 IconsInfo::GetIcons(extension).Get( |
157 web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY)); | 158 web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY)); |
158 ExtensionResource resource = IconsInfo::GetIconResource( | 159 ExtensionResource resource = IconsInfo::GetIconResource( |
159 extension, web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY); | 160 extension, web_app.icons[i].width, ExtensionIconSet::MATCH_EXACTLY); |
160 ASSERT_TRUE(!resource.empty()); | 161 ASSERT_TRUE(!resource.empty()); |
161 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); | 162 EXPECT_TRUE(file_util::PathExists(resource.GetFilePath())); |
162 } | 163 } |
163 } | 164 } |
164 | 165 |
165 TEST_F(ExtensionFromWebApp, Minimal) { | 166 TEST_F(ExtensionFromWebApp, Minimal) { |
(...skipping 25 matching lines...) Expand all Loading... |
191 EXPECT_EQ("", extension->description()); | 192 EXPECT_EQ("", extension->description()); |
192 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); | 193 EXPECT_EQ(web_app.app_url, extension->GetFullLaunchURL()); |
193 EXPECT_EQ(0u, IconsInfo::GetIcons(extension).map().size()); | 194 EXPECT_EQ(0u, IconsInfo::GetIcons(extension).map().size()); |
194 EXPECT_EQ(0u, extension->GetActivePermissions()->apis().size()); | 195 EXPECT_EQ(0u, extension->GetActivePermissions()->apis().size()); |
195 ASSERT_EQ(1u, extension->web_extent().patterns().size()); | 196 ASSERT_EQ(1u, extension->web_extent().patterns().size()); |
196 EXPECT_EQ("*://aaronboodman.com/*", | 197 EXPECT_EQ("*://aaronboodman.com/*", |
197 extension->web_extent().patterns().begin()->GetAsString()); | 198 extension->web_extent().patterns().begin()->GetAsString()); |
198 } | 199 } |
199 | 200 |
200 } // namespace extensions | 201 } // namespace extensions |
OLD | NEW |