| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 85     // Delete the dialog first, as it holds a pointer to the listener. | 84     // Delete the dialog first, as it holds a pointer to the listener. | 
| 86     dialog_ = NULL; | 85     dialog_ = NULL; | 
| 87     listener_.reset(); | 86     listener_.reset(); | 
| 88 | 87 | 
| 89     second_dialog_ = NULL; | 88     second_dialog_ = NULL; | 
| 90     second_listener_.reset(); | 89     second_listener_.reset(); | 
| 91   } | 90   } | 
| 92 | 91 | 
| 93   // Creates a file system mount point for a directory. | 92   // Creates a file system mount point for a directory. | 
| 94   void AddMountPoint(const FilePath& path) { | 93   void AddMountPoint(const FilePath& path) { | 
| 95     fileapi::FileSystemPathManager* path_manager = |  | 
| 96         browser()->profile()->GetFileSystemContext()->path_manager(); |  | 
| 97     fileapi::ExternalFileSystemMountPointProvider* provider = | 94     fileapi::ExternalFileSystemMountPointProvider* provider = | 
| 98         path_manager->external_provider(); | 95         browser()->profile()->GetFileSystemContext()->external_provider(); | 
| 99     provider->AddMountPoint(path); | 96     provider->AddMountPoint(path); | 
| 100   } | 97   } | 
| 101 | 98 | 
| 102   void OpenDialog(SelectFileDialog::Type dialog_type, | 99   void OpenDialog(SelectFileDialog::Type dialog_type, | 
| 103                   const FilePath& file_path, | 100                   const FilePath& file_path, | 
| 104                   const gfx::NativeWindow& owning_window, | 101                   const gfx::NativeWindow& owning_window, | 
| 105                   const std::string& additional_message) { | 102                   const std::string& additional_message) { | 
| 106     // Spawn a dialog to open a file.  The dialog will signal that it is ready | 103     // Spawn a dialog to open a file.  The dialog will signal that it is ready | 
| 107     // via chrome.test.sendMessage() in the extension JavaScript. | 104     // via chrome.test.sendMessage() in the extension JavaScript. | 
| 108     ExtensionTestMessageListener init_listener("worker-initialized", | 105     ExtensionTestMessageListener init_listener("worker-initialized", | 
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 405   ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 402   ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 
| 406 | 403 | 
| 407   // Click cancel button. | 404   // Click cancel button. | 
| 408   CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 405   CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 
| 409 | 406 | 
| 410   // Listener should have been informed of the cancellation. | 407   // Listener should have been informed of the cancellation. | 
| 411   ASSERT_FALSE(listener_->file_selected()); | 408   ASSERT_FALSE(listener_->file_selected()); | 
| 412   ASSERT_TRUE(listener_->canceled()); | 409   ASSERT_TRUE(listener_->canceled()); | 
| 413   ASSERT_EQ(this, listener_->params()); | 410   ASSERT_EQ(this, listener_->params()); | 
| 414 } | 411 } | 
| OLD | NEW | 
|---|