Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/api/file_handlers/mime_util.h" | 5 #include "chrome/browser/extensions/api/file_handlers/mime_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 base::FilePath html_mime_file_path_; | 69 base::FilePath html_mime_file_path_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 TEST_F(FileHandlersMimeUtilTest, GetMimeTypeForLocalPath) { | 72 TEST_F(FileHandlersMimeUtilTest, GetMimeTypeForLocalPath) { |
| 73 { | 73 { |
| 74 std::string result; | 74 std::string result; |
| 75 GetMimeTypeForLocalPath( | 75 GetMimeTypeForLocalPath( |
| 76 &profile_, | 76 &profile_, |
| 77 base::FilePath::FromUTF8Unsafe(kJPEGExtensionFilePath), | 77 base::FilePath::FromUTF8Unsafe(kJPEGExtensionFilePath), |
| 78 base::Bind(&OnMimeTypeResult, &result)); | 78 base::Bind(&OnMimeTypeResult, &result)); |
| 79 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 79 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
| 80 EXPECT_EQ("image/jpeg", result); | 81 EXPECT_EQ("image/jpeg", result); |
| 81 } | 82 } |
| 82 | 83 |
| 83 { | 84 { |
| 84 std::string result; | 85 std::string result; |
| 85 GetMimeTypeForLocalPath( | 86 GetMimeTypeForLocalPath( |
| 86 &profile_, | 87 &profile_, |
| 87 base::FilePath::FromUTF8Unsafe(kJPEGExtensionUpperCaseFilePath), | 88 base::FilePath::FromUTF8Unsafe(kJPEGExtensionUpperCaseFilePath), |
| 88 base::Bind(&OnMimeTypeResult, &result)); | 89 base::Bind(&OnMimeTypeResult, &result)); |
| 90 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 89 base::RunLoop().RunUntilIdle(); | 91 base::RunLoop().RunUntilIdle(); |
| 90 EXPECT_EQ("image/jpeg", result); | 92 EXPECT_EQ("image/jpeg", result); |
| 91 } | 93 } |
| 92 | 94 |
| 93 { | 95 { |
| 94 std::string result; | 96 std::string result; |
| 95 GetMimeTypeForLocalPath(&profile_, | 97 GetMimeTypeForLocalPath(&profile_, |
| 96 html_mime_file_path_, | 98 html_mime_file_path_, |
| 97 base::Bind(&OnMimeTypeResult, &result)); | 99 base::Bind(&OnMimeTypeResult, &result)); |
| 100 | |
| 101 // Since there are two calls to the blocking pool, it has to be flushed | |
| 102 // twice. | |
| 98 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 103 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 99 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 105 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 106 base::RunLoop().RunUntilIdle(); | |
| 107 | |
| 100 EXPECT_EQ("text/html", result); | 108 EXPECT_EQ("text/html", result); |
| 101 } | 109 } |
| 102 } | 110 } |
| 103 | 111 |
| 104 TEST_F(FileHandlersMimeUtilTest, MimeTypeCollector_ForURLs) { | 112 TEST_F(FileHandlersMimeUtilTest, MimeTypeCollector_ForURLs) { |
| 105 MimeTypeCollector collector(&profile_); | 113 MimeTypeCollector collector(&profile_); |
| 106 | 114 |
| 107 std::vector<fileapi::FileSystemURL> urls; | 115 std::vector<fileapi::FileSystemURL> urls; |
| 108 urls.push_back(CreateNativeLocalFileSystemURL( | 116 urls.push_back(CreateNativeLocalFileSystemURL( |
| 109 file_system_context_, | 117 file_system_context_, |
| 110 base::FilePath::FromUTF8Unsafe(kJPEGExtensionFilePath))); | 118 base::FilePath::FromUTF8Unsafe(kJPEGExtensionFilePath))); |
| 111 urls.push_back(CreateNativeLocalFileSystemURL( | 119 urls.push_back(CreateNativeLocalFileSystemURL( |
| 112 file_system_context_, | 120 file_system_context_, |
| 113 base::FilePath::FromUTF8Unsafe(kJPEGExtensionUpperCaseFilePath))); | 121 base::FilePath::FromUTF8Unsafe(kJPEGExtensionUpperCaseFilePath))); |
| 114 urls.push_back(CreateNativeLocalFileSystemURL(file_system_context_, | 122 urls.push_back(CreateNativeLocalFileSystemURL(file_system_context_, |
| 115 html_mime_file_path_)); | 123 html_mime_file_path_)); |
| 116 | 124 |
| 117 std::vector<std::string> result; | 125 std::vector<std::string> result; |
| 118 collector.CollectForURLs(urls, base::Bind(&OnMimeTypesCollected, &result)); | 126 collector.CollectForURLs(urls, base::Bind(&OnMimeTypesCollected, &result)); |
| 119 | 127 |
| 120 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 128 // Each URL may do up to 2 calls to the blocking pool. Hence, we need to |
| 121 base::RunLoop().RunUntilIdle(); | 129 // flush it at least 6 times. This is unelegant, but there seem to be no |
|
not at google - send to devlin
2014/07/08 16:02:28
inelegant
and indeed.
it would be nice if FlushF
mtomasz
2014/07/09 02:21:02
I just found a utility function in drive code:
htt
not at google - send to devlin
2014/07/09 02:38:20
hey that would be good. how do you propose to reus
mtomasz
2014/07/09 03:55:42
We could move that code from test_util.h|cc to a n
not at google - send to devlin
2014/07/09 13:23:50
sounds good.
| |
| 130 // better way. | |
| 131 for (int i = 0; i < 6; ++i) { | |
| 132 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 133 base::RunLoop().RunUntilIdle(); | |
| 134 } | |
| 122 | 135 |
| 123 ASSERT_EQ(3u, result.size()); | 136 ASSERT_EQ(3u, result.size()); |
| 124 EXPECT_EQ("image/jpeg", result[0]); | 137 EXPECT_EQ("image/jpeg", result[0]); |
| 125 EXPECT_EQ("image/jpeg", result[1]); | 138 EXPECT_EQ("image/jpeg", result[1]); |
| 126 EXPECT_EQ("text/html", result[2]); | 139 EXPECT_EQ("text/html", result[2]); |
| 127 } | 140 } |
| 128 | 141 |
| 129 TEST_F(FileHandlersMimeUtilTest, MimeTypeCollector_ForLocalPaths) { | 142 TEST_F(FileHandlersMimeUtilTest, MimeTypeCollector_ForLocalPaths) { |
| 130 MimeTypeCollector collector(&profile_); | 143 MimeTypeCollector collector(&profile_); |
| 131 | 144 |
| 132 std::vector<base::FilePath> local_paths; | 145 std::vector<base::FilePath> local_paths; |
| 133 local_paths.push_back(base::FilePath::FromUTF8Unsafe(kJPEGExtensionFilePath)); | 146 local_paths.push_back(base::FilePath::FromUTF8Unsafe(kJPEGExtensionFilePath)); |
| 134 local_paths.push_back( | 147 local_paths.push_back( |
| 135 base::FilePath::FromUTF8Unsafe(kJPEGExtensionUpperCaseFilePath)); | 148 base::FilePath::FromUTF8Unsafe(kJPEGExtensionUpperCaseFilePath)); |
| 136 local_paths.push_back(html_mime_file_path_); | 149 local_paths.push_back(html_mime_file_path_); |
| 137 | 150 |
| 138 std::vector<std::string> result; | 151 std::vector<std::string> result; |
| 139 collector.CollectForLocalPaths(local_paths, | 152 collector.CollectForLocalPaths(local_paths, |
| 140 base::Bind(&OnMimeTypesCollected, &result)); | 153 base::Bind(&OnMimeTypesCollected, &result)); |
| 141 | 154 |
| 142 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 155 for (int i = 0; i < 6; ++i) { |
| 143 base::RunLoop().RunUntilIdle(); | 156 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 157 base::RunLoop().RunUntilIdle(); | |
| 158 } | |
| 144 | 159 |
| 145 ASSERT_EQ(3u, result.size()); | 160 ASSERT_EQ(3u, result.size()); |
| 146 EXPECT_EQ("image/jpeg", result[0]); | 161 EXPECT_EQ("image/jpeg", result[0]); |
| 147 EXPECT_EQ("image/jpeg", result[1]); | 162 EXPECT_EQ("image/jpeg", result[1]); |
| 148 EXPECT_EQ("text/html", result[2]); | 163 EXPECT_EQ("text/html", result[2]); |
| 149 } | 164 } |
| 150 | 165 |
| 151 } // namespace app_file_handler_util | 166 } // namespace app_file_handler_util |
| 152 } // namespace extensions | 167 } // namespace extensions |
| OLD | NEW |