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/safe_browsing_service.h" |
19 #include "chrome/browser/safe_browsing/test_database_manager.h" | 19 #include "chrome/browser/safe_browsing/test_database_manager.h" |
20 #endif | 20 #endif |
21 | 21 |
| 22 using safe_browsing::SafeBrowsingService; |
| 23 |
22 namespace { | 24 namespace { |
23 | 25 |
24 class TestSelectFileDialogFactory final : public ui::SelectFileDialogFactory { | 26 class TestSelectFileDialogFactory final : public ui::SelectFileDialogFactory { |
25 public: | 27 public: |
26 using SelectedFileInfoList = std::vector<ui::SelectedFileInfo>; | 28 using SelectedFileInfoList = std::vector<ui::SelectedFileInfo>; |
27 | 29 |
28 enum Mode { | 30 enum Mode { |
29 RESPOND_WITH_FILE_LIST, | 31 RESPOND_WITH_FILE_LIST, |
30 CANCEL, | 32 CANCEL, |
31 REPLACE_BASENAME, | 33 REPLACE_BASENAME, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 117 } |
116 | 118 |
117 SelectedFileInfoList selected_file_info_; | 119 SelectedFileInfoList selected_file_info_; |
118 Mode mode_; | 120 Mode mode_; |
119 }; | 121 }; |
120 | 122 |
121 std::vector<ui::SelectedFileInfo> selected_file_info_; | 123 std::vector<ui::SelectedFileInfo> selected_file_info_; |
122 Mode mode_; | 124 Mode mode_; |
123 }; | 125 }; |
124 | 126 |
125 class FakeDatabaseManager : public TestSafeBrowsingDatabaseManager { | 127 class FakeDatabaseManager |
| 128 : public safe_browsing::TestSafeBrowsingDatabaseManager { |
126 public: | 129 public: |
127 bool IsSupported() const override { return true; } | 130 bool IsSupported() const override { return true; } |
128 bool MatchDownloadWhitelistUrl(const GURL& url) override { | 131 bool MatchDownloadWhitelistUrl(const GURL& url) override { |
129 // This matches the behavior in RunTestViaHTTP(). | 132 // This matches the behavior in RunTestViaHTTP(). |
130 return url.SchemeIsHTTPOrHTTPS() && url.has_path() && | 133 return url.SchemeIsHTTPOrHTTPS() && url.has_path() && |
131 url.path().find("/files/test_case.html") == 0; | 134 url.path().find("/files/test_case.html") == 0; |
132 } | 135 } |
133 | 136 |
134 protected: | 137 protected: |
135 ~FakeDatabaseManager() override {} | 138 ~FakeDatabaseManager() override {} |
136 }; | 139 }; |
137 | 140 |
138 class TestSafeBrowsingService : public SafeBrowsingService { | 141 class TestSafeBrowsingService : public SafeBrowsingService { |
139 public: | 142 public: |
140 SafeBrowsingDatabaseManager* CreateDatabaseManager() override { | 143 safe_browsing::SafeBrowsingDatabaseManager* CreateDatabaseManager() override { |
141 return new FakeDatabaseManager(); | 144 return new FakeDatabaseManager(); |
142 } | 145 } |
143 | 146 |
144 protected: | 147 protected: |
145 ~TestSafeBrowsingService() override {} | 148 ~TestSafeBrowsingService() override {} |
146 | 149 |
147 SafeBrowsingProtocolManagerDelegate* GetProtocolManagerDelegate() override { | 150 safe_browsing::SafeBrowsingProtocolManagerDelegate* |
| 151 GetProtocolManagerDelegate() override { |
148 // Our FakeDatabaseManager doesn't implement this delegate. | 152 // Our FakeDatabaseManager doesn't implement this delegate. |
149 return NULL; | 153 return NULL; |
150 } | 154 } |
151 }; | 155 }; |
152 | 156 |
153 class TestSafeBrowsingServiceFactory : public SafeBrowsingServiceFactory { | 157 class TestSafeBrowsingServiceFactory |
| 158 : public safe_browsing::SafeBrowsingServiceFactory { |
154 public: | 159 public: |
155 SafeBrowsingService* CreateSafeBrowsingService() override { | 160 SafeBrowsingService* CreateSafeBrowsingService() override { |
156 SafeBrowsingService* service = new TestSafeBrowsingService(); | 161 SafeBrowsingService* service = new TestSafeBrowsingService(); |
157 return service; | 162 return service; |
158 } | 163 } |
159 }; | 164 }; |
160 | 165 |
161 class PPAPIFileChooserTest : public OutOfProcessPPAPITest {}; | 166 class PPAPIFileChooserTest : public OutOfProcessPPAPITest {}; |
162 | 167 |
163 class PPAPIFileChooserTestWithSBService : public PPAPIFileChooserTest { | 168 class PPAPIFileChooserTestWithSBService : public PPAPIFileChooserTest { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); | 331 RunTestViaHTTP("FileChooser_SaveAsDangerousExecutableAllowed"); |
327 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); | 332 base::FilePath actual_filename = temp_dir.path().AppendASCII("dangerous.exe"); |
328 | 333 |
329 ASSERT_TRUE(base::PathExists(actual_filename)); | 334 ASSERT_TRUE(base::PathExists(actual_filename)); |
330 std::string file_contents; | 335 std::string file_contents; |
331 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); | 336 ASSERT_TRUE(base::ReadFileToString(actual_filename, &file_contents, 100)); |
332 EXPECT_EQ("Hello from PPAPI", file_contents); | 337 EXPECT_EQ("Hello from PPAPI", file_contents); |
333 } | 338 } |
334 | 339 |
335 #endif // FULL_SAFE_BROWSING | 340 #endif // FULL_SAFE_BROWSING |
OLD | NEW |