| 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/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 | 29 | 
|  | 30 using content::BrowserContext; | 
|  | 31 | 
| 30 // Mock listener used by test below. | 32 // Mock listener used by test below. | 
| 31 class MockSelectFileDialogListener : public SelectFileDialog::Listener { | 33 class MockSelectFileDialogListener : public SelectFileDialog::Listener { | 
| 32  public: | 34  public: | 
| 33   MockSelectFileDialogListener() | 35   MockSelectFileDialogListener() | 
| 34     : file_selected_(false), | 36     : file_selected_(false), | 
| 35       canceled_(false), | 37       canceled_(false), | 
| 36       params_(NULL) { | 38       params_(NULL) { | 
| 37   } | 39   } | 
| 38 | 40 | 
| 39   bool file_selected() const { return file_selected_; } | 41   bool file_selected() const { return file_selected_; } | 
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 94     dialog_ = NULL; | 96     dialog_ = NULL; | 
| 95     listener_.reset(); | 97     listener_.reset(); | 
| 96 | 98 | 
| 97     second_dialog_ = NULL; | 99     second_dialog_ = NULL; | 
| 98     second_listener_.reset(); | 100     second_listener_.reset(); | 
| 99   } | 101   } | 
| 100 | 102 | 
| 101   // Creates a file system mount point for a directory. | 103   // Creates a file system mount point for a directory. | 
| 102   void AddMountPoint(const FilePath& path) { | 104   void AddMountPoint(const FilePath& path) { | 
| 103     fileapi::ExternalFileSystemMountPointProvider* provider = | 105     fileapi::ExternalFileSystemMountPointProvider* provider = | 
| 104         browser()->profile()->GetFileSystemContext()->external_provider(); | 106         BrowserContext::GetFileSystemContext(browser()->profile())-> | 
|  | 107             external_provider(); | 
| 105     provider->AddMountPoint(path); | 108     provider->AddMountPoint(path); | 
| 106   } | 109   } | 
| 107 | 110 | 
| 108   void OpenDialog(SelectFileDialog::Type dialog_type, | 111   void OpenDialog(SelectFileDialog::Type dialog_type, | 
| 109                   const FilePath& file_path, | 112                   const FilePath& file_path, | 
| 110                   const gfx::NativeWindow& owning_window, | 113                   const gfx::NativeWindow& owning_window, | 
| 111                   const std::string& additional_message) { | 114                   const std::string& additional_message) { | 
| 112     // Spawn a dialog to open a file.  The dialog will signal that it is ready | 115     // Spawn a dialog to open a file.  The dialog will signal that it is ready | 
| 113     // via chrome.test.sendMessage() in the extension JavaScript. | 116     // via chrome.test.sendMessage() in the extension JavaScript. | 
| 114     ExtensionTestMessageListener init_listener("worker-initialized", | 117     ExtensionTestMessageListener init_listener("worker-initialized", | 
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 359   ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 362   ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 
| 360 | 363 | 
| 361   // Click cancel button. | 364   // Click cancel button. | 
| 362   CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 365   CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 
| 363 | 366 | 
| 364   // Listener should have been informed of the cancellation. | 367   // Listener should have been informed of the cancellation. | 
| 365   ASSERT_FALSE(listener_->file_selected()); | 368   ASSERT_FALSE(listener_->file_selected()); | 
| 366   ASSERT_TRUE(listener_->canceled()); | 369   ASSERT_TRUE(listener_->canceled()); | 
| 367   ASSERT_EQ(this, listener_->params()); | 370   ASSERT_EQ(this, listener_->params()); | 
| 368 } | 371 } | 
| OLD | NEW | 
|---|