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 <memory> |
| 8 |
7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/path_service.h" | 13 #include "base/path_service.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/browser/chromeos/file_manager/volume_manager.h" | 17 #include "chrome/browser/chromeos/file_manager/volume_manager.h" |
17 #include "chrome/browser/extensions/component_loader.h" | 18 #include "chrome/browser/extensions/component_loader.h" |
18 #include "chrome/browser/extensions/extension_browsertest.h" | 19 #include "chrome/browser/extensions/extension_browsertest.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_navigator.h" | 22 #include "chrome/browser/ui/browser_navigator.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 void AddMountPoint(const base::FilePath& path) { | 133 void AddMountPoint(const base::FilePath& path) { |
133 EXPECT_TRUE(file_manager::VolumeManager::Get( | 134 EXPECT_TRUE(file_manager::VolumeManager::Get( |
134 browser()->profile())->RegisterDownloadsDirectoryForTesting(path)); | 135 browser()->profile())->RegisterDownloadsDirectoryForTesting(path)); |
135 browser()->profile()->GetPrefs()->SetFilePath( | 136 browser()->profile()->GetPrefs()->SetFilePath( |
136 prefs::kDownloadDefaultDirectory, downloads_dir_); | 137 prefs::kDownloadDefaultDirectory, downloads_dir_); |
137 } | 138 } |
138 | 139 |
139 void CheckJavascriptErrors() { | 140 void CheckJavascriptErrors() { |
140 content::RenderFrameHost* host = | 141 content::RenderFrameHost* host = |
141 dialog_->GetRenderViewHost()->GetMainFrame(); | 142 dialog_->GetRenderViewHost()->GetMainFrame(); |
142 scoped_ptr<base::Value> value = | 143 std::unique_ptr<base::Value> value = |
143 content::ExecuteScriptAndGetValue(host, "window.JSErrorCount"); | 144 content::ExecuteScriptAndGetValue(host, "window.JSErrorCount"); |
144 int js_error_count = 0; | 145 int js_error_count = 0; |
145 ASSERT_TRUE(value->GetAsInteger(&js_error_count)); | 146 ASSERT_TRUE(value->GetAsInteger(&js_error_count)); |
146 ASSERT_EQ(0, js_error_count); | 147 ASSERT_EQ(0, js_error_count); |
147 } | 148 } |
148 | 149 |
149 void OpenDialog(ui::SelectFileDialog::Type dialog_type, | 150 void OpenDialog(ui::SelectFileDialog::Type dialog_type, |
150 const base::FilePath& file_path, | 151 const base::FilePath& file_path, |
151 const gfx::NativeWindow& owning_window, | 152 const gfx::NativeWindow& owning_window, |
152 const std::string& additional_message) { | 153 const std::string& additional_message) { |
153 // Spawn a dialog to open a file. The dialog will signal that it is ready | 154 // Spawn a dialog to open a file. The dialog will signal that it is ready |
154 // via chrome.test.sendMessage() in the extension JavaScript. | 155 // via chrome.test.sendMessage() in the extension JavaScript. |
155 ExtensionTestMessageListener init_listener("ready", false /* will_reply */); | 156 ExtensionTestMessageListener init_listener("ready", false /* will_reply */); |
156 | 157 |
157 scoped_ptr<ExtensionTestMessageListener> additional_listener; | 158 std::unique_ptr<ExtensionTestMessageListener> additional_listener; |
158 if (!additional_message.empty()) { | 159 if (!additional_message.empty()) { |
159 additional_listener.reset( | 160 additional_listener.reset( |
160 new ExtensionTestMessageListener(additional_message, false)); | 161 new ExtensionTestMessageListener(additional_message, false)); |
161 } | 162 } |
162 | 163 |
163 dialog_->SelectFile(dialog_type, | 164 dialog_->SelectFile(dialog_type, |
164 base::string16() /* title */, | 165 base::string16() /* title */, |
165 file_path, | 166 file_path, |
166 NULL /* file_types */, | 167 NULL /* file_types */, |
167 0 /* file_type_index */, | 168 0 /* file_type_index */, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 // The file selection handler closes the dialog and does not return control | 216 // The file selection handler closes the dialog and does not return control |
216 // to JavaScript, so do not wait for return values. | 217 // to JavaScript, so do not wait for return values. |
217 host->GetMainFrame()->ExecuteJavaScriptForTests(script); | 218 host->GetMainFrame()->ExecuteJavaScriptForTests(script); |
218 LOG(INFO) << "Waiting for window close notification."; | 219 LOG(INFO) << "Waiting for window close notification."; |
219 listener_->WaitForCalled(); | 220 listener_->WaitForCalled(); |
220 | 221 |
221 // Dialog no longer believes it is running. | 222 // Dialog no longer believes it is running. |
222 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | 223 ASSERT_FALSE(dialog_->IsRunning(owning_window)); |
223 } | 224 } |
224 | 225 |
225 scoped_ptr<MockSelectFileDialogListener> listener_; | 226 std::unique_ptr<MockSelectFileDialogListener> listener_; |
226 scoped_refptr<SelectFileDialogExtension> dialog_; | 227 scoped_refptr<SelectFileDialogExtension> dialog_; |
227 | 228 |
228 scoped_ptr<MockSelectFileDialogListener> second_listener_; | 229 std::unique_ptr<MockSelectFileDialogListener> second_listener_; |
229 scoped_refptr<SelectFileDialogExtension> second_dialog_; | 230 scoped_refptr<SelectFileDialogExtension> second_dialog_; |
230 | 231 |
231 base::ScopedTempDir tmp_dir_; | 232 base::ScopedTempDir tmp_dir_; |
232 base::FilePath downloads_dir_; | 233 base::FilePath downloads_dir_; |
233 }; | 234 }; |
234 | 235 |
235 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, CreateAndDestroy) { | 236 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, CreateAndDestroy) { |
236 // Browser window must be up for us to test dialog window parent. | 237 // Browser window must be up for us to test dialog window parent. |
237 gfx::NativeWindow native_window = browser()->window()->GetNativeWindow(); | 238 gfx::NativeWindow native_window = browser()->window()->GetNativeWindow(); |
238 ASSERT_TRUE(native_window != NULL); | 239 ASSERT_TRUE(native_window != NULL); |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 399 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); |
399 | 400 |
400 // Click cancel button. | 401 // Click cancel button. |
401 CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 402 CloseDialog(DIALOG_BTN_CANCEL, owning_window); |
402 | 403 |
403 // Listener should have been informed of the cancellation. | 404 // Listener should have been informed of the cancellation. |
404 ASSERT_FALSE(listener_->file_selected()); | 405 ASSERT_FALSE(listener_->file_selected()); |
405 ASSERT_TRUE(listener_->canceled()); | 406 ASSERT_TRUE(listener_->canceled()); |
406 ASSERT_EQ(this, listener_->params()); | 407 ASSERT_EQ(this, listener_->params()); |
407 } | 408 } |
OLD | NEW |