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_icon_hasher.h" | 5 #include "chrome/browser/android/webapk/webapk_icon_hasher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Runs WebApkIconHasher and blocks till the murmur2 hash is computed. | 31 // Runs WebApkIconHasher and blocks till the murmur2 hash is computed. |
32 class WebApkIconHasherRunner { | 32 class WebApkIconHasherRunner { |
33 public: | 33 public: |
34 WebApkIconHasherRunner() | 34 WebApkIconHasherRunner() |
35 : url_request_context_getter_(new net::TestURLRequestContextGetter( | 35 : url_request_context_getter_(new net::TestURLRequestContextGetter( |
36 base::ThreadTaskRunnerHandle::Get())) {} | 36 base::ThreadTaskRunnerHandle::Get())) {} |
37 ~WebApkIconHasherRunner() {} | 37 ~WebApkIconHasherRunner() {} |
38 | 38 |
39 void Run(const GURL& icon_url) { | 39 void Run(const GURL& icon_url) { |
40 WebApkIconHasher hasher(url_request_context_getter_.get(), icon_url, | 40 WebApkIconHasher::DownloadAndComputeMurmur2Hash( |
| 41 url_request_context_getter_.get(), icon_url, |
41 base::Bind(&WebApkIconHasherRunner::OnCompleted, | 42 base::Bind(&WebApkIconHasherRunner::OnCompleted, |
42 base::Unretained(this))); | 43 base::Unretained(this))); |
43 hasher.DownloadAndComputeMurmur2Hash(); | |
44 | 44 |
45 base::RunLoop run_loop; | 45 base::RunLoop run_loop; |
46 on_completed_callback_ = run_loop.QuitClosure(); | 46 on_completed_callback_ = run_loop.QuitClosure(); |
47 run_loop.Run(); | 47 run_loop.Run(); |
48 } | 48 } |
49 | 49 |
50 const std::string& murmur2_hash() { return murmur2_hash_; } | 50 const std::string& murmur2_hash() { return murmur2_hash_; } |
51 | 51 |
52 private: | 52 private: |
53 void OnCompleted(const std::string& murmur2_hash) { | 53 void OnCompleted(const std::string& murmur2_hash) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 | 128 |
129 // Test that the hash callback is called with an empty string if an HTTP error | 129 // Test that the hash callback is called with an empty string if an HTTP error |
130 // prevents the icon URL from being fetched. | 130 // prevents the icon URL from being fetched. |
131 TEST_F(WebApkIconHasherTest, HTTPError) { | 131 TEST_F(WebApkIconHasherTest, HTTPError) { |
132 GURL icon_url = test_server()->GetURL("/nocontent"); | 132 GURL icon_url = test_server()->GetURL("/nocontent"); |
133 WebApkIconHasherRunner runner; | 133 WebApkIconHasherRunner runner; |
134 runner.Run(icon_url); | 134 runner.Run(icon_url); |
135 EXPECT_EQ("", runner.murmur2_hash()); | 135 EXPECT_EQ("", runner.murmur2_hash()); |
136 } | 136 } |
OLD | NEW |