OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_manager_dialog.h" | 5 #include "chrome/browser/ui/views/file_manager_dialog.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/scoped_temp_dir.h" | 11 #include "base/scoped_temp_dir.h" |
12 #include "base/threading/platform_thread.h" | 12 #include "base/threading/platform_thread.h" |
13 #include "base/utf_string_conversions.h" // ASCIIToUTF16 | 13 #include "base/utf_string_conversions.h" // ASCIIToUTF16 |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "chrome/browser/extensions/extension_browsertest.h" | 15 #include "chrome/browser/extensions/extension_browsertest.h" |
16 #include "chrome/browser/extensions/extension_test_message_listener.h" | 16 #include "chrome/browser/extensions/extension_test_message_listener.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_navigator.h" |
19 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
20 #include "chrome/browser/ui/shell_dialogs.h" // SelectFileDialog | 21 #include "chrome/browser/ui/shell_dialogs.h" // SelectFileDialog |
21 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
24 #include "content/common/content_notification_types.h" | 25 #include "content/common/content_notification_types.h" |
25 #include "webkit/fileapi/file_system_context.h" | 26 #include "webkit/fileapi/file_system_context.h" |
26 #include "webkit/fileapi/file_system_mount_point_provider.h" | 27 #include "webkit/fileapi/file_system_mount_point_provider.h" |
27 #include "webkit/fileapi/file_system_path_manager.h" | 28 #include "webkit/fileapi/file_system_path_manager.h" |
28 | 29 |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 290 |
290 // Dialog no longer believes it is running. | 291 // Dialog no longer believes it is running. |
291 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | 292 ASSERT_FALSE(dialog_->IsRunning(owning_window)); |
292 | 293 |
293 // Listener should have been informed that the file was selected. | 294 // Listener should have been informed that the file was selected. |
294 ASSERT_TRUE(listener_->file_selected()); | 295 ASSERT_TRUE(listener_->file_selected()); |
295 ASSERT_FALSE(listener_->canceled()); | 296 ASSERT_FALSE(listener_->canceled()); |
296 ASSERT_EQ(test_file, listener_->path()); | 297 ASSERT_EQ(test_file, listener_->path()); |
297 ASSERT_EQ(this, listener_->params()); | 298 ASSERT_EQ(this, listener_->params()); |
298 } | 299 } |
| 300 |
| 301 IN_PROC_BROWSER_TEST_F(FileManagerDialogTest, OpenSingletonTabAndCancel) { |
| 302 // Add tmp mount point even though this test won't use it directly. |
| 303 // We need this to make sure that at least one top-level directory exists |
| 304 // in the file browser. |
| 305 FilePath tmp_dir("/tmp"); |
| 306 AddMountPoint(tmp_dir); |
| 307 |
| 308 // Spawn a dialog to open a file. The dialog will signal that it is ready |
| 309 // via chrome.test.sendMessage() in the extension JavaScript. |
| 310 ExtensionTestMessageListener init_listener("worker-initialized", |
| 311 false /* will_reply */); |
| 312 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); |
| 313 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, |
| 314 string16() /* title */, |
| 315 FilePath() /* default_path */, |
| 316 NULL /* file_types */, |
| 317 0 /* file_type_index */, |
| 318 FILE_PATH_LITERAL("") /* default_extension */, |
| 319 NULL /* source_contents */, |
| 320 owning_window, |
| 321 this /* params */); |
| 322 LOG(INFO) << "Waiting for JavaScript ready message."; |
| 323 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); |
| 324 |
| 325 // Dialog should be running now. |
| 326 ASSERT_TRUE(dialog_->IsRunning(owning_window)); |
| 327 |
| 328 // Open a singleton tab in background. |
| 329 browser::NavigateParams p(browser(), GURL("www.google.com"), |
| 330 PageTransition::LINK); |
| 331 p.window_action = browser::NavigateParams::SHOW_WINDOW; |
| 332 p.disposition = SINGLETON_TAB; |
| 333 browser::Navigate(&p); |
| 334 |
| 335 // Inject JavaScript to click the cancel button and wait for notification |
| 336 // that the window has closed. |
| 337 ui_test_utils::WindowedNotificationObserver host_destroyed( |
| 338 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 339 NotificationService::AllSources()); |
| 340 RenderViewHost* host = dialog_->GetRenderViewHost(); |
| 341 string16 main_frame; |
| 342 string16 script = ASCIIToUTF16( |
| 343 "console.log(\'Test JavaScript injected.\');" |
| 344 "document.querySelector(\'.cancel\').click();"); |
| 345 // The file selection handler closes the dialog and does not return control |
| 346 // to JavaScript, so do not wait for return values. |
| 347 host->ExecuteJavascriptInWebFrame(main_frame, script); |
| 348 LOG(INFO) << "Waiting for window close notification."; |
| 349 host_destroyed.Wait(); |
| 350 |
| 351 // Dialog no longer believes it is running. |
| 352 ASSERT_FALSE(dialog_->IsRunning(owning_window)); |
| 353 |
| 354 // Listener should have been informed of the cancellation. |
| 355 ASSERT_FALSE(listener_->file_selected()); |
| 356 ASSERT_TRUE(listener_->canceled()); |
| 357 ASSERT_EQ(this, listener_->params()); |
| 358 } |
OLD | NEW |