OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/android/webapk/webapk_installer.h" | 5 #include "chrome/browser/android/webapk/webapk_installer.h" |
6 | 6 |
7 #include <jni.h> | 7 #include <jni.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 const base::FilePath::CharType kTestDataDir[] = | 37 const base::FilePath::CharType kTestDataDir[] = |
38 FILE_PATH_LITERAL("chrome/test/data"); | 38 FILE_PATH_LITERAL("chrome/test/data"); |
39 | 39 |
40 // URL of mock WebAPK server. | 40 // URL of mock WebAPK server. |
41 const char* kServerUrl = "/webapkserver/"; | 41 const char* kServerUrl = "/webapkserver/"; |
42 | 42 |
43 // The best primary icon URL from Web Manifest. We use a random file in the test | 43 // The URLs of best icons from Web Manifest. We use a random file in the test |
44 // data directory. Since WebApkInstaller does not try to decode the file as an | 44 // data directory. Since WebApkInstaller does not try to decode the file as an |
45 // image it is OK that the file is not an image. | 45 // image it is OK that the file is not an image. |
46 const char* kBestPrimaryIconUrl = "/simple.html"; | 46 const char* kBestPrimaryIconUrl = "/simple.html"; |
47 const char* kBestBadgeIconUrl = "/simple.html"; | |
47 | 48 |
48 // URL of file to download from the WebAPK server. We use a random file in the | 49 // URL of file to download from the WebAPK server. We use a random file in the |
49 // test data directory. | 50 // test data directory. |
50 const char* kDownloadUrl = "/simple.html"; | 51 const char* kDownloadUrl = "/simple.html"; |
51 | 52 |
52 // The package name of the downloaded WebAPK. | 53 // The package name of the downloaded WebAPK. |
53 const char* kDownloadedWebApkPackageName = "party.unicode"; | 54 const char* kDownloadedWebApkPackageName = "party.unicode"; |
54 | 55 |
55 // WebApkInstaller subclass where | 56 // WebApkInstaller subclass where |
56 // WebApkInstaller::StartInstallingDownloadedWebApk() and | 57 // WebApkInstaller::StartInstallingDownloadedWebApk() and |
57 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and | 58 // WebApkInstaller::StartUpdateUsingDownloadedWebApk() and |
58 // WebApkInstaller::CanUseGooglePlayInstallService() and | 59 // WebApkInstaller::CanUseGooglePlayInstallService() and |
59 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out. | 60 // WebApkInstaller::InstallOrUpdateWebApkFromGooglePlay() are stubbed out. |
60 class TestWebApkInstaller : public WebApkInstaller { | 61 class TestWebApkInstaller : public WebApkInstaller { |
61 public: | 62 public: |
62 TestWebApkInstaller(content::BrowserContext* browser_context, | 63 TestWebApkInstaller(content::BrowserContext* browser_context, |
63 const ShortcutInfo& shortcut_info, | 64 const ShortcutInfo& shortcut_info, |
64 const SkBitmap& shortcut_icon, | 65 const SkBitmap& primary_icon, |
66 const SkBitmap& badge_icon, | |
65 bool can_use_google_play_install_service) | 67 bool can_use_google_play_install_service) |
66 : WebApkInstaller(browser_context, shortcut_info, shortcut_icon), | 68 : WebApkInstaller(browser_context, |
69 shortcut_info, | |
70 primary_icon, | |
71 badge_icon), | |
67 can_use_google_play_install_service_( | 72 can_use_google_play_install_service_( |
68 can_use_google_play_install_service) {} | 73 can_use_google_play_install_service) {} |
69 | 74 |
70 void InstallDownloadedWebApk( | 75 void InstallDownloadedWebApk( |
71 JNIEnv* env, | 76 JNIEnv* env, |
72 const base::android::ScopedJavaLocalRef<jstring>& file_path, | 77 const base::android::ScopedJavaLocalRef<jstring>& file_path, |
73 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { | 78 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { |
74 PostTaskToRunSuccessCallback(); | 79 PostTaskToRunSuccessCallback(); |
75 } | 80 } |
76 | 81 |
(...skipping 25 matching lines...) Expand all Loading... | |
102 // available. | 107 // available. |
103 bool can_use_google_play_install_service_; | 108 bool can_use_google_play_install_service_; |
104 | 109 |
105 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); | 110 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); |
106 }; | 111 }; |
107 | 112 |
108 // Runs the WebApkInstaller installation process/update and blocks till done. | 113 // Runs the WebApkInstaller installation process/update and blocks till done. |
109 class WebApkInstallerRunner { | 114 class WebApkInstallerRunner { |
110 public: | 115 public: |
111 WebApkInstallerRunner(content::BrowserContext* browser_context, | 116 WebApkInstallerRunner(content::BrowserContext* browser_context, |
112 const GURL& best_primary_icon_url) | 117 const GURL& best_primary_icon_url, |
118 const GURL& best_badge_icon_url) | |
113 : browser_context_(browser_context), | 119 : browser_context_(browser_context), |
114 best_primary_icon_url_(best_primary_icon_url), | 120 best_primary_icon_url_(best_primary_icon_url), |
121 best_badge_icon_url_(best_badge_icon_url), | |
115 can_use_google_play_install_service_(false) {} | 122 can_use_google_play_install_service_(false) {} |
116 | 123 |
117 ~WebApkInstallerRunner() {} | 124 ~WebApkInstallerRunner() {} |
118 | 125 |
119 void SetCanUseGooglePlayInstallService( | 126 void SetCanUseGooglePlayInstallService( |
120 bool can_use_google_play_install_service) { | 127 bool can_use_google_play_install_service) { |
121 can_use_google_play_install_service_ = can_use_google_play_install_service; | 128 can_use_google_play_install_service_ = can_use_google_play_install_service; |
122 } | 129 } |
123 | 130 |
124 void RunInstallWebApk() { | 131 void RunInstallWebApk() { |
125 WebApkInstaller::InstallAsyncForTesting( | 132 WebApkInstaller::InstallAsyncForTesting( |
126 CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted, | 133 CreateWebApkInstaller(), base::Bind(&WebApkInstallerRunner::OnCompleted, |
127 base::Unretained(this))); | 134 base::Unretained(this))); |
128 Run(); | 135 Run(); |
129 } | 136 } |
130 | 137 |
131 void RunUpdateWebApk() { | 138 void RunUpdateWebApk() { |
132 const int kWebApkVersion = 1; | 139 const int kWebApkVersion = 1; |
133 | 140 |
134 std::map<std::string, std::string> icon_url_to_murmur2_hash{ | 141 std::map<std::string, std::string> icon_url_to_murmur2_hash{ |
135 {best_primary_icon_url_.spec(), "0"}}; | 142 {best_primary_icon_url_.spec(), "0"}, |
143 {best_badge_icon_url_.spec(), "0"}}; | |
136 | 144 |
137 WebApkInstaller::UpdateAsyncForTesting( | 145 WebApkInstaller::UpdateAsyncForTesting( |
138 CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion, | 146 CreateWebApkInstaller(), kDownloadedWebApkPackageName, kWebApkVersion, |
139 icon_url_to_murmur2_hash, false /* is_manifest_stale */, | 147 icon_url_to_murmur2_hash, false /* is_manifest_stale */, |
140 base::Bind(&WebApkInstallerRunner::OnCompleted, | 148 base::Bind(&WebApkInstallerRunner::OnCompleted, |
141 base::Unretained(this))); | 149 base::Unretained(this))); |
142 Run(); | 150 Run(); |
143 } | 151 } |
144 | 152 |
145 WebApkInstaller* CreateWebApkInstaller() { | 153 WebApkInstaller* CreateWebApkInstaller() { |
146 ShortcutInfo info(GURL::EmptyGURL()); | 154 ShortcutInfo info(GURL::EmptyGURL()); |
147 info.best_primary_icon_url = best_primary_icon_url_; | 155 info.best_primary_icon_url = best_primary_icon_url_; |
156 info.best_badge_icon_url = best_badge_icon_url_; | |
148 | 157 |
149 // WebApkInstaller owns itself. | 158 // WebApkInstaller owns itself. |
150 WebApkInstaller* installer = | 159 WebApkInstaller* installer = |
151 new TestWebApkInstaller(browser_context_, info, SkBitmap(), | 160 new TestWebApkInstaller(browser_context_, info, SkBitmap(), SkBitmap(), |
152 can_use_google_play_install_service_); | 161 can_use_google_play_install_service_); |
153 installer->SetTimeoutMs(100); | 162 installer->SetTimeoutMs(100); |
154 return installer; | 163 return installer; |
155 } | 164 } |
156 | 165 |
157 void Run() { | 166 void Run() { |
158 base::RunLoop run_loop; | 167 base::RunLoop run_loop; |
159 on_completed_callback_ = run_loop.QuitClosure(); | 168 on_completed_callback_ = run_loop.QuitClosure(); |
160 run_loop.Run(); | 169 run_loop.Run(); |
161 } | 170 } |
162 | 171 |
163 WebApkInstallResult result() { return result_; } | 172 WebApkInstallResult result() { return result_; } |
164 | 173 |
165 private: | 174 private: |
166 void OnCompleted(WebApkInstallResult result, | 175 void OnCompleted(WebApkInstallResult result, |
167 bool relax_updates, | 176 bool relax_updates, |
168 const std::string& webapk_package) { | 177 const std::string& webapk_package) { |
169 result_ = result; | 178 result_ = result; |
170 on_completed_callback_.Run(); | 179 on_completed_callback_.Run(); |
171 } | 180 } |
172 | 181 |
173 content::BrowserContext* browser_context_; | 182 content::BrowserContext* browser_context_; |
174 | 183 |
175 // The Web Manifest's icon URL. | 184 // The Web Manifest's icon URLs. |
176 const GURL best_primary_icon_url_; | 185 const GURL best_primary_icon_url_; |
186 const GURL best_badge_icon_url_; | |
177 | 187 |
178 // Called after the installation process has succeeded or failed. | 188 // Called after the installation process has succeeded or failed. |
179 base::Closure on_completed_callback_; | 189 base::Closure on_completed_callback_; |
180 | 190 |
181 // The result of the installation process. | 191 // The result of the installation process. |
182 WebApkInstallResult result_; | 192 WebApkInstallResult result_; |
183 | 193 |
184 // Whether Google Play Service can be used and the install delegate is | 194 // Whether Google Play Service can be used and the install delegate is |
185 // available. | 195 // available. |
186 bool can_use_google_play_install_service_; | 196 bool can_use_google_play_install_service_; |
(...skipping 22 matching lines...) Expand all Loading... | |
209 // Builds WebApk proto and blocks till done. | 219 // Builds WebApk proto and blocks till done. |
210 class BuildProtoRunner { | 220 class BuildProtoRunner { |
211 public: | 221 public: |
212 explicit BuildProtoRunner(content::BrowserContext* browser_context) | 222 explicit BuildProtoRunner(content::BrowserContext* browser_context) |
213 : browser_context_(browser_context) {} | 223 : browser_context_(browser_context) {} |
214 | 224 |
215 ~BuildProtoRunner() {} | 225 ~BuildProtoRunner() {} |
216 | 226 |
217 void BuildSync( | 227 void BuildSync( |
218 const GURL& best_primary_icon_url, | 228 const GURL& best_primary_icon_url, |
229 const GURL& best_badge_icon_url, | |
219 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, | 230 const std::map<std::string, std::string>& icon_url_to_murmur2_hash, |
220 bool is_manifest_stale) { | 231 bool is_manifest_stale) { |
221 ShortcutInfo info(GURL::EmptyGURL()); | 232 ShortcutInfo info(GURL::EmptyGURL()); |
222 info.best_primary_icon_url = best_primary_icon_url; | 233 info.best_primary_icon_url = best_primary_icon_url; |
234 info.best_badge_icon_url = best_badge_icon_url; | |
223 | 235 |
224 // WebApkInstaller owns itself. | 236 // WebApkInstaller owns itself. |
225 WebApkInstaller* installer = | 237 WebApkInstaller* installer = new TestWebApkInstaller( |
226 new TestWebApkInstaller(browser_context_, info, SkBitmap(), false); | 238 browser_context_, info, SkBitmap(), SkBitmap(), false); |
227 installer->BuildWebApkProtoInBackgroundForTesting( | 239 installer->BuildWebApkProtoInBackgroundForTesting( |
228 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, | 240 base::Bind(&BuildProtoRunner::OnBuiltWebApkProto, |
229 base::Unretained(this)), | 241 base::Unretained(this)), |
230 icon_url_to_murmur2_hash, is_manifest_stale); | 242 icon_url_to_murmur2_hash, is_manifest_stale); |
231 | 243 |
232 base::RunLoop run_loop; | 244 base::RunLoop run_loop; |
233 on_completed_callback_ = run_loop.QuitClosure(); | 245 on_completed_callback_ = run_loop.QuitClosure(); |
234 run_loop.Run(); | 246 run_loop.Run(); |
235 } | 247 } |
236 | 248 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 void TearDown() override { | 291 void TearDown() override { |
280 profile_.reset(); | 292 profile_.reset(); |
281 base::RunLoop().RunUntilIdle(); | 293 base::RunLoop().RunUntilIdle(); |
282 } | 294 } |
283 | 295 |
284 // Sets the best Web Manifest's primary icon URL. | 296 // Sets the best Web Manifest's primary icon URL. |
285 void SetBestPrimaryIconUrl(const GURL& best_primary_icon_url) { | 297 void SetBestPrimaryIconUrl(const GURL& best_primary_icon_url) { |
286 best_primary_icon_url_ = best_primary_icon_url; | 298 best_primary_icon_url_ = best_primary_icon_url; |
287 } | 299 } |
288 | 300 |
301 // Sets the best Web Manifest's badge icon URL. | |
302 void SetBestBadgeIconUrl(const GURL& best_badge_icon_url) { | |
303 best_badge_icon_url_ = best_badge_icon_url; | |
304 } | |
305 | |
289 // Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller | 306 // Sets the URL to send the webapk::CreateWebApkRequest to. WebApkInstaller |
290 // should fail if the URL is not |kServerUrl|. | 307 // should fail if the URL is not |kServerUrl|. |
291 void SetWebApkServerUrl(const GURL& server_url) { | 308 void SetWebApkServerUrl(const GURL& server_url) { |
292 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 309 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
293 switches::kWebApkServerUrl, server_url.spec()); | 310 switches::kWebApkServerUrl, server_url.spec()); |
294 } | 311 } |
295 | 312 |
296 // Sets the function that should be used to build the response to the | 313 // Sets the function that should be used to build the response to the |
297 // WebAPK creation request. | 314 // WebAPK creation request. |
298 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) { | 315 void SetWebApkResponseBuilder(const WebApkResponseBuilder& builder) { |
299 webapk_response_builder_ = builder; | 316 webapk_response_builder_ = builder; |
300 } | 317 } |
301 | 318 |
302 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() { | 319 std::unique_ptr<WebApkInstallerRunner> CreateWebApkInstallerRunner() { |
303 return std::unique_ptr<WebApkInstallerRunner>( | 320 return std::unique_ptr<WebApkInstallerRunner>(new WebApkInstallerRunner( |
304 new WebApkInstallerRunner(profile_.get(), best_primary_icon_url_)); | 321 profile_.get(), best_primary_icon_url_, best_badge_icon_url_)); |
305 } | 322 } |
306 | 323 |
307 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() { | 324 std::unique_ptr<BuildProtoRunner> CreateBuildProtoRunner() { |
308 return std::unique_ptr<BuildProtoRunner>( | 325 return std::unique_ptr<BuildProtoRunner>( |
309 new BuildProtoRunner(profile_.get())); | 326 new BuildProtoRunner(profile_.get())); |
310 } | 327 } |
311 | 328 |
312 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; } | 329 net::test_server::EmbeddedTestServer* test_server() { return &test_server_; } |
313 | 330 |
314 private: | 331 private: |
315 // Sets default configuration for running WebApkInstaller. | 332 // Sets default configuration for running WebApkInstaller. |
316 void SetDefaults() { | 333 void SetDefaults() { |
317 GURL best_primary_icon_url = test_server_.GetURL(kBestPrimaryIconUrl); | 334 GURL best_primary_icon_url = test_server_.GetURL(kBestPrimaryIconUrl); |
318 SetBestPrimaryIconUrl(best_primary_icon_url); | 335 SetBestPrimaryIconUrl(best_primary_icon_url); |
336 GURL best_badge_icon_url = test_server_.GetURL(kBestBadgeIconUrl); | |
337 SetBestBadgeIconUrl(best_badge_icon_url); | |
319 GURL server_url = test_server_.GetURL(kServerUrl); | 338 GURL server_url = test_server_.GetURL(kServerUrl); |
320 SetWebApkServerUrl(server_url); | 339 SetWebApkServerUrl(server_url); |
321 GURL download_url = test_server_.GetURL(kDownloadUrl); | 340 GURL download_url = test_server_.GetURL(kDownloadUrl); |
322 SetWebApkResponseBuilder( | 341 SetWebApkResponseBuilder( |
323 base::Bind(&BuildValidWebApkResponse, download_url)); | 342 base::Bind(&BuildValidWebApkResponse, download_url)); |
324 } | 343 } |
325 | 344 |
326 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( | 345 std::unique_ptr<net::test_server::HttpResponse> HandleWebApkRequest( |
327 const net::test_server::HttpRequest& request) { | 346 const net::test_server::HttpRequest& request) { |
328 return (request.relative_url == kServerUrl) | 347 return (request.relative_url == kServerUrl) |
329 ? webapk_response_builder_.Run() | 348 ? webapk_response_builder_.Run() |
330 : std::unique_ptr<net::test_server::HttpResponse>(); | 349 : std::unique_ptr<net::test_server::HttpResponse>(); |
331 } | 350 } |
332 | 351 |
333 std::unique_ptr<TestingProfile> profile_; | 352 std::unique_ptr<TestingProfile> profile_; |
334 content::TestBrowserThreadBundle thread_bundle_; | 353 content::TestBrowserThreadBundle thread_bundle_; |
335 net::EmbeddedTestServer test_server_; | 354 net::EmbeddedTestServer test_server_; |
336 | 355 |
337 // Web Manifest's icon URL. | 356 // Web Manifest's icon URLs. |
338 GURL best_primary_icon_url_; | 357 GURL best_primary_icon_url_; |
358 GURL best_badge_icon_url_; | |
339 | 359 |
340 // Builds response to the WebAPK creation request. | 360 // Builds response to the WebAPK creation request. |
341 WebApkResponseBuilder webapk_response_builder_; | 361 WebApkResponseBuilder webapk_response_builder_; |
342 | 362 |
343 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); | 363 DISALLOW_COPY_AND_ASSIGN(WebApkInstallerTest); |
344 }; | 364 }; |
345 | 365 |
346 // Test installation succeeding. | 366 // Test installation succeeding. |
347 TEST_F(WebApkInstallerTest, Success) { | 367 TEST_F(WebApkInstallerTest, Success) { |
348 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 368 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
349 runner->RunInstallWebApk(); | 369 runner->RunInstallWebApk(); |
350 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result()); | 370 EXPECT_EQ(WebApkInstallResult::SUCCESS, runner->result()); |
351 } | 371 } |
352 | 372 |
353 // Test that installation fails if fetching the bitmap at the best primary icon | 373 // Test that installation fails if fetching the bitmap at the best primary icon |
354 // URL times out. In a perfect world the fetch would never time out because the | 374 // URL times out. In a perfect world the fetch would never time out because the |
355 // bitmap at the best primary icon URL should be in the HTTP cache. | 375 // bitmap at the best primary icon URL should be in the HTTP cache. |
356 TEST_F(WebApkInstallerTest, BestPrimaryIconUrlDownloadTimesOut) { | 376 TEST_F(WebApkInstallerTest, BestPrimaryIconUrlDownloadTimesOut) { |
357 GURL best_primary_icon_url = test_server()->GetURL("/slow?1000"); | 377 GURL best_primary_icon_url = test_server()->GetURL("/slow?1000"); |
358 SetBestPrimaryIconUrl(best_primary_icon_url); | 378 SetBestPrimaryIconUrl(best_primary_icon_url); |
359 | 379 |
360 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 380 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
361 runner->RunInstallWebApk(); | 381 runner->RunInstallWebApk(); |
362 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | 382 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); |
363 } | 383 } |
364 | 384 |
385 // Test that installation fails if fetching the bitmap at the best badge icon | |
386 // URL times out. In a perfect world the fetch would never time out because the | |
387 // bitmap at the best badge icon URL should be in the HTTP cache. | |
388 TEST_F(WebApkInstallerTest, BestBadgeIconUrlDownloadTimesOut) { | |
389 GURL best_badge_icon_url = test_server()->GetURL("/slow?1000"); | |
390 SetBestBadgeIconUrl(best_badge_icon_url); | |
pkotwicz
2017/03/30 21:49:50
Nit: You can merge lines 389 and 390
F
2017/04/03 21:57:29
Done.
| |
391 | |
392 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | |
393 runner->RunInstallWebApk(); | |
394 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | |
395 } | |
396 | |
365 // Test that installation fails if the WebAPK creation request times out. | 397 // Test that installation fails if the WebAPK creation request times out. |
366 TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) { | 398 TEST_F(WebApkInstallerTest, CreateWebApkRequestTimesOut) { |
367 GURL server_url = test_server()->GetURL("/slow?1000"); | 399 GURL server_url = test_server()->GetURL("/slow?1000"); |
368 SetWebApkServerUrl(server_url); | 400 SetWebApkServerUrl(server_url); |
369 | 401 |
370 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 402 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
371 runner->RunInstallWebApk(); | 403 runner->RunInstallWebApk(); |
372 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); | 404 EXPECT_EQ(WebApkInstallResult::FAILURE, runner->result()); |
373 } | 405 } |
374 | 406 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { | 484 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsObsolete) { |
453 GURL icon_url_1 = test_server()->GetURL("/icon1.png"); | 485 GURL icon_url_1 = test_server()->GetURL("/icon1.png"); |
454 GURL icon_url_2 = test_server()->GetURL("/icon2.png"); | 486 GURL icon_url_2 = test_server()->GetURL("/icon2.png"); |
455 std::string icon_murmur2_hash_1 = "1"; | 487 std::string icon_murmur2_hash_1 = "1"; |
456 std::string icon_murmur2_hash_2 = "2"; | 488 std::string icon_murmur2_hash_2 = "2"; |
457 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 489 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
458 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; | 490 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; |
459 icon_url_to_murmur2_hash[icon_url_2.spec()] = icon_murmur2_hash_2; | 491 icon_url_to_murmur2_hash[icon_url_2.spec()] = icon_murmur2_hash_2; |
460 | 492 |
461 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); | 493 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); |
462 runner->BuildSync(GURL(""), icon_url_to_murmur2_hash, | 494 runner->BuildSync(GURL(""), GURL(""), icon_url_to_murmur2_hash, |
pkotwicz
2017/03/30 21:49:50
Nit: You can use the no-arg constructor of GURL()
F
2017/04/03 21:57:29
Done.
| |
463 true /* is_manifest_stale*/); | 495 true /* is_manifest_stale*/); |
464 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); | 496 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); |
465 ASSERT_NE(nullptr, webapk_request); | 497 ASSERT_NE(nullptr, webapk_request); |
466 | 498 |
467 webapk::WebAppManifest manifest = webapk_request->manifest(); | 499 webapk::WebAppManifest manifest = webapk_request->manifest(); |
468 ASSERT_EQ(3, manifest.icons_size()); | 500 ASSERT_EQ(3, manifest.icons_size()); |
469 | 501 |
470 webapk::Image icons[3]; | 502 webapk::Image icons[3]; |
471 for (int i = 0; i < 3; ++i) | 503 for (int i = 0; i < 3; ++i) |
472 icons[i] = manifest.icons(i); | 504 icons[i] = manifest.icons(i); |
473 | 505 |
474 EXPECT_EQ("", icons[0].src()); | 506 EXPECT_EQ("", icons[0].src()); |
475 EXPECT_FALSE(icons[0].has_hash()); | 507 EXPECT_FALSE(icons[0].has_hash()); |
476 EXPECT_TRUE(icons[0].has_image_data()); | 508 EXPECT_TRUE(icons[0].has_image_data()); |
477 | 509 |
478 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); | 510 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); |
479 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); | 511 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); |
480 EXPECT_FALSE(icons[1].has_image_data()); | 512 EXPECT_FALSE(icons[1].has_image_data()); |
481 | 513 |
482 EXPECT_EQ(icon_url_2.spec(), icons[2].src()); | 514 EXPECT_EQ(icon_url_2.spec(), icons[2].src()); |
483 EXPECT_EQ(icon_murmur2_hash_2, icons[2].hash()); | 515 EXPECT_EQ(icon_murmur2_hash_2, icons[2].hash()); |
484 EXPECT_FALSE(icons[2].has_image_data()); | 516 EXPECT_FALSE(icons[2].has_image_data()); |
485 } | 517 } |
486 | 518 |
487 // Tests a WebApk install or update request is built properly when the Chrome | 519 // Tests a WebApk install or update request is built properly when the Chrome |
488 // knows the best icon URL of a site after fetching its Web Manifest. | 520 // knows the best icon URL of a site after fetching its Web Manifest. |
489 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) { | 521 TEST_F(WebApkInstallerTest, BuildWebApkProtoWhenManifestIsAvailable) { |
490 GURL icon_url_1 = test_server()->GetURL("/icon.png"); | 522 GURL icon_url_1 = test_server()->GetURL("/icon.png"); |
491 GURL best_primary_icon_url = test_server()->GetURL(kBestPrimaryIconUrl); | 523 GURL best_primary_icon_url = test_server()->GetURL(kBestPrimaryIconUrl); |
524 GURL best_badge_icon_url = test_server()->GetURL(kBestBadgeIconUrl); | |
492 std::string icon_murmur2_hash_1 = "1"; | 525 std::string icon_murmur2_hash_1 = "1"; |
493 std::string best_primary_icon_murmur2_hash = "0"; | 526 std::string best_primary_icon_murmur2_hash = "0"; |
527 std::string best_badge_icon_murmur2_hash = "0"; | |
494 std::map<std::string, std::string> icon_url_to_murmur2_hash; | 528 std::map<std::string, std::string> icon_url_to_murmur2_hash; |
495 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; | 529 icon_url_to_murmur2_hash[icon_url_1.spec()] = icon_murmur2_hash_1; |
496 icon_url_to_murmur2_hash[best_primary_icon_url.spec()] = | 530 icon_url_to_murmur2_hash[best_primary_icon_url.spec()] = |
497 best_primary_icon_murmur2_hash; | 531 best_primary_icon_murmur2_hash; |
532 icon_url_to_murmur2_hash[best_badge_icon_url.spec()] = | |
533 best_badge_icon_murmur2_hash; | |
498 | 534 |
499 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); | 535 std::unique_ptr<BuildProtoRunner> runner = CreateBuildProtoRunner(); |
500 runner->BuildSync(best_primary_icon_url, icon_url_to_murmur2_hash, | 536 runner->BuildSync(best_primary_icon_url, best_badge_icon_url, |
501 false /* is_manifest_stale*/); | 537 icon_url_to_murmur2_hash, false /* is_manifest_stale*/); |
502 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); | 538 webapk::WebApk* webapk_request = runner->GetWebApkRequest(); |
503 ASSERT_NE(nullptr, webapk_request); | 539 ASSERT_NE(nullptr, webapk_request); |
504 | 540 |
505 webapk::WebAppManifest manifest = webapk_request->manifest(); | 541 webapk::WebAppManifest manifest = webapk_request->manifest(); |
506 ASSERT_EQ(2, manifest.icons_size()); | 542 ASSERT_EQ(2, manifest.icons_size()); |
pkotwicz
2017/03/30 21:49:50
Don't you need to update this test?
i.e. ASSERT_E
F
2017/04/03 21:57:29
Done. In this test case, primary icon and badge ic
| |
507 | 543 |
508 webapk::Image icons[2]; | 544 webapk::Image icons[2]; |
509 for (int i = 0; i < 2; ++i) | 545 for (int i = 0; i < 2; ++i) |
510 icons[i] = manifest.icons(i); | 546 icons[i] = manifest.icons(i); |
511 | 547 |
512 EXPECT_EQ(best_primary_icon_url.spec(), icons[0].src()); | 548 EXPECT_EQ(best_primary_icon_url.spec(), icons[0].src()); |
513 EXPECT_EQ(best_primary_icon_murmur2_hash, icons[0].hash()); | 549 EXPECT_EQ(best_primary_icon_murmur2_hash, icons[0].hash()); |
514 EXPECT_TRUE(icons[0].has_image_data()); | 550 EXPECT_TRUE(icons[0].has_image_data()); |
515 | 551 |
516 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); | 552 EXPECT_EQ(icon_url_1.spec(), icons[1].src()); |
517 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); | 553 EXPECT_EQ(icon_murmur2_hash_1, icons[1].hash()); |
518 EXPECT_FALSE(icons[1].has_image_data()); | 554 EXPECT_FALSE(icons[1].has_image_data()); |
519 } | 555 } |
OLD | NEW |