| 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 "chrome/browser/ui/views/select_file_dialog_extension.h" | 5 #include "chrome/browser/ui/views/select_file_dialog_extension.h" |
| 6 | 6 |
| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool file_selected() const { return file_selected_; } | 45 bool file_selected() const { return file_selected_; } |
| 46 bool canceled() const { return canceled_; } | 46 bool canceled() const { return canceled_; } |
| 47 base::FilePath path() const { return path_; } | 47 base::FilePath path() const { return path_; } |
| 48 void* params() const { return params_; } | 48 void* params() const { return params_; } |
| 49 | 49 |
| 50 // ui::SelectFileDialog::Listener implementation. | 50 // ui::SelectFileDialog::Listener implementation. |
| 51 virtual void FileSelected(const base::FilePath& path, | 51 virtual void FileSelected(const base::FilePath& path, |
| 52 int index, | 52 int index, |
| 53 void* params) OVERRIDE { | 53 void* params) override { |
| 54 file_selected_ = true; | 54 file_selected_ = true; |
| 55 path_ = path; | 55 path_ = path; |
| 56 params_ = params; | 56 params_ = params; |
| 57 } | 57 } |
| 58 virtual void FileSelectedWithExtraInfo( | 58 virtual void FileSelectedWithExtraInfo( |
| 59 const ui::SelectedFileInfo& selected_file_info, | 59 const ui::SelectedFileInfo& selected_file_info, |
| 60 int index, | 60 int index, |
| 61 void* params) OVERRIDE { | 61 void* params) override { |
| 62 FileSelected(selected_file_info.local_path, index, params); | 62 FileSelected(selected_file_info.local_path, index, params); |
| 63 } | 63 } |
| 64 virtual void MultiFilesSelected( | 64 virtual void MultiFilesSelected( |
| 65 const std::vector<base::FilePath>& files, void* params) OVERRIDE {} | 65 const std::vector<base::FilePath>& files, void* params) override {} |
| 66 virtual void FileSelectionCanceled(void* params) OVERRIDE { | 66 virtual void FileSelectionCanceled(void* params) override { |
| 67 canceled_ = true; | 67 canceled_ = true; |
| 68 params_ = params; | 68 params_ = params; |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 bool file_selected_; | 72 bool file_selected_; |
| 73 bool canceled_; | 73 bool canceled_; |
| 74 base::FilePath path_; | 74 base::FilePath path_; |
| 75 void* params_; | 75 void* params_; |
| 76 | 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(MockSelectFileDialogListener); | 77 DISALLOW_COPY_AND_ASSIGN(MockSelectFileDialogListener); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class SelectFileDialogExtensionBrowserTest : public ExtensionBrowserTest { | 80 class SelectFileDialogExtensionBrowserTest : public ExtensionBrowserTest { |
| 81 public: | 81 public: |
| 82 enum DialogButtonType { | 82 enum DialogButtonType { |
| 83 DIALOG_BTN_OK, | 83 DIALOG_BTN_OK, |
| 84 DIALOG_BTN_CANCEL | 84 DIALOG_BTN_CANCEL |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 virtual void SetUp() OVERRIDE { | 87 virtual void SetUp() override { |
| 88 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); | 88 extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); |
| 89 | 89 |
| 90 // Create the dialog wrapper object, but don't show it yet. | 90 // Create the dialog wrapper object, but don't show it yet. |
| 91 listener_.reset(new MockSelectFileDialogListener()); | 91 listener_.reset(new MockSelectFileDialogListener()); |
| 92 dialog_ = new SelectFileDialogExtension(listener_.get(), NULL); | 92 dialog_ = new SelectFileDialogExtension(listener_.get(), NULL); |
| 93 | 93 |
| 94 // We have to provide at least one mount point. | 94 // We have to provide at least one mount point. |
| 95 // File manager looks for "Downloads" mount point, so use this name. | 95 // File manager looks for "Downloads" mount point, so use this name. |
| 96 base::FilePath tmp_path; | 96 base::FilePath tmp_path; |
| 97 PathService::Get(base::DIR_TEMP, &tmp_path); | 97 PathService::Get(base::DIR_TEMP, &tmp_path); |
| 98 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDirUnderPath(tmp_path)); | 98 ASSERT_TRUE(tmp_dir_.CreateUniqueTempDirUnderPath(tmp_path)); |
| 99 downloads_dir_ = tmp_dir_.path().Append("Downloads"); | 99 downloads_dir_ = tmp_dir_.path().Append("Downloads"); |
| 100 base::CreateDirectory(downloads_dir_); | 100 base::CreateDirectory(downloads_dir_); |
| 101 | 101 |
| 102 // Must run after our setup because it actually runs the test. | 102 // Must run after our setup because it actually runs the test. |
| 103 ExtensionBrowserTest::SetUp(); | 103 ExtensionBrowserTest::SetUp(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 virtual void TearDown() OVERRIDE { | 106 virtual void TearDown() override { |
| 107 ExtensionBrowserTest::TearDown(); | 107 ExtensionBrowserTest::TearDown(); |
| 108 | 108 |
| 109 // Delete the dialog first, as it holds a pointer to the listener. | 109 // Delete the dialog first, as it holds a pointer to the listener. |
| 110 dialog_ = NULL; | 110 dialog_ = NULL; |
| 111 listener_.reset(); | 111 listener_.reset(); |
| 112 | 112 |
| 113 second_dialog_ = NULL; | 113 second_dialog_ = NULL; |
| 114 second_listener_.reset(); | 114 second_listener_.reset(); |
| 115 } | 115 } |
| 116 | 116 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 362 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); |
| 363 | 363 |
| 364 // Click cancel button. | 364 // Click cancel button. |
| 365 CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 365 CloseDialog(DIALOG_BTN_CANCEL, owning_window); |
| 366 | 366 |
| 367 // Listener should have been informed of the cancellation. | 367 // Listener should have been informed of the cancellation. |
| 368 ASSERT_FALSE(listener_->file_selected()); | 368 ASSERT_FALSE(listener_->file_selected()); |
| 369 ASSERT_TRUE(listener_->canceled()); | 369 ASSERT_TRUE(listener_->canceled()); |
| 370 ASSERT_EQ(this, listener_->params()); | 370 ASSERT_EQ(this, listener_->params()); |
| 371 } | 371 } |
| OLD | NEW |