OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/importer/safari_importer.h" | 5 #include "chrome/browser/importer/safari_importer.h" |
6 | 6 |
7 #include "app/sql/connection.h" | 7 #include "app/sql/connection.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/scoped_temp_dir.h" |
12 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/history/history_types.h" | 15 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/browser/importer/importer_bridge.h" | 16 #include "chrome/browser/importer/importer_bridge.h" |
16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/test/file_test_utils.h" | |
18 #include "testing/platform_test.h" | 18 #include "testing/platform_test.h" |
19 | 19 |
20 // In order to test the Safari import functionality effectively, we store a | 20 // In order to test the Safari import functionality effectively, we store a |
21 // simulated Library directory containing dummy data files in the same | 21 // simulated Library directory containing dummy data files in the same |
22 // structure as ~/Library in the Chrome test data directory. | 22 // structure as ~/Library in the Chrome test data directory. |
23 // This function returns the path to that directory. | 23 // This function returns the path to that directory. |
24 FilePath GetTestSafariLibraryPath() { | 24 FilePath GetTestSafariLibraryPath() { |
25 FilePath test_dir; | 25 FilePath test_dir; |
26 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); | 26 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); |
27 | 27 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 TEST_F(SafariImporterTest, CanImport) { | 150 TEST_F(SafariImporterTest, CanImport) { |
151 uint16 items = importer::NONE; | 151 uint16 items = importer::NONE; |
152 EXPECT_TRUE(SafariImporter::CanImport(GetTestSafariLibraryPath(), &items)); | 152 EXPECT_TRUE(SafariImporter::CanImport(GetTestSafariLibraryPath(), &items)); |
153 EXPECT_EQ(items, importer::HISTORY | importer::FAVORITES); | 153 EXPECT_EQ(items, importer::HISTORY | importer::FAVORITES); |
154 EXPECT_EQ(items & importer::COOKIES, importer::NONE); | 154 EXPECT_EQ(items & importer::COOKIES, importer::NONE); |
155 EXPECT_EQ(items & importer::PASSWORDS, importer::NONE); | 155 EXPECT_EQ(items & importer::PASSWORDS, importer::NONE); |
156 EXPECT_EQ(items & importer::SEARCH_ENGINES, importer::NONE); | 156 EXPECT_EQ(items & importer::SEARCH_ENGINES, importer::NONE); |
157 EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE); | 157 EXPECT_EQ(items & importer::HOME_PAGE, importer::NONE); |
158 | 158 |
159 // Check that we don't import anything from a bogus library directory. | 159 // Check that we don't import anything from a bogus library directory. |
160 FilePath fake_library_dir; | 160 ScopedTempDir fake_library_dir; |
161 file_util::CreateNewTempDirectory("FakeSafariLibrary", &fake_library_dir); | 161 ASSERT_TRUE(fake_library_dir.CreateUniqueTempDir()); |
162 FileAutoDeleter deleter(fake_library_dir); | 162 EXPECT_FALSE(SafariImporter::CanImport(fake_library_dir.path(), &items)); |
163 EXPECT_FALSE(SafariImporter::CanImport(fake_library_dir, &items)); | |
164 } | 163 } |
OLD | NEW |