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_navigator.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/shell_dialogs.h" // SelectFileDialog | 21 #include "chrome/browser/ui/shell_dialogs.h" // SelectFileDialog |
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_types.h" | 26 #include "content/public/browser/notification_types.h" |
26 #include "webkit/fileapi/file_system_context.h" | 27 #include "webkit/fileapi/file_system_context.h" |
27 #include "webkit/fileapi/file_system_mount_point_provider.h" | 28 #include "webkit/fileapi/file_system_mount_point_provider.h" |
28 #include "webkit/fileapi/file_system_path_manager.h" | 29 #include "webkit/fileapi/file_system_path_manager.h" |
29 | 30 |
30 // Mock listener used by test below. | 31 // Mock listener used by test below. |
31 class MockSelectFileDialogListener : public SelectFileDialog::Listener { | 32 class MockSelectFileDialogListener : public SelectFileDialog::Listener { |
32 public: | 33 public: |
33 MockSelectFileDialogListener() | 34 MockSelectFileDialogListener() |
34 : file_selected_(false), | 35 : file_selected_(false), |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 LOG(INFO) << "Waiting for JavaScript ready message."; | 137 LOG(INFO) << "Waiting for JavaScript ready message."; |
137 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); | 138 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); |
138 | 139 |
139 // Dialog should be running now. | 140 // Dialog should be running now. |
140 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | 141 ASSERT_TRUE(dialog_->IsRunning(owning_window)); |
141 | 142 |
142 // Inject JavaScript to click the cancel button and wait for notification | 143 // Inject JavaScript to click the cancel button and wait for notification |
143 // that the window has closed. | 144 // that the window has closed. |
144 ui_test_utils::WindowedNotificationObserver host_destroyed( | 145 ui_test_utils::WindowedNotificationObserver host_destroyed( |
145 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 146 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
146 NotificationService::AllSources()); | 147 content::NotificationService::AllSources()); |
147 RenderViewHost* host = dialog_->GetRenderViewHost(); | 148 RenderViewHost* host = dialog_->GetRenderViewHost(); |
148 string16 main_frame; | 149 string16 main_frame; |
149 string16 script = ASCIIToUTF16( | 150 string16 script = ASCIIToUTF16( |
150 "console.log(\'Test JavaScript injected.\');" | 151 "console.log(\'Test JavaScript injected.\');" |
151 "document.querySelector(\'.cancel\').click();"); | 152 "document.querySelector(\'.cancel\').click();"); |
152 // The file selection handler closes the dialog and does not return control | 153 // The file selection handler closes the dialog and does not return control |
153 // to JavaScript, so do not wait for return values. | 154 // to JavaScript, so do not wait for return values. |
154 host->ExecuteJavascriptInWebFrame(main_frame, script); | 155 host->ExecuteJavascriptInWebFrame(main_frame, script); |
155 LOG(INFO) << "Waiting for window close notification."; | 156 LOG(INFO) << "Waiting for window close notification."; |
156 host_destroyed.Wait(); | 157 host_destroyed.Wait(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 LOG(INFO) << "Waiting for JavaScript selection-change-complete message."; | 207 LOG(INFO) << "Waiting for JavaScript selection-change-complete message."; |
207 ASSERT_TRUE(selection_listener.WaitUntilSatisfied()); | 208 ASSERT_TRUE(selection_listener.WaitUntilSatisfied()); |
208 | 209 |
209 // Dialog should be running now. | 210 // Dialog should be running now. |
210 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | 211 ASSERT_TRUE(dialog_->IsRunning(owning_window)); |
211 | 212 |
212 // Inject JavaScript to click the open button and wait for notification | 213 // Inject JavaScript to click the open button and wait for notification |
213 // that the window has closed. | 214 // that the window has closed. |
214 ui_test_utils::WindowedNotificationObserver host_destroyed( | 215 ui_test_utils::WindowedNotificationObserver host_destroyed( |
215 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 216 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
216 NotificationService::AllSources()); | 217 content::NotificationService::AllSources()); |
217 RenderViewHost* host = dialog_->GetRenderViewHost(); | 218 RenderViewHost* host = dialog_->GetRenderViewHost(); |
218 string16 main_frame; | 219 string16 main_frame; |
219 string16 script = ASCIIToUTF16( | 220 string16 script = ASCIIToUTF16( |
220 "console.log(\'Test JavaScript injected.\');" | 221 "console.log(\'Test JavaScript injected.\');" |
221 "document.querySelector('.ok').click();"); | 222 "document.querySelector('.ok').click();"); |
222 // The file selection handler closes the dialog and does not return control | 223 // The file selection handler closes the dialog and does not return control |
223 // to JavaScript, so do not wait for return values. | 224 // to JavaScript, so do not wait for return values. |
224 host->ExecuteJavascriptInWebFrame(main_frame, script); | 225 host->ExecuteJavascriptInWebFrame(main_frame, script); |
225 LOG(INFO) << "Waiting for window close notification."; | 226 LOG(INFO) << "Waiting for window close notification."; |
226 host_destroyed.Wait(); | 227 host_destroyed.Wait(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 LOG(INFO) << "Waiting for JavaScript directory-change-complete message."; | 273 LOG(INFO) << "Waiting for JavaScript directory-change-complete message."; |
273 ASSERT_TRUE(dir_change_listener.WaitUntilSatisfied()); | 274 ASSERT_TRUE(dir_change_listener.WaitUntilSatisfied()); |
274 | 275 |
275 // Dialog should be running now. | 276 // Dialog should be running now. |
276 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | 277 ASSERT_TRUE(dialog_->IsRunning(owning_window)); |
277 | 278 |
278 // Inject JavaScript to click the save button and wait for notification | 279 // Inject JavaScript to click the save button and wait for notification |
279 // that the window has closed. | 280 // that the window has closed. |
280 ui_test_utils::WindowedNotificationObserver host_destroyed( | 281 ui_test_utils::WindowedNotificationObserver host_destroyed( |
281 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 282 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
282 NotificationService::AllSources()); | 283 content::NotificationService::AllSources()); |
283 RenderViewHost* host = dialog_->GetRenderViewHost(); | 284 RenderViewHost* host = dialog_->GetRenderViewHost(); |
284 string16 main_frame; | 285 string16 main_frame; |
285 string16 script = ASCIIToUTF16( | 286 string16 script = ASCIIToUTF16( |
286 "console.log(\'Test JavaScript injected.\');" | 287 "console.log(\'Test JavaScript injected.\');" |
287 "document.querySelector('.ok').click();"); | 288 "document.querySelector('.ok').click();"); |
288 // The file selection handler closes the dialog and does not return control | 289 // The file selection handler closes the dialog and does not return control |
289 // to JavaScript, so do not wait for return values. | 290 // to JavaScript, so do not wait for return values. |
290 host->ExecuteJavascriptInWebFrame(main_frame, script); | 291 host->ExecuteJavascriptInWebFrame(main_frame, script); |
291 LOG(INFO) << "Waiting for window close notification."; | 292 LOG(INFO) << "Waiting for window close notification."; |
292 host_destroyed.Wait(); | 293 host_destroyed.Wait(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 browser::NavigateParams p(browser(), GURL("www.google.com"), | 334 browser::NavigateParams p(browser(), GURL("www.google.com"), |
334 content::PAGE_TRANSITION_LINK); | 335 content::PAGE_TRANSITION_LINK); |
335 p.window_action = browser::NavigateParams::SHOW_WINDOW; | 336 p.window_action = browser::NavigateParams::SHOW_WINDOW; |
336 p.disposition = SINGLETON_TAB; | 337 p.disposition = SINGLETON_TAB; |
337 browser::Navigate(&p); | 338 browser::Navigate(&p); |
338 | 339 |
339 // Inject JavaScript to click the cancel button and wait for notification | 340 // Inject JavaScript to click the cancel button and wait for notification |
340 // that the window has closed. | 341 // that the window has closed. |
341 ui_test_utils::WindowedNotificationObserver host_destroyed( | 342 ui_test_utils::WindowedNotificationObserver host_destroyed( |
342 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 343 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
343 NotificationService::AllSources()); | 344 content::NotificationService::AllSources()); |
344 RenderViewHost* host = dialog_->GetRenderViewHost(); | 345 RenderViewHost* host = dialog_->GetRenderViewHost(); |
345 string16 main_frame; | 346 string16 main_frame; |
346 string16 script = ASCIIToUTF16( | 347 string16 script = ASCIIToUTF16( |
347 "console.log(\'Test JavaScript injected.\');" | 348 "console.log(\'Test JavaScript injected.\');" |
348 "document.querySelector(\'.cancel\').click();"); | 349 "document.querySelector(\'.cancel\').click();"); |
349 // The file selection handler closes the dialog and does not return control | 350 // The file selection handler closes the dialog and does not return control |
350 // to JavaScript, so do not wait for return values. | 351 // to JavaScript, so do not wait for return values. |
351 host->ExecuteJavascriptInWebFrame(main_frame, script); | 352 host->ExecuteJavascriptInWebFrame(main_frame, script); |
352 LOG(INFO) << "Waiting for window close notification."; | 353 LOG(INFO) << "Waiting for window close notification."; |
353 host_destroyed.Wait(); | 354 host_destroyed.Wait(); |
354 | 355 |
355 // Dialog no longer believes it is running. | 356 // Dialog no longer believes it is running. |
356 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | 357 ASSERT_FALSE(dialog_->IsRunning(owning_window)); |
357 | 358 |
358 // Listener should have been informed of the cancellation. | 359 // Listener should have been informed of the cancellation. |
359 ASSERT_FALSE(listener_->file_selected()); | 360 ASSERT_FALSE(listener_->file_selected()); |
360 ASSERT_TRUE(listener_->canceled()); | 361 ASSERT_TRUE(listener_->canceled()); |
361 ASSERT_EQ(this, listener_->params()); | 362 ASSERT_EQ(this, listener_->params()); |
362 } | 363 } |
OLD | NEW |