| 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" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "content/public/test/test_browser_thread_bundle.h" | 15 #include "content/public/test/test_browser_thread_bundle.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 16 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const base::FilePath::CharType kTestDataDir[] = | 23 const base::FilePath::CharType kTestDataDir[] = |
| 24 FILE_PATH_LITERAL("chrome/test/data"); | 24 FILE_PATH_LITERAL("chrome/test/data"); |
| 25 | 25 |
| 26 const char kIconUrl[] = "/android/google.png"; | 26 const char kIconUrl[] = "/android/google.png"; |
| 27 | 27 |
| 28 // Murmur2 hash for |kIconUrl|. | 28 // Murmur2 hash for |kIconUrl|. |
| 29 const char kIconMurmur2Hash[] = "13321047016824288610"; | 29 const char kIconMurmur2Hash[] = "2081059568551351877"; |
| 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) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 // Test that the hash callback is called with an empty string if an HTTP error | 100 // Test that the hash callback is called with an empty string if an HTTP error |
| 101 // prevents the icon URL from being fetched. | 101 // prevents the icon URL from being fetched. |
| 102 TEST_F(WebApkIconHasherTest, HTTPError) { | 102 TEST_F(WebApkIconHasherTest, HTTPError) { |
| 103 GURL icon_url = test_server()->GetURL("/nocontent"); | 103 GURL icon_url = test_server()->GetURL("/nocontent"); |
| 104 WebApkIconHasherRunner runner; | 104 WebApkIconHasherRunner runner; |
| 105 runner.Run(icon_url); | 105 runner.Run(icon_url); |
| 106 EXPECT_EQ("", runner.murmur2_hash()); | 106 EXPECT_EQ("", runner.murmur2_hash()); |
| 107 } | 107 } |
| OLD | NEW |