| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 class TestWebApkInstaller : public WebApkInstaller { | 59 class TestWebApkInstaller : public WebApkInstaller { |
| 60 public: | 60 public: |
| 61 TestWebApkInstaller(const ShortcutInfo& shortcut_info, | 61 TestWebApkInstaller(const ShortcutInfo& shortcut_info, |
| 62 const SkBitmap& shortcut_icon) | 62 const SkBitmap& shortcut_icon) |
| 63 : WebApkInstaller(shortcut_info, shortcut_icon) {} | 63 : WebApkInstaller(shortcut_info, shortcut_icon) {} |
| 64 | 64 |
| 65 bool StartInstallingDownloadedWebApk( | 65 bool StartInstallingDownloadedWebApk( |
| 66 JNIEnv* env, | 66 JNIEnv* env, |
| 67 const base::android::ScopedJavaLocalRef<jstring>& file_path, | 67 const base::android::ScopedJavaLocalRef<jstring>& file_path, |
| 68 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { | 68 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { |
| 69 PostTaskToRunSuccessCallback(); |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 | 72 |
| 72 bool StartUpdateUsingDownloadedWebApk( | 73 bool StartUpdateUsingDownloadedWebApk( |
| 73 JNIEnv* env, | 74 JNIEnv* env, |
| 74 const base::android::ScopedJavaLocalRef<jstring>& file_path, | 75 const base::android::ScopedJavaLocalRef<jstring>& file_path, |
| 75 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { | 76 const base::android::ScopedJavaLocalRef<jstring>& package_name) override { |
| 77 PostTaskToRunSuccessCallback(); |
| 76 return true; | 78 return true; |
| 77 } | 79 } |
| 78 | 80 |
| 81 void PostTaskToRunSuccessCallback() { |
| 82 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 83 FROM_HERE, |
| 84 base::Bind(&TestWebApkInstaller::OnSuccess, base::Unretained(this))); |
| 85 } |
| 86 |
| 79 private: | 87 private: |
| 80 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); | 88 DISALLOW_COPY_AND_ASSIGN(TestWebApkInstaller); |
| 81 }; | 89 }; |
| 82 | 90 |
| 83 // Runs the WebApkInstaller installation process/update and blocks till done. | 91 // Runs the WebApkInstaller installation process/update and blocks till done. |
| 84 class WebApkInstallerRunner { | 92 class WebApkInstallerRunner { |
| 85 public: | 93 public: |
| 86 explicit WebApkInstallerRunner(const GURL& icon_url) | 94 explicit WebApkInstallerRunner(const GURL& icon_url) |
| 87 : url_request_context_getter_(new net::TestURLRequestContextGetter( | 95 : url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 88 base::ThreadTaskRunnerHandle::Get())), | 96 base::ThreadTaskRunnerHandle::Get())), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 135 |
| 128 void Run() { | 136 void Run() { |
| 129 base::RunLoop run_loop; | 137 base::RunLoop run_loop; |
| 130 on_completed_callback_ = run_loop.QuitClosure(); | 138 on_completed_callback_ = run_loop.QuitClosure(); |
| 131 run_loop.Run(); | 139 run_loop.Run(); |
| 132 } | 140 } |
| 133 | 141 |
| 134 bool success() { return success_; } | 142 bool success() { return success_; } |
| 135 | 143 |
| 136 private: | 144 private: |
| 137 void OnCompleted(bool success) { | 145 void OnCompleted(bool success, const std::string& webapk_package) { |
| 138 success_ = success; | 146 success_ = success; |
| 139 on_completed_callback_.Run(); | 147 on_completed_callback_.Run(); |
| 140 } | 148 } |
| 141 | 149 |
| 142 scoped_refptr<net::TestURLRequestContextGetter> | 150 scoped_refptr<net::TestURLRequestContextGetter> |
| 143 url_request_context_getter_; | 151 url_request_context_getter_; |
| 144 | 152 |
| 145 // The Web Manifest's icon URL. | 153 // The Web Manifest's icon URL. |
| 146 const GURL icon_url_; | 154 const GURL icon_url_; |
| 147 | 155 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 runner->RunInstallWebApk(); | 341 runner->RunInstallWebApk(); |
| 334 EXPECT_FALSE(runner->success()); | 342 EXPECT_FALSE(runner->success()); |
| 335 } | 343 } |
| 336 | 344 |
| 337 // Test update succeeding. | 345 // Test update succeeding. |
| 338 TEST_F(WebApkInstallerTest, UpdateSuccess) { | 346 TEST_F(WebApkInstallerTest, UpdateSuccess) { |
| 339 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); | 347 std::unique_ptr<WebApkInstallerRunner> runner = CreateWebApkInstallerRunner(); |
| 340 runner->RunUpdateWebApk(); | 348 runner->RunUpdateWebApk(); |
| 341 EXPECT_TRUE(runner->success()); | 349 EXPECT_TRUE(runner->success()); |
| 342 } | 350 } |
| OLD | NEW |