| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/test/ppapi/ppapi_test.h" | 11 #include "chrome/test/ppapi/ppapi_test.h" |
| 12 #include "ppapi/shared_impl/test_utils.h" | 12 #include "ppapi/shared_impl/test_utils.h" |
| 13 #include "ui/shell_dialogs/select_file_dialog.h" | 13 #include "ui/shell_dialogs/select_file_dialog.h" |
| 14 #include "ui/shell_dialogs/select_file_dialog_factory.h" | 14 #include "ui/shell_dialogs/select_file_dialog_factory.h" |
| 15 #include "ui/shell_dialogs/selected_file_info.h" | 15 #include "ui/shell_dialogs/selected_file_info.h" |
| 16 | 16 |
| 17 #if defined(FULL_SAFE_BROWSING) | 17 #if defined(FULL_SAFE_BROWSING) |
| 18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 18 #include "chrome/browser/safe_browsing/test_safe_browsing_service.h" |
| 19 #include "components/safe_browsing_db/test_database_manager.h" | 19 #include "components/safe_browsing_db/test_database_manager.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 using safe_browsing::SafeBrowsingService; | 22 using safe_browsing::SafeBrowsingService; |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 class TestSelectFileDialogFactory final : public ui::SelectFileDialogFactory { | 26 class TestSelectFileDialogFactory final : public ui::SelectFileDialogFactory { |
| 27 public: | 27 public: |
| 28 using SelectedFileInfoList = std::vector<ui::SelectedFileInfo>; | 28 using SelectedFileInfoList = std::vector<ui::SelectedFileInfo>; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 bool MatchDownloadWhitelistUrl(const GURL& url) override { | 131 bool MatchDownloadWhitelistUrl(const GURL& url) override { |
| 132 // This matches the behavior in RunTestViaHTTP(). | 132 // This matches the behavior in RunTestViaHTTP(). |
| 133 return url.SchemeIsHTTPOrHTTPS() && url.has_path() && | 133 return url.SchemeIsHTTPOrHTTPS() && url.has_path() && |
| 134 url.path().find("/test_case.html") == 0; | 134 url.path().find("/test_case.html") == 0; |
| 135 } | 135 } |
| 136 | 136 |
| 137 protected: | 137 protected: |
| 138 ~FakeDatabaseManager() override {} | 138 ~FakeDatabaseManager() override {} |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 class TestSafeBrowsingService : public SafeBrowsingService { | |
| 142 public: | |
| 143 safe_browsing::SafeBrowsingDatabaseManager* CreateDatabaseManager() override { | |
| 144 return new FakeDatabaseManager(); | |
| 145 } | |
| 146 | |
| 147 protected: | |
| 148 ~TestSafeBrowsingService() override {} | |
| 149 | |
| 150 safe_browsing::SafeBrowsingProtocolManagerDelegate* | |
| 151 GetProtocolManagerDelegate() override { | |
| 152 // Our FakeDatabaseManager doesn't implement this delegate. | |
| 153 return NULL; | |
| 154 } | |
| 155 }; | |
| 156 | |
| 157 class TestSafeBrowsingServiceFactory | |
| 158 : public safe_browsing::SafeBrowsingServiceFactory { | |
| 159 public: | |
| 160 SafeBrowsingService* CreateSafeBrowsingService() override { | |
| 161 SafeBrowsingService* service = new TestSafeBrowsingService(); | |
| 162 return service; | |
| 163 } | |
| 164 }; | |
| 165 | |
| 166 class PPAPIFileChooserTest : public OutOfProcessPPAPITest {}; | 141 class PPAPIFileChooserTest : public OutOfProcessPPAPITest {}; |
| 167 | 142 |
| 168 class PPAPIFileChooserTestWithSBService : public PPAPIFileChooserTest { | 143 class PPAPIFileChooserTestWithSBService : public PPAPIFileChooserTest { |
| 169 public: | 144 public: |
| 170 void SetUp() override { | 145 void SetUp() override { |
| 146 safe_browsing_service_factory_.SetTestDatabaseManager( |
| 147 new FakeDatabaseManager()); |
| 171 SafeBrowsingService::RegisterFactory(&safe_browsing_service_factory_); | 148 SafeBrowsingService::RegisterFactory(&safe_browsing_service_factory_); |
| 172 PPAPIFileChooserTest::SetUp(); | 149 PPAPIFileChooserTest::SetUp(); |
| 173 } | 150 } |
| 151 |
| 174 void TearDown() override { | 152 void TearDown() override { |
| 175 PPAPIFileChooserTest::TearDown(); | 153 PPAPIFileChooserTest::TearDown(); |
| 176 SafeBrowsingService::RegisterFactory(nullptr); | 154 SafeBrowsingService::RegisterFactory(nullptr); |
| 177 } | 155 } |
| 178 | 156 |
| 179 private: | 157 protected: |
| 180 TestSafeBrowsingServiceFactory safe_browsing_service_factory_; | 158 safe_browsing::TestSafeBrowsingServiceFactory safe_browsing_service_factory_; |
| 181 }; | 159 }; |
| 182 | 160 |
| 183 } // namespace | 161 } // namespace |
| 184 | 162 |
| 185 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) { | 163 IN_PROC_BROWSER_TEST_F(PPAPIFileChooserTest, FileChooser_Open_Success) { |
| 186 const char kContents[] = "Hello from browser"; | 164 const char kContents[] = "Hello from browser"; |
| 187 base::ScopedTempDir temp_dir; | 165 base::ScopedTempDir temp_dir; |
| 188 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 166 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 189 | 167 |
| 190 base::FilePath existing_filename = temp_dir.path().AppendASCII("foo"); | 168 base::FilePath existing_filename = temp_dir.path().AppendASCII("foo"); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); | 319 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); |
| 342 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); | 320 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); |
| 343 | 321 |
| 344 ASSERT_TRUE(base::PathExists(actual_filename)); | 322 ASSERT_TRUE(base::PathExists(actual_filename)); |
| 345 std::string file_contents; | 323 std::string file_contents; |
| 346 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); | 324 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents)); |
| 347 EXPECT_EQ("Hello from PPAPI", file_contents); | 325 EXPECT_EQ("Hello from PPAPI", file_contents); |
| 348 } | 326 } |
| 349 | 327 |
| 350 #endif // FULL_SAFE_BROWSING | 328 #endif // FULL_SAFE_BROWSING |
| OLD | NEW |