| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 7 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 8 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 8 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 9 | 9 |
| 10 using extensions::FileSystemChooseFileFunction; | 10 using extensions::FileSystemChooseEntryFunction; |
| 11 | 11 |
| 12 class FileSystemApiTest : public extensions::PlatformAppBrowserTest { | 12 class FileSystemApiTest : public extensions::PlatformAppBrowserTest { |
| 13 public: | 13 public: |
| 14 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 14 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 15 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 15 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 16 test_root_folder_ = test_data_dir_.AppendASCII("api_test") | 16 test_root_folder_ = test_data_dir_.AppendASCII("api_test") |
| 17 .AppendASCII("file_system"); | 17 .AppendASCII("file_system"); |
| 18 } | 18 } |
| 19 | 19 |
| 20 virtual void TearDown() OVERRIDE { | 20 virtual void TearDown() OVERRIDE { |
| 21 FileSystemChooseFileFunction::StopSkippingPickerForTest(); | 21 FileSystemChooseEntryFunction::StopSkippingPickerForTest(); |
| 22 extensions::PlatformAppBrowserTest::TearDown(); | 22 extensions::PlatformAppBrowserTest::TearDown(); |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 protected: | 25 protected: |
| 26 FilePath TempFilePath(const std::string& destination_name, bool copy_gold) { | 26 FilePath TempFilePath(const std::string& destination_name, bool copy_gold) { |
| 27 if (!temp_dir_.CreateUniqueTempDir()) { | 27 if (!temp_dir_.CreateUniqueTempDir()) { |
| 28 ADD_FAILURE() << "CreateUniqueTempDir failed"; | 28 ADD_FAILURE() << "CreateUniqueTempDir failed"; |
| 29 return FilePath(); | 29 return FilePath(); |
| 30 } | 30 } |
| 31 FilePath destination = temp_dir_.path().AppendASCII(destination_name); | 31 FilePath destination = temp_dir_.path().AppendASCII(destination_name); |
| 32 if (copy_gold) { | 32 if (copy_gold) { |
| 33 FilePath source = test_root_folder_.AppendASCII("gold.txt"); | 33 FilePath source = test_root_folder_.AppendASCII("gold.txt"); |
| 34 EXPECT_TRUE(file_util::CopyFile(source, destination)); | 34 EXPECT_TRUE(file_util::CopyFile(source, destination)); |
| 35 } | 35 } |
| 36 return destination; | 36 return destination; |
| 37 } | 37 } |
| 38 | 38 |
| 39 FilePath test_root_folder_; | 39 FilePath test_root_folder_; |
| 40 ScopedTempDir temp_dir_; | 40 ScopedTempDir temp_dir_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) { | 43 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPath) { |
| 44 FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); | 44 FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); |
| 45 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 45 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 46 &test_file); | 46 &test_file); |
| 47 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path")) | 47 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/get_display_path")) |
| 48 << message_; | 48 << message_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 #if defined(OS_WIN) || defined(OS_POSIX) | 51 #if defined(OS_WIN) || defined(OS_POSIX) |
| 52 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) { | 52 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetDisplayPathPrettify) { |
| 53 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| 54 int override = base::DIR_PROFILE; | 54 int override = base::DIR_PROFILE; |
| 55 #elif defined(OS_POSIX) | 55 #elif defined(OS_POSIX) |
| 56 int override = base::DIR_HOME; | 56 int override = base::DIR_HOME; |
| 57 #endif | 57 #endif |
| 58 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(override, | 58 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded(override, |
| 59 test_root_folder_, false)); | 59 test_root_folder_, false)); |
| 60 | 60 |
| 61 FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); | 61 FilePath test_file = test_root_folder_.AppendASCII("gold.txt"); |
| 62 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 62 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 63 &test_file); | 63 &test_file); |
| 64 ASSERT_TRUE(RunPlatformAppTest( | 64 ASSERT_TRUE(RunPlatformAppTest( |
| 65 "api_test/file_system/get_display_path_prettify")) << message_; | 65 "api_test/file_system/get_display_path_prettify")) << message_; |
| 66 } | 66 } |
| 67 #endif | 67 #endif |
| 68 | 68 |
| 69 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) { | 69 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenExistingFileTest) { |
| 70 FilePath test_file = TempFilePath("open_existing.txt", true); | 70 FilePath test_file = TempFilePath("open_existing.txt", true); |
| 71 ASSERT_FALSE(test_file.empty()); | 71 ASSERT_FALSE(test_file.empty()); |
| 72 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 72 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 73 &test_file); | 73 &test_file); |
| 74 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) | 74 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) |
| 75 << message_; | 75 << message_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 78 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 79 FileSystemApiInvalidChooseFileTypeTest) { | 79 FileSystemApiInvalidChooseEntryTypeTest) { |
| 80 FilePath test_file = TempFilePath("open_existing.txt", true); | 80 FilePath test_file = TempFilePath("open_existing.txt", true); |
| 81 ASSERT_FALSE(test_file.empty()); | 81 ASSERT_FALSE(test_file.empty()); |
| 82 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 82 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 83 &test_file); | 83 &test_file); |
| 84 ASSERT_TRUE(RunPlatformAppTest( | 84 ASSERT_TRUE(RunPlatformAppTest( |
| 85 "api_test/file_system/invalid_choose_file_type")) << message_; | 85 "api_test/file_system/invalid_choose_file_type")) << message_; |
| 86 } | 86 } |
| 87 | 87 |
| 88 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 88 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 89 FileSystemApiOpenExistingFileWithWriteTest) { | 89 FileSystemApiOpenExistingFileWithWriteTest) { |
| 90 FilePath test_file = TempFilePath("open_existing.txt", true); | 90 FilePath test_file = TempFilePath("open_existing.txt", true); |
| 91 ASSERT_FALSE(test_file.empty()); | 91 ASSERT_FALSE(test_file.empty()); |
| 92 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 92 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 93 &test_file); | 93 &test_file); |
| 94 ASSERT_TRUE(RunPlatformAppTest( | 94 ASSERT_TRUE(RunPlatformAppTest( |
| 95 "api_test/file_system/open_existing_with_write")) << message_; | 95 "api_test/file_system/open_existing_with_write")) << message_; |
| 96 } | 96 } |
| 97 | 97 |
| 98 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 98 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 99 FileSystemApiOpenWritableExistingFileTest) { | 99 FileSystemApiOpenWritableExistingFileTest) { |
| 100 FilePath test_file = TempFilePath("open_existing.txt", true); | 100 FilePath test_file = TempFilePath("open_existing.txt", true); |
| 101 ASSERT_FALSE(test_file.empty()); | 101 ASSERT_FALSE(test_file.empty()); |
| 102 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 102 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 103 &test_file); | 103 &test_file); |
| 104 ASSERT_TRUE(RunPlatformAppTest( | 104 ASSERT_TRUE(RunPlatformAppTest( |
| 105 "api_test/file_system/open_writable_existing")) << message_; | 105 "api_test/file_system/open_writable_existing")) << message_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 108 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 109 FileSystemApiOpenWritableExistingFileWithWriteTest) { | 109 FileSystemApiOpenWritableExistingFileWithWriteTest) { |
| 110 FilePath test_file = TempFilePath("open_existing.txt", true); | 110 FilePath test_file = TempFilePath("open_existing.txt", true); |
| 111 ASSERT_FALSE(test_file.empty()); | 111 ASSERT_FALSE(test_file.empty()); |
| 112 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 112 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 113 &test_file); | 113 &test_file); |
| 114 ASSERT_TRUE(RunPlatformAppTest( | 114 ASSERT_TRUE(RunPlatformAppTest( |
| 115 "api_test/file_system/open_writable_existing_with_write")) << message_; | 115 "api_test/file_system/open_writable_existing_with_write")) << message_; |
| 116 } | 116 } |
| 117 | 117 |
| 118 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) { | 118 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenCancelTest) { |
| 119 FileSystemChooseFileFunction::SkipPickerAndAlwaysCancelForTest(); | 119 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); |
| 120 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel")) | 120 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_cancel")) |
| 121 << message_; | 121 << message_; |
| 122 } | 122 } |
| 123 | 123 |
| 124 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) { | 124 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiOpenBackgroundTest) { |
| 125 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background")) | 125 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_background")) |
| 126 << message_; | 126 << message_; |
| 127 } | 127 } |
| 128 | 128 |
| 129 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveNewFileTest) { | 129 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveNewFileTest) { |
| 130 FilePath test_file = TempFilePath("save_new.txt", false); | 130 FilePath test_file = TempFilePath("save_new.txt", false); |
| 131 ASSERT_FALSE(test_file.empty()); | 131 ASSERT_FALSE(test_file.empty()); |
| 132 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 132 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 133 &test_file); | 133 &test_file); |
| 134 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new")) | 134 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new")) |
| 135 << message_; | 135 << message_; |
| 136 } | 136 } |
| 137 | 137 |
| 138 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveExistingFileTest) { | 138 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveExistingFileTest) { |
| 139 FilePath test_file = TempFilePath("save_existing.txt", true); | 139 FilePath test_file = TempFilePath("save_existing.txt", true); |
| 140 ASSERT_FALSE(test_file.empty()); | 140 ASSERT_FALSE(test_file.empty()); |
| 141 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 141 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 142 &test_file); | 142 &test_file); |
| 143 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_existing")) | 143 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_existing")) |
| 144 << message_; | 144 << message_; |
| 145 } | 145 } |
| 146 | 146 |
| 147 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 147 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 148 FileSystemApiSaveNewFileWithWriteTest) { | 148 FileSystemApiSaveNewFileWithWriteTest) { |
| 149 FilePath test_file = TempFilePath("save_new.txt", false); | 149 FilePath test_file = TempFilePath("save_new.txt", false); |
| 150 ASSERT_FALSE(test_file.empty()); | 150 ASSERT_FALSE(test_file.empty()); |
| 151 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 151 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 152 &test_file); | 152 &test_file); |
| 153 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new_with_write")) | 153 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_new_with_write")) |
| 154 << message_; | 154 << message_; |
| 155 } | 155 } |
| 156 | 156 |
| 157 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 157 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 158 FileSystemApiSaveExistingFileWithWriteTest) { | 158 FileSystemApiSaveExistingFileWithWriteTest) { |
| 159 FilePath test_file = TempFilePath("save_existing.txt", true); | 159 FilePath test_file = TempFilePath("save_existing.txt", true); |
| 160 ASSERT_FALSE(test_file.empty()); | 160 ASSERT_FALSE(test_file.empty()); |
| 161 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 161 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 162 &test_file); | 162 &test_file); |
| 163 ASSERT_TRUE(RunPlatformAppTest( | 163 ASSERT_TRUE(RunPlatformAppTest( |
| 164 "api_test/file_system/save_existing_with_write")) << message_; | 164 "api_test/file_system/save_existing_with_write")) << message_; |
| 165 } | 165 } |
| 166 | 166 |
| 167 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) { | 167 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveCancelTest) { |
| 168 FileSystemChooseFileFunction::SkipPickerAndAlwaysCancelForTest(); | 168 FileSystemChooseEntryFunction::SkipPickerAndAlwaysCancelForTest(); |
| 169 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel")) | 169 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_cancel")) |
| 170 << message_; | 170 << message_; |
| 171 } | 171 } |
| 172 | 172 |
| 173 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) { | 173 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiSaveBackgroundTest) { |
| 174 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background")) | 174 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/save_background")) |
| 175 << message_; | 175 << message_; |
| 176 } | 176 } |
| 177 | 177 |
| 178 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetWritableTest) { | 178 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiGetWritableTest) { |
| 179 FilePath test_file = TempFilePath("writable.txt", true); | 179 FilePath test_file = TempFilePath("writable.txt", true); |
| 180 ASSERT_FALSE(test_file.empty()); | 180 ASSERT_FALSE(test_file.empty()); |
| 181 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 181 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 182 &test_file); | 182 &test_file); |
| 183 ASSERT_TRUE(RunPlatformAppTest( | 183 ASSERT_TRUE(RunPlatformAppTest( |
| 184 "api_test/file_system/get_writable_file_entry")) << message_; | 184 "api_test/file_system/get_writable_file_entry")) << message_; |
| 185 } | 185 } |
| 186 | 186 |
| 187 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 187 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
| 188 FileSystemApiGetWritableWithWriteTest) { | 188 FileSystemApiGetWritableWithWriteTest) { |
| 189 FilePath test_file = TempFilePath("writable.txt", true); | 189 FilePath test_file = TempFilePath("writable.txt", true); |
| 190 ASSERT_FALSE(test_file.empty()); | 190 ASSERT_FALSE(test_file.empty()); |
| 191 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 191 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 192 &test_file); | 192 &test_file); |
| 193 ASSERT_TRUE(RunPlatformAppTest( | 193 ASSERT_TRUE(RunPlatformAppTest( |
| 194 "api_test/file_system/get_writable_file_entry_with_write")) << message_; | 194 "api_test/file_system/get_writable_file_entry_with_write")) << message_; |
| 195 } | 195 } |
| 196 | 196 |
| 197 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) { | 197 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiIsWritableTest) { |
| 198 FilePath test_file = TempFilePath("writable.txt", true); | 198 FilePath test_file = TempFilePath("writable.txt", true); |
| 199 ASSERT_FALSE(test_file.empty()); | 199 ASSERT_FALSE(test_file.empty()); |
| 200 FileSystemChooseFileFunction::SkipPickerAndAlwaysSelectPathForTest( | 200 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 201 &test_file); | 201 &test_file); |
| 202 ASSERT_TRUE(RunPlatformAppTest( | 202 ASSERT_TRUE(RunPlatformAppTest( |
| 203 "api_test/file_system/is_writable_file_entry")) << message_; | 203 "api_test/file_system/is_writable_file_entry")) << message_; |
| 204 } | 204 } |
| OLD | NEW |