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" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 | 83 |
84 // Creates a file system mount point for a directory. | 84 // Creates a file system mount point for a directory. |
85 void AddMountPoint(const FilePath& path) { | 85 void AddMountPoint(const FilePath& path) { |
86 fileapi::FileSystemPathManager* path_manager = | 86 fileapi::FileSystemPathManager* path_manager = |
87 browser()->profile()->GetFileSystemContext()->path_manager(); | 87 browser()->profile()->GetFileSystemContext()->path_manager(); |
88 fileapi::ExternalFileSystemMountPointProvider* provider = | 88 fileapi::ExternalFileSystemMountPointProvider* provider = |
89 path_manager->external_provider(); | 89 path_manager->external_provider(); |
90 provider->AddMountPoint(path); | 90 provider->AddMountPoint(path); |
91 } | 91 } |
92 | 92 |
93 void OpenDialog(SelectFileDialog::Type dialog_type, | |
James Cook
2011/11/10 21:04:54
Nice that you extracted this shared code!
| |
94 const FilePath& file_path, | |
95 const gfx::NativeWindow& owning_window, | |
96 const std::string& additional_message) { | |
97 // Spawn a dialog to open a file. The dialog will signal that it is ready | |
98 // via chrome.test.sendMessage() in the extension JavaScript. | |
99 ExtensionTestMessageListener init_listener("worker-initialized", | |
100 false /* will_reply */); | |
101 | |
102 scoped_ptr<ExtensionTestMessageListener> additional_listener; | |
103 if (!additional_message.empty()) { | |
104 additional_listener.reset( | |
105 new ExtensionTestMessageListener(additional_message, false)); | |
106 } | |
107 | |
108 dialog_->SelectFile(dialog_type, | |
109 string16() /* title */, | |
110 file_path, | |
111 NULL /* file_types */, | |
112 0 /* file_type_index */, | |
113 FILE_PATH_LITERAL("") /* default_extension */, | |
114 NULL /* source_contents */, | |
115 owning_window, | |
116 this /* params */); | |
117 | |
118 LOG(INFO) << "Waiting for JavaScript ready message."; | |
119 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); | |
120 | |
121 if (additional_listener.get()) { | |
122 LOG(INFO) << "Waiting for JavaScript " << additional_message | |
123 << " message."; | |
124 ASSERT_TRUE(additional_listener->WaitUntilSatisfied()); | |
125 } | |
126 | |
127 // Dialog should be running now. | |
128 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | |
129 } | |
130 | |
131 void CloseDialog(bool press_ok, const gfx::NativeWindow& owning_window) { | |
James Cook
2011/11/10 21:04:54
Maybe use an enum or a string for the button to pr
tbarzic
2011/11/10 22:00:48
Done.
| |
132 // Inject JavaScript to click the cancel button and wait for notification | |
133 // that the window has closed. | |
134 ui_test_utils::WindowedNotificationObserver host_destroyed( | |
135 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | |
136 content::NotificationService::AllSources()); | |
137 RenderViewHost* host = dialog_->GetRenderViewHost(); | |
138 string16 main_frame; | |
139 std::string button_class = press_ok ? ".ok" : ".cancel"; | |
140 string16 script = ASCIIToUTF16( | |
141 "console.log(\'Test JavaScript injected.\');" | |
142 "document.querySelector(\'" + button_class + "\').click();"); | |
143 // The file selection handler closes the dialog and does not return control | |
144 // to JavaScript, so do not wait for return values. | |
145 host->ExecuteJavascriptInWebFrame(main_frame, script); | |
146 LOG(INFO) << "Waiting for window close notification."; | |
147 host_destroyed.Wait(); | |
148 | |
149 // Dialog no longer believes it is running. | |
150 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | |
151 } | |
152 | |
93 scoped_ptr<MockSelectFileDialogListener> listener_; | 153 scoped_ptr<MockSelectFileDialogListener> listener_; |
94 scoped_refptr<FileManagerDialog> dialog_; | 154 scoped_refptr<FileManagerDialog> dialog_; |
95 }; | 155 }; |
96 | 156 |
97 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, CreateAndDestroy) { | 157 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, CreateAndDestroy) { |
98 // Browser window must be up for us to test dialog window parent. | 158 // Browser window must be up for us to test dialog window parent. |
99 gfx::NativeWindow native_window = browser()->window()->GetNativeHandle(); | 159 gfx::NativeWindow native_window = browser()->window()->GetNativeHandle(); |
100 ASSERT_TRUE(native_window != NULL); | 160 ASSERT_TRUE(native_window != NULL); |
101 | 161 |
102 // Before we call SelectFile, dialog is not running/visible. | 162 // Before we call SelectFile, dialog is not running/visible. |
(...skipping 10 matching lines...) Expand all Loading... | |
113 // TODO(jamescook): Add a test for selecting a file for an <input type='file'/> | 173 // TODO(jamescook): Add a test for selecting a file for an <input type='file'/> |
114 // page element, as that uses different memory management pathways. | 174 // page element, as that uses different memory management pathways. |
115 // crbug.com/98791 | 175 // crbug.com/98791 |
116 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, SelectFileAndCancel) { | 176 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, SelectFileAndCancel) { |
117 // Add tmp mount point even though this test won't use it directly. | 177 // Add tmp mount point even though this test won't use it directly. |
118 // We need this to make sure that at least one top-level directory exists | 178 // We need this to make sure that at least one top-level directory exists |
119 // in the file browser. | 179 // in the file browser. |
120 FilePath tmp_dir("/tmp"); | 180 FilePath tmp_dir("/tmp"); |
121 AddMountPoint(tmp_dir); | 181 AddMountPoint(tmp_dir); |
122 | 182 |
123 // Spawn a dialog to open a file. The dialog will signal that it is ready | |
124 // via chrome.test.sendMessage() in the extension JavaScript. | |
125 ExtensionTestMessageListener init_listener("worker-initialized", | |
126 false /* will_reply */); | |
127 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | 183 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); |
128 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, | |
129 string16() /* title */, | |
130 FilePath() /* default_path */, | |
131 NULL /* file_types */, | |
132 0 /* file_type_index */, | |
133 FILE_PATH_LITERAL("") /* default_extension */, | |
134 NULL /* source_contents */, | |
135 owning_window, | |
136 this /* params */); | |
137 LOG(INFO) << "Waiting for JavaScript ready message."; | |
138 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); | |
139 | 184 |
140 // Dialog should be running now. | 185 // FilePath() for default path. |
141 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | 186 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); |
142 | 187 |
143 // Inject JavaScript to click the cancel button and wait for notification | 188 // Press cancel button. |
144 // that the window has closed. | 189 CloseDialog(false, owning_window); |
145 ui_test_utils::WindowedNotificationObserver host_destroyed( | |
146 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | |
147 content::NotificationService::AllSources()); | |
148 RenderViewHost* host = dialog_->GetRenderViewHost(); | |
149 string16 main_frame; | |
150 string16 script = ASCIIToUTF16( | |
151 "console.log(\'Test JavaScript injected.\');" | |
152 "document.querySelector(\'.cancel\').click();"); | |
153 // The file selection handler closes the dialog and does not return control | |
154 // to JavaScript, so do not wait for return values. | |
155 host->ExecuteJavascriptInWebFrame(main_frame, script); | |
156 LOG(INFO) << "Waiting for window close notification."; | |
157 host_destroyed.Wait(); | |
158 | |
159 // Dialog no longer believes it is running. | |
160 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | |
161 | 190 |
162 // Listener should have been informed of the cancellation. | 191 // Listener should have been informed of the cancellation. |
163 ASSERT_FALSE(listener_->file_selected()); | 192 ASSERT_FALSE(listener_->file_selected()); |
164 ASSERT_TRUE(listener_->canceled()); | 193 ASSERT_TRUE(listener_->canceled()); |
165 ASSERT_EQ(this, listener_->params()); | 194 ASSERT_EQ(this, listener_->params()); |
166 } | 195 } |
167 | 196 |
168 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, SelectFileAndOpen) { | 197 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, SelectFileAndOpen) { |
169 // Allow the tmp directory to be mounted. We explicitly use /tmp because | 198 // Allow the tmp directory to be mounted. We explicitly use /tmp because |
170 // it it whitelisted for file system access on Chrome OS. | 199 // it it whitelisted for file system access on Chrome OS. |
171 FilePath tmp_dir("/tmp"); | 200 FilePath tmp_dir("/tmp"); |
172 AddMountPoint(tmp_dir); | 201 AddMountPoint(tmp_dir); |
173 | 202 |
174 // Create a directory with a single file in it. ScopedTempDir will delete | 203 // Create a directory with a single file in it. ScopedTempDir will delete |
175 // itself and our temp file when it goes out of scope. | 204 // itself and our temp file when it goes out of scope. |
176 ScopedTempDir scoped_temp_dir; | 205 ScopedTempDir scoped_temp_dir; |
177 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | 206 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); |
178 FilePath temp_dir = scoped_temp_dir.path(); | 207 FilePath temp_dir = scoped_temp_dir.path(); |
179 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); | 208 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); |
180 | 209 |
181 // Create an empty file to give us something to select. | 210 // Create an empty file to give us something to select. |
182 FILE* fp = file_util::OpenFile(test_file, "w"); | 211 FILE* fp = file_util::OpenFile(test_file, "w"); |
183 ASSERT_TRUE(fp != NULL); | 212 ASSERT_TRUE(fp != NULL); |
184 ASSERT_TRUE(file_util::CloseFile(fp)); | 213 ASSERT_TRUE(file_util::CloseFile(fp)); |
185 | 214 |
215 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | |
216 | |
186 // Spawn a dialog to open a file. Provide the path to the file so the dialog | 217 // Spawn a dialog to open a file. Provide the path to the file so the dialog |
187 // will automatically select it. Ensure that the OK button is enabled by | 218 // will automatically select it. Ensure that the OK button is enabled by |
188 // waiting for chrome.test.sendMessage('selection-change-complete'). | 219 // waiting for chrome.test.sendMessage('selection-change-complete'). |
189 // The extension starts a Web Worker to read file metadata, so it may send | 220 // The extension starts a Web Worker to read file metadata, so it may send |
190 // 'selection-change-complete' before 'worker-initialized'. This is OK. | 221 // 'selection-change-complete' before 'worker-initialized'. This is OK. |
191 ExtensionTestMessageListener init_listener("worker-initialized", | 222 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, test_file, owning_window, |
192 false /* will_reply */); | 223 "selection-change-complete"); |
193 ExtensionTestMessageListener selection_listener("selection-change-complete", | |
194 false /* will_reply */); | |
195 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | |
196 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, | |
197 string16() /* title */, | |
198 test_file, | |
199 NULL /* file_types */, | |
200 0 /* file_type_index */, | |
201 FILE_PATH_LITERAL("") /* default_extension */, | |
202 NULL /* source_contents */, | |
203 owning_window, | |
204 this /* params */); | |
205 LOG(INFO) << "Waiting for JavaScript initialized message."; | |
206 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); | |
207 LOG(INFO) << "Waiting for JavaScript selection-change-complete message."; | |
208 ASSERT_TRUE(selection_listener.WaitUntilSatisfied()); | |
209 | 224 |
210 // Dialog should be running now. | 225 // Click open button. |
211 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | 226 CloseDialog(true, owning_window); |
212 | |
213 // Inject JavaScript to click the open button and wait for notification | |
214 // that the window has closed. | |
215 ui_test_utils::WindowedNotificationObserver host_destroyed( | |
216 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | |
217 content::NotificationService::AllSources()); | |
218 RenderViewHost* host = dialog_->GetRenderViewHost(); | |
219 string16 main_frame; | |
220 string16 script = ASCIIToUTF16( | |
221 "console.log(\'Test JavaScript injected.\');" | |
222 "document.querySelector('.ok').click();"); | |
223 // The file selection handler closes the dialog and does not return control | |
224 // to JavaScript, so do not wait for return values. | |
225 host->ExecuteJavascriptInWebFrame(main_frame, script); | |
226 LOG(INFO) << "Waiting for window close notification."; | |
227 host_destroyed.Wait(); | |
228 | |
229 // Dialog no longer believes it is running. | |
230 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | |
231 | 227 |
232 // Listener should have been informed that the file was opened. | 228 // Listener should have been informed that the file was opened. |
233 ASSERT_TRUE(listener_->file_selected()); | 229 ASSERT_TRUE(listener_->file_selected()); |
234 ASSERT_FALSE(listener_->canceled()); | 230 ASSERT_FALSE(listener_->canceled()); |
235 ASSERT_EQ(test_file, listener_->path()); | 231 ASSERT_EQ(test_file, listener_->path()); |
236 ASSERT_EQ(this, listener_->params()); | 232 ASSERT_EQ(this, listener_->params()); |
237 } | 233 } |
238 | 234 |
239 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, SelectFileAndSave) { | 235 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, SelectFileAndSave) { |
240 // Allow the tmp directory to be mounted. We explicitly use /tmp because | 236 // Allow the tmp directory to be mounted. We explicitly use /tmp because |
241 // it it whitelisted for file system access on Chrome OS. | 237 // it it whitelisted for file system access on Chrome OS. |
242 FilePath tmp_dir("/tmp"); | 238 FilePath tmp_dir("/tmp"); |
243 AddMountPoint(tmp_dir); | 239 AddMountPoint(tmp_dir); |
244 | 240 |
245 // Create a directory with a single file in it. ScopedTempDir will delete | 241 // Create a directory with a single file in it. ScopedTempDir will delete |
246 // itself and our temp file when it goes out of scope. | 242 // itself and our temp file when it goes out of scope. |
247 ScopedTempDir scoped_temp_dir; | 243 ScopedTempDir scoped_temp_dir; |
248 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | 244 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); |
249 FilePath temp_dir = scoped_temp_dir.path(); | 245 FilePath temp_dir = scoped_temp_dir.path(); |
250 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); | 246 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); |
251 | 247 |
248 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | |
249 | |
252 // Spawn a dialog to save a file, providing a suggested path. | 250 // Spawn a dialog to save a file, providing a suggested path. |
253 // Ensure "Save" button is enabled by waiting for notification from | 251 // Ensure "Save" button is enabled by waiting for notification from |
254 // chrome.test.sendMessage(). | 252 // chrome.test.sendMessage(). |
255 // The extension starts a Web Worker to read file metadata, so it may send | 253 // The extension starts a Web Worker to read file metadata, so it may send |
256 // 'directory-change-complete' before 'worker-initialized'. This is OK. | 254 // 'directory-change-complete' before 'worker-initialized'. This is OK. |
257 ExtensionTestMessageListener init_listener("worker-initialized", | 255 OpenDialog(SelectFileDialog::SELECT_SAVEAS_FILE, test_file, owning_window, |
258 false /* will_reply */); | 256 "directory-change-complete"); |
259 ExtensionTestMessageListener dir_change_listener("directory-change-complete", | |
260 false /* will_reply */); | |
261 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | |
262 dialog_->SelectFile(SelectFileDialog::SELECT_SAVEAS_FILE, | |
263 string16() /* title */, | |
264 test_file, | |
265 NULL /* file_types */, | |
266 0 /* file_type_index */, | |
267 FILE_PATH_LITERAL("") /* default_extension */, | |
268 NULL /* source_contents */, | |
269 owning_window, | |
270 this /* params */); | |
271 LOG(INFO) << "Waiting for JavaScript initialized message."; | |
272 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); | |
273 LOG(INFO) << "Waiting for JavaScript directory-change-complete message."; | |
274 ASSERT_TRUE(dir_change_listener.WaitUntilSatisfied()); | |
275 | 257 |
276 // Dialog should be running now. | 258 // Click save button. |
277 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | 259 CloseDialog(true, owning_window); |
278 | |
279 // Inject JavaScript to click the save button and wait for notification | |
280 // that the window has closed. | |
281 ui_test_utils::WindowedNotificationObserver host_destroyed( | |
282 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | |
283 content::NotificationService::AllSources()); | |
284 RenderViewHost* host = dialog_->GetRenderViewHost(); | |
285 string16 main_frame; | |
286 string16 script = ASCIIToUTF16( | |
287 "console.log(\'Test JavaScript injected.\');" | |
288 "document.querySelector('.ok').click();"); | |
289 // The file selection handler closes the dialog and does not return control | |
290 // to JavaScript, so do not wait for return values. | |
291 host->ExecuteJavascriptInWebFrame(main_frame, script); | |
292 LOG(INFO) << "Waiting for window close notification."; | |
293 host_destroyed.Wait(); | |
294 | |
295 // Dialog no longer believes it is running. | |
296 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | |
297 | 260 |
298 // Listener should have been informed that the file was selected. | 261 // Listener should have been informed that the file was selected. |
299 ASSERT_TRUE(listener_->file_selected()); | 262 ASSERT_TRUE(listener_->file_selected()); |
300 ASSERT_FALSE(listener_->canceled()); | 263 ASSERT_FALSE(listener_->canceled()); |
301 ASSERT_EQ(test_file, listener_->path()); | 264 ASSERT_EQ(test_file, listener_->path()); |
302 ASSERT_EQ(this, listener_->params()); | 265 ASSERT_EQ(this, listener_->params()); |
303 } | 266 } |
304 | 267 |
305 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, | 268 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, |
306 OpenSingletonTabAndCancel) { | 269 OpenSingletonTabAndCancel) { |
307 // Add tmp mount point even though this test won't use it directly. | 270 // Add tmp mount point even though this test won't use it directly. |
308 // We need this to make sure that at least one top-level directory exists | 271 // We need this to make sure that at least one top-level directory exists |
309 // in the file browser. | 272 // in the file browser. |
310 FilePath tmp_dir("/tmp"); | 273 FilePath tmp_dir("/tmp"); |
311 AddMountPoint(tmp_dir); | 274 AddMountPoint(tmp_dir); |
312 | 275 |
313 // Spawn a dialog to open a file. The dialog will signal that it is ready | |
314 // via chrome.test.sendMessage() in the extension JavaScript. | |
315 ExtensionTestMessageListener init_listener("worker-initialized", | |
316 false /* will_reply */); | |
317 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | 276 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); |
318 dialog_->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, | |
319 string16() /* title */, | |
320 FilePath() /* default_path */, | |
321 NULL /* file_types */, | |
322 0 /* file_type_index */, | |
323 FILE_PATH_LITERAL("") /* default_extension */, | |
324 NULL /* source_contents */, | |
325 owning_window, | |
326 this /* params */); | |
327 LOG(INFO) << "Waiting for JavaScript ready message."; | |
328 ASSERT_TRUE(init_listener.WaitUntilSatisfied()); | |
329 | 277 |
330 // Dialog should be running now. | 278 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); |
James Cook
2011/11/10 21:04:54
Yeah, these are much easier to read with the commo
tbarzic
2011/11/10 22:00:48
:)
| |
331 ASSERT_TRUE(dialog_->IsRunning(owning_window)); | |
332 | 279 |
333 // Open a singleton tab in background. | 280 // Open a singleton tab in background. |
334 browser::NavigateParams p(browser(), GURL("www.google.com"), | 281 browser::NavigateParams p(browser(), GURL("www.google.com"), |
335 content::PAGE_TRANSITION_LINK); | 282 content::PAGE_TRANSITION_LINK); |
336 p.window_action = browser::NavigateParams::SHOW_WINDOW; | 283 p.window_action = browser::NavigateParams::SHOW_WINDOW; |
337 p.disposition = SINGLETON_TAB; | 284 p.disposition = SINGLETON_TAB; |
338 browser::Navigate(&p); | 285 browser::Navigate(&p); |
339 | 286 |
340 // Inject JavaScript to click the cancel button and wait for notification | 287 // Press cancel button. |
341 // that the window has closed. | 288 CloseDialog(false, owning_window); |
342 ui_test_utils::WindowedNotificationObserver host_destroyed( | |
343 content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | |
344 content::NotificationService::AllSources()); | |
345 RenderViewHost* host = dialog_->GetRenderViewHost(); | |
346 string16 main_frame; | |
347 string16 script = ASCIIToUTF16( | |
348 "console.log(\'Test JavaScript injected.\');" | |
349 "document.querySelector(\'.cancel\').click();"); | |
350 // The file selection handler closes the dialog and does not return control | |
351 // to JavaScript, so do not wait for return values. | |
352 host->ExecuteJavascriptInWebFrame(main_frame, script); | |
353 LOG(INFO) << "Waiting for window close notification."; | |
354 host_destroyed.Wait(); | |
355 | |
356 // Dialog no longer believes it is running. | |
357 ASSERT_FALSE(dialog_->IsRunning(owning_window)); | |
358 | 289 |
359 // Listener should have been informed of the cancellation. | 290 // Listener should have been informed of the cancellation. |
360 ASSERT_FALSE(listener_->file_selected()); | 291 ASSERT_FALSE(listener_->file_selected()); |
361 ASSERT_TRUE(listener_->canceled()); | 292 ASSERT_TRUE(listener_->canceled()); |
362 ASSERT_EQ(this, listener_->params()); | 293 ASSERT_EQ(this, listener_->params()); |
363 } | 294 } |
295 | |
296 IN_PROC_BROWSER_TEST_F(FileManagerDialogBrowserTest, OpenTwoDialogs) { | |
297 // Add tmp mount point even though this test won't use it directly. | |
298 // We need this to make sure that at least one top-level directory exists | |
299 // in the file browser. | |
300 FilePath tmp_dir("/tmp"); | |
301 AddMountPoint(tmp_dir); | |
302 | |
303 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | |
304 | |
305 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); | |
306 | |
307 scoped_ptr<MockSelectFileDialogListener> | |
308 listener2(new MockSelectFileDialogListener()); | |
309 scoped_refptr<FileManagerDialog> dialog2 = | |
James Cook
2011/11/10 21:04:54
Optional: dialog2 could become a member variable o
tbarzic
2011/11/10 22:00:48
Done.
| |
310 new FileManagerDialog(listener2.get()); | |
311 dialog2->SelectFile(SelectFileDialog::SELECT_OPEN_FILE, | |
312 string16() /* title */, | |
313 FilePath() /* default_path */, | |
314 NULL /* file_types */, | |
315 0 /* file_type_index */, | |
316 FILE_PATH_LITERAL("") /* default_extension */, | |
317 NULL /* source_contents */, | |
318 owning_window, | |
319 this /* params */); | |
320 | |
321 // Dialog should not be running now. | |
322 ASSERT_FALSE(dialog2->IsRunning(owning_window)); | |
323 | |
324 // Click cancel button. | |
325 CloseDialog(false, owning_window); | |
326 | |
327 // Listener should have been informed of the cancellation. | |
328 ASSERT_FALSE(listener_->file_selected()); | |
329 ASSERT_TRUE(listener_->canceled()); | |
330 ASSERT_EQ(this, listener_->params()); | |
331 | |
332 dialog2 = NULL; | |
333 listener2.reset(); | |
334 } | |
OLD | NEW |