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