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/select_file_dialog_extension.h" | 5 #include "chrome/browser/ui/views/select_file_dialog_extension.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_navigator.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/select_file_dialog.h" | 21 #include "chrome/browser/ui/select_file_dialog.h" |
22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
27 #include "webkit/fileapi/file_system_context.h" | 27 #include "webkit/fileapi/file_system_context.h" |
28 #include "webkit/fileapi/file_system_mount_point_provider.h" | 28 #include "webkit/fileapi/file_system_mount_point_provider.h" |
29 #include "webkit/fileapi/file_system_path_manager.h" | |
30 | 29 |
31 // Mock listener used by test below. | 30 // Mock listener used by test below. |
32 class MockSelectFileDialogListener : public SelectFileDialog::Listener { | 31 class MockSelectFileDialogListener : public SelectFileDialog::Listener { |
33 public: | 32 public: |
34 MockSelectFileDialogListener() | 33 MockSelectFileDialogListener() |
35 : file_selected_(false), | 34 : file_selected_(false), |
36 canceled_(false), | 35 canceled_(false), |
37 params_(NULL) { | 36 params_(NULL) { |
38 } | 37 } |
39 | 38 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // Delete the dialog first, as it holds a pointer to the listener. | 93 // Delete the dialog first, as it holds a pointer to the listener. |
95 dialog_ = NULL; | 94 dialog_ = NULL; |
96 listener_.reset(); | 95 listener_.reset(); |
97 | 96 |
98 second_dialog_ = NULL; | 97 second_dialog_ = NULL; |
99 second_listener_.reset(); | 98 second_listener_.reset(); |
100 } | 99 } |
101 | 100 |
102 // Creates a file system mount point for a directory. | 101 // Creates a file system mount point for a directory. |
103 void AddMountPoint(const FilePath& path) { | 102 void AddMountPoint(const FilePath& path) { |
104 fileapi::FileSystemPathManager* path_manager = | |
105 browser()->profile()->GetFileSystemContext()->path_manager(); | |
106 fileapi::ExternalFileSystemMountPointProvider* provider = | 103 fileapi::ExternalFileSystemMountPointProvider* provider = |
107 path_manager->external_provider(); | 104 browser()->profile()->GetFileSystemContext()->external_provider(); |
108 provider->AddMountPoint(path); | 105 provider->AddMountPoint(path); |
109 } | 106 } |
110 | 107 |
111 void OpenDialog(SelectFileDialog::Type dialog_type, | 108 void OpenDialog(SelectFileDialog::Type dialog_type, |
112 const FilePath& file_path, | 109 const FilePath& file_path, |
113 const gfx::NativeWindow& owning_window, | 110 const gfx::NativeWindow& owning_window, |
114 const std::string& additional_message) { | 111 const std::string& additional_message) { |
115 // Spawn a dialog to open a file. The dialog will signal that it is ready | 112 // Spawn a dialog to open a file. The dialog will signal that it is ready |
116 // via chrome.test.sendMessage() in the extension JavaScript. | 113 // via chrome.test.sendMessage() in the extension JavaScript. |
117 ExtensionTestMessageListener init_listener("worker-initialized", | 114 ExtensionTestMessageListener init_listener("worker-initialized", |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 359 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); |
363 | 360 |
364 // Click cancel button. | 361 // Click cancel button. |
365 CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 362 CloseDialog(DIALOG_BTN_CANCEL, owning_window); |
366 | 363 |
367 // Listener should have been informed of the cancellation. | 364 // Listener should have been informed of the cancellation. |
368 ASSERT_FALSE(listener_->file_selected()); | 365 ASSERT_FALSE(listener_->file_selected()); |
369 ASSERT_TRUE(listener_->canceled()); | 366 ASSERT_TRUE(listener_->canceled()); |
370 ASSERT_EQ(this, listener_->params()); | 367 ASSERT_EQ(this, listener_->params()); |
371 } | 368 } |
OLD | NEW |