| 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/media_galleries/fileapi/iapps_finder_impl.h" | 5 #include "chrome/browser/media_galleries/fileapi/iapps_finder_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/base_paths_win.h" | 10 #include "base/base_paths_win.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/test/scoped_path_override.h" | 19 #include "base/test/scoped_path_override.h" |
| 20 #include "base/threading/thread_restrictions.h" |
| 20 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 22 | 23 |
| 23 namespace iapps { | 24 namespace iapps { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 std::string EncodePath(const base::FilePath& path) { | 28 std::string EncodePath(const base::FilePath& path) { |
| 28 std::string input(reinterpret_cast<const char*>(path.value().data()), | 29 std::string input(reinterpret_cast<const char*>(path.value().data()), |
| 29 path.value().size()*2); | 30 path.value().size()*2); |
| 30 std::string result; | 31 std::string result; |
| 31 base::Base64Encode(input, &result); | 32 base::Base64Encode(input, &result); |
| 32 return result; | 33 return result; |
| 33 } | 34 } |
| 34 | 35 |
| 35 void TouchFile(const base::FilePath& file) { | 36 void TouchFile(const base::FilePath& file) { |
| 37 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 36 ASSERT_EQ(1, base::WriteFile(file, " ", 1)); | 38 ASSERT_EQ(1, base::WriteFile(file, " ", 1)); |
| 37 } | 39 } |
| 38 | 40 |
| 39 class ITunesFinderWinTest : public InProcessBrowserTest { | 41 class ITunesFinderWinTest : public InProcessBrowserTest { |
| 40 public: | 42 public: |
| 41 ITunesFinderWinTest() : test_finder_callback_called_(false) {} | 43 ITunesFinderWinTest() : test_finder_callback_called_(false) {} |
| 42 | 44 |
| 43 ~ITunesFinderWinTest() override {} | 45 ~ITunesFinderWinTest() override {} |
| 44 | 46 |
| 45 void SetUp() override { | 47 void SetUp() override { |
| 46 ASSERT_TRUE(app_data_dir_.CreateUniqueTempDir()); | 48 ASSERT_TRUE(app_data_dir_.CreateUniqueTempDir()); |
| 47 ASSERT_TRUE(music_dir_.CreateUniqueTempDir()); | 49 ASSERT_TRUE(music_dir_.CreateUniqueTempDir()); |
| 48 app_data_dir_override_.reset( | 50 app_data_dir_override_.reset( |
| 49 new base::ScopedPathOverride(base::DIR_APP_DATA, app_data_dir())); | 51 new base::ScopedPathOverride(base::DIR_APP_DATA, app_data_dir())); |
| 50 music_dir_override_.reset( | 52 music_dir_override_.reset( |
| 51 new base::ScopedPathOverride(chrome::DIR_USER_MUSIC, music_dir())); | 53 new base::ScopedPathOverride(chrome::DIR_USER_MUSIC, music_dir())); |
| 52 InProcessBrowserTest::SetUp(); | 54 InProcessBrowserTest::SetUp(); |
| 53 } | 55 } |
| 54 | 56 |
| 55 const base::FilePath& app_data_dir() { return app_data_dir_.GetPath(); } | 57 const base::FilePath& app_data_dir() { return app_data_dir_.GetPath(); } |
| 56 | 58 |
| 57 const base::FilePath& music_dir() { return music_dir_.GetPath(); } | 59 const base::FilePath& music_dir() { return music_dir_.GetPath(); } |
| 58 | 60 |
| 59 void WritePrefFile(const std::string& data) { | 61 void WritePrefFile(const std::string& data) { |
| 62 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 60 base::FilePath pref_dir = | 63 base::FilePath pref_dir = |
| 61 app_data_dir().AppendASCII("Apple Computer").AppendASCII("iTunes"); | 64 app_data_dir().AppendASCII("Apple Computer").AppendASCII("iTunes"); |
| 62 ASSERT_TRUE(base::CreateDirectory(pref_dir)); | 65 ASSERT_TRUE(base::CreateDirectory(pref_dir)); |
| 63 ASSERT_EQ(static_cast<int>(data.size()), | 66 ASSERT_EQ(static_cast<int>(data.size()), |
| 64 base::WriteFile(pref_dir.AppendASCII("iTunesPrefs.xml"), | 67 base::WriteFile(pref_dir.AppendASCII("iTunesPrefs.xml"), |
| 65 data.data(), data.size())); | 68 data.data(), data.size())); |
| 66 } | 69 } |
| 67 | 70 |
| 68 void TouchDefault() { | 71 void TouchDefault() { |
| 72 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 69 base::FilePath default_dir = music_dir().AppendASCII("iTunes"); | 73 base::FilePath default_dir = music_dir().AppendASCII("iTunes"); |
| 70 ASSERT_TRUE(base::CreateDirectory(default_dir)); | 74 ASSERT_TRUE(base::CreateDirectory(default_dir)); |
| 71 TouchFile(default_dir.AppendASCII("iTunes Music Library.xml")); | 75 TouchFile(default_dir.AppendASCII("iTunes Music Library.xml")); |
| 72 } | 76 } |
| 73 | 77 |
| 74 void TestFindITunesLibrary() { | 78 void TestFindITunesLibrary() { |
| 79 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 75 test_finder_callback_called_ = false; | 80 test_finder_callback_called_ = false; |
| 76 result_.clear(); | 81 result_.clear(); |
| 77 base::RunLoop loop; | 82 base::RunLoop loop; |
| 78 FindITunesLibrary(base::Bind(&ITunesFinderWinTest::TestFinderCallback, | 83 FindITunesLibrary(base::Bind(&ITunesFinderWinTest::TestFinderCallback, |
| 79 base::Unretained(this), loop.QuitClosure())); | 84 base::Unretained(this), loop.QuitClosure())); |
| 80 loop.Run(); | 85 loop.Run(); |
| 81 } | 86 } |
| 82 | 87 |
| 83 bool EmptyResult() const { | 88 bool EmptyResult() const { |
| 84 return result_.empty(); | 89 return result_.empty(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 "</plist>", EncodePath(library_xml).c_str()); | 189 "</plist>", EncodePath(library_xml).c_str()); |
| 185 WritePrefFile(xml); | 190 WritePrefFile(xml); |
| 186 TestFindITunesLibrary(); | 191 TestFindITunesLibrary(); |
| 187 EXPECT_TRUE(test_finder_callback_called()); | 192 EXPECT_TRUE(test_finder_callback_called()); |
| 188 EXPECT_TRUE(EmptyResult()); | 193 EXPECT_TRUE(EmptyResult()); |
| 189 } | 194 } |
| 190 | 195 |
| 191 } // namespace | 196 } // namespace |
| 192 | 197 |
| 193 } // namespace iapps | 198 } // namespace iapps |
| OLD | NEW |