| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 ASSERT_TRUE(value->GetAsInteger(&js_error_count)); | 131 ASSERT_TRUE(value->GetAsInteger(&js_error_count)); |
| 132 ASSERT_EQ(0, js_error_count); | 132 ASSERT_EQ(0, js_error_count); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void OpenDialog(ui::SelectFileDialog::Type dialog_type, | 135 void OpenDialog(ui::SelectFileDialog::Type dialog_type, |
| 136 const base::FilePath& file_path, | 136 const base::FilePath& file_path, |
| 137 const gfx::NativeWindow& owning_window, | 137 const gfx::NativeWindow& owning_window, |
| 138 const std::string& additional_message) { | 138 const std::string& additional_message) { |
| 139 // Spawn a dialog to open a file. The dialog will signal that it is ready | 139 // Spawn a dialog to open a file. The dialog will signal that it is ready |
| 140 // via chrome.test.sendMessage() in the extension JavaScript. | 140 // via chrome.test.sendMessage() in the extension JavaScript. |
| 141 ExtensionTestMessageListener init_listener("worker-initialized", | 141 ExtensionTestMessageListener init_listener("ready", false /* will_reply */); |
| 142 false /* will_reply */); | |
| 143 | 142 |
| 144 scoped_ptr<ExtensionTestMessageListener> additional_listener; | 143 scoped_ptr<ExtensionTestMessageListener> additional_listener; |
| 145 if (!additional_message.empty()) { | 144 if (!additional_message.empty()) { |
| 146 additional_listener.reset( | 145 additional_listener.reset( |
| 147 new ExtensionTestMessageListener(additional_message, false)); | 146 new ExtensionTestMessageListener(additional_message, false)); |
| 148 } | 147 } |
| 149 | 148 |
| 150 dialog_->SelectFile(dialog_type, | 149 dialog_->SelectFile(dialog_type, |
| 151 base::string16() /* title */, | 150 base::string16() /* title */, |
| 152 file_path, | 151 file_path, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // Create an empty file to give us something to select. | 270 // Create an empty file to give us something to select. |
| 272 FILE* fp = base::OpenFile(test_file, "w"); | 271 FILE* fp = base::OpenFile(test_file, "w"); |
| 273 ASSERT_TRUE(fp != NULL); | 272 ASSERT_TRUE(fp != NULL); |
| 274 ASSERT_TRUE(base::CloseFile(fp)); | 273 ASSERT_TRUE(base::CloseFile(fp)); |
| 275 | 274 |
| 276 gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow(); | 275 gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow(); |
| 277 | 276 |
| 278 // Spawn a dialog to open a file. Provide the path to the file so the dialog | 277 // Spawn a dialog to open a file. Provide the path to the file so the dialog |
| 279 // will automatically select it. Ensure that the OK button is enabled by | 278 // will automatically select it. Ensure that the OK button is enabled by |
| 280 // waiting for chrome.test.sendMessage('selection-change-complete'). | 279 // waiting for chrome.test.sendMessage('selection-change-complete'). |
| 281 // The extension starts a Web Worker to read file metadata, so it may send | |
| 282 // 'selection-change-complete' before 'worker-initialized'. This is OK. | |
| 283 ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_OPEN_FILE, | 280 ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_OPEN_FILE, |
| 284 test_file, owning_window, | 281 test_file, owning_window, |
| 285 "selection-change-complete")); | 282 "selection-change-complete")); |
| 286 | 283 |
| 287 // Click open button. | 284 // Click open button. |
| 288 CloseDialog(DIALOG_BTN_OK, owning_window); | 285 CloseDialog(DIALOG_BTN_OK, owning_window); |
| 289 | 286 |
| 290 // Listener should have been informed that the file was opened. | 287 // Listener should have been informed that the file was opened. |
| 291 ASSERT_TRUE(listener_->file_selected()); | 288 ASSERT_TRUE(listener_->file_selected()); |
| 292 ASSERT_FALSE(listener_->canceled()); | 289 ASSERT_FALSE(listener_->canceled()); |
| 293 ASSERT_EQ(test_file, listener_->path()); | 290 ASSERT_EQ(test_file, listener_->path()); |
| 294 ASSERT_EQ(this, listener_->params()); | 291 ASSERT_EQ(this, listener_->params()); |
| 295 } | 292 } |
| 296 | 293 |
| 297 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, | 294 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, |
| 298 SelectFileAndSave) { | 295 SelectFileAndSave) { |
| 299 AddMountPoint(downloads_dir_); | 296 AddMountPoint(downloads_dir_); |
| 300 | 297 |
| 301 base::FilePath test_file = | 298 base::FilePath test_file = |
| 302 downloads_dir_.AppendASCII("file_manager_test.html"); | 299 downloads_dir_.AppendASCII("file_manager_test.html"); |
| 303 | 300 |
| 304 gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow(); | 301 gfx::NativeWindow owning_window = browser()->window()->GetNativeWindow(); |
| 305 | 302 |
| 306 // Spawn a dialog to save a file, providing a suggested path. | 303 // Spawn a dialog to save a file, providing a suggested path. |
| 307 // Ensure "Save" button is enabled by waiting for notification from | 304 // Ensure "Save" button is enabled by waiting for notification from |
| 308 // chrome.test.sendMessage(). | 305 // chrome.test.sendMessage(). |
| 309 // The extension starts a Web Worker to read file metadata, so it may send | |
| 310 // 'directory-change-complete' before 'worker-initialized'. This is OK. | |
| 311 ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_SAVEAS_FILE, | 306 ASSERT_NO_FATAL_FAILURE(OpenDialog(ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
| 312 test_file, owning_window, | 307 test_file, owning_window, |
| 313 "directory-change-complete")); | 308 "directory-change-complete")); |
| 314 | 309 |
| 315 // Click save button. | 310 // Click save button. |
| 316 CloseDialog(DIALOG_BTN_OK, owning_window); | 311 CloseDialog(DIALOG_BTN_OK, owning_window); |
| 317 | 312 |
| 318 // Listener should have been informed that the file was selected. | 313 // Listener should have been informed that the file was selected. |
| 319 ASSERT_TRUE(listener_->file_selected()); | 314 ASSERT_TRUE(listener_->file_selected()); |
| 320 ASSERT_FALSE(listener_->canceled()); | 315 ASSERT_FALSE(listener_->canceled()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 357 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); |
| 363 | 358 |
| 364 // Click cancel button. | 359 // Click cancel button. |
| 365 CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 360 CloseDialog(DIALOG_BTN_CANCEL, owning_window); |
| 366 | 361 |
| 367 // Listener should have been informed of the cancellation. | 362 // Listener should have been informed of the cancellation. |
| 368 ASSERT_FALSE(listener_->file_selected()); | 363 ASSERT_FALSE(listener_->file_selected()); |
| 369 ASSERT_TRUE(listener_->canceled()); | 364 ASSERT_TRUE(listener_->canceled()); |
| 370 ASSERT_EQ(this, listener_->params()); | 365 ASSERT_EQ(this, listener_->params()); |
| 371 } | 366 } |
| OLD | NEW |