Chromium Code Reviews| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 private: | 91 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); | 92 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 // Runs the WebApkInstaller installation process/update and blocks till done. | 95 // Runs the WebApkInstaller installation process/update and blocks till done. |
| 96 class WebApkInstallerRunner { | 96 class WebApkInstallerRunner { |
| 97 public: | 97 public: |
| 98 explicit WebApkInstallerRunner(const GURL& icon_url) | 98 explicit WebApkInstallerRunner(const GURL& icon_url) |
| 99 : url_request_context_getter_(new net::TestURLRequestContextGetter( | 99 : url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 100 base::ThreadTaskRunnerHandle::Get())), | 100 base::ThreadTaskRunnerHandle::Get())), |
| 101 icon_url_(icon_url) {} | 101 icon_url_(icon_url) {} |
|
pkotwicz
2016/11/14 22:43:11
Nit: |icon_url_| -> |best_icon_url_|
Xi Han
2016/11/15 20:07:08
Done.
| |
| 102 ~WebApkInstallerRunner() {} | 102 ~WebApkInstallerRunner() {} |
| 103 | 103 |
| 104 void RunInstallWebApk() { | 104 void RunInstallWebApk() { |
| 105 WebApkInstaller* installer = CreateWebApkInstaller(); | 105 WebApkInstaller* installer = CreateWebApkInstaller(); |
| 106 | 106 |
| 107 installer->InstallAsyncWithURLRequestContextGetter( | 107 installer->InstallAsyncWithURLRequestContextGetter( |
| 108 url_request_context_getter_.get(), | 108 url_request_context_getter_.get(), |
| 109 base::Bind(&WebApkInstallerRunner::OnCompleted, | 109 base::Bind(&WebApkInstallerRunner::OnCompleted, |
| 110 base::Unretained(this))); | 110 base::Unretained(this))); |
| 111 Run(); | 111 Run(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 122 base::Bind(&WebApkInstallerRunner::OnCompleted, base::Unretained(this)), | 122 base::Bind(&WebApkInstallerRunner::OnCompleted, base::Unretained(this)), |
| 123 kIconMurmur2Hash, | 123 kIconMurmur2Hash, |
| 124 kDownloadedWebApkPackageName, | 124 kDownloadedWebApkPackageName, |
| 125 kWebApkVersion); | 125 kWebApkVersion); |
| 126 | 126 |
| 127 Run(); | 127 Run(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 WebApkInstaller* CreateWebApkInstaller() { | 130 WebApkInstaller* CreateWebApkInstaller() { |
| 131 ShortcutInfo info(GURL::EmptyGURL()); | 131 ShortcutInfo info(GURL::EmptyGURL()); |
| 132 info.icon_url = icon_url_; | 132 info.best_icon_url = icon_url_; |
| 133 | 133 |
| 134 // WebApkInstaller owns itself. | 134 // WebApkInstaller owns itself. |
| 135 WebApkInstaller* installer = new TestWebApkInstaller(info, SkBitmap()); | 135 WebApkInstaller* installer = new TestWebApkInstaller(info, SkBitmap()); |
| 136 installer->SetTimeoutMs(100); | 136 installer->SetTimeoutMs(100); |
| 137 return installer; | 137 return installer; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void Run() { | 140 void Run() { |
| 141 base::RunLoop run_loop; | 141 base::RunLoop run_loop; |
| 142 on_completed_callback_ = run_loop.QuitClosure(); | 142 on_completed_callback_ = run_loop.QuitClosure(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 runner->RunInstallWebApk(); | 349 runner->RunInstallWebApk(); |
| 350 EXPECT_FALSE(runner->success()); | 350 EXPECT_FALSE(runner->success()); |
| 351 } | 351 } |
| 352 | 352 |
| 353 // Test update succeeding. | 353 // Test update succeeding. |
| 354 TEST_F(WebApkInstallerTest, UpdateSuccess) { | 354 TEST_F(WebApkInstallerTest, UpdateSuccess) { |
| 355 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 355 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
| 356 runner->RunUpdateWebApk(); | 356 runner->RunUpdateWebApk(); |
| 357 EXPECT_TRUE(runner->success()); | 357 EXPECT_TRUE(runner->success()); |
| 358 } | 358 } |
| OLD | NEW |