1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_NATIVE_FILE_SYSTEM_FILE_SYSTEM_CHOOSER_TEST_HELPERS_H_ 6 #define CONTENT_BROWSER_NATIVE_FILE_SYSTEM_FILE_SYSTEM_CHOOSER_TEST_HELPERS_H_ 7 8 #include "base/optional.h" 9 #include "ui/gfx/native_widget_types.h" 10 #include "ui/shell_dialogs/select_file_dialog.h" 11 #include "ui/shell_dialogs/select_file_dialog_factory.h" 12 #include "ui/shell_dialogs/select_file_policy.h" 13 14 namespace content { 15 16 // Struct used to report what parameters one of the (fake) SelectFileDialog 17 // implementations below was created with. 18 struct SelectFileDialogParams { 19 SelectFileDialogParams(); 20 ~SelectFileDialogParams(); 21 22 ui::SelectFileDialog::Type type = ui::SelectFileDialog::SELECT_NONE; 23 base::Optional<ui::SelectFileDialog::FileTypeInfo> file_types; 24 gfx::NativeWindow owning_window = {}; 25 }; 26 27 // A fake ui::SelectFileDialog, which will cancel the file selection instead of 28 // selecting a file. 29 class CancellingSelectFileDialogFactory : public ui::SelectFileDialogFactory { 30 public: 31 explicit CancellingSelectFileDialogFactory( 32 SelectFileDialogParams* out_params = nullptr); 33 ~CancellingSelectFileDialogFactory() override; 34 35 ui::SelectFileDialog* Create( 36 ui::SelectFileDialog::Listener* listener, 37 std::unique_ptr<ui::SelectFilePolicy> policy) override; 38 39 private: 40 SelectFileDialogParams* out_params_; 41 }; 42 43 // A fake ui::SelectFileDialog, which will select one or more pre-determined 44 // files. 45 class FakeSelectFileDialogFactory : public ui::SelectFileDialogFactory { 46 public: 47 FakeSelectFileDialogFactory(std::vector<base::FilePath> result, 48 SelectFileDialogParams* out_params = nullptr); 49 ~FakeSelectFileDialogFactory() override; 50 51 ui::SelectFileDialog* Create( 52 ui::SelectFileDialog::Listener* listener, 53 std::unique_ptr<ui::SelectFilePolicy> policy) override; 54 55 private: 56 std::vector<base::FilePath> result_; 57 SelectFileDialogParams* out_params_; 58 }; 59 60 } // namespace content 61 62 #endif // CONTENT_BROWSER_NATIVE_FILE_SYSTEM_FILE_SYSTEM_CHOOSER_TEST_HELPERS_H_