Chromium Code Reviews| 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" |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 #if !defined(OS_CHROMEOS) | 211 #if !defined(OS_CHROMEOS) |
| 212 #define MAYBE_SelectFileAndCancel DISABLED_SelectFileAndCancel | 212 #define MAYBE_SelectFileAndCancel DISABLED_SelectFileAndCancel |
| 213 #else | 213 #else |
| 214 #define MAYBE_SelectFileAndCancel SelectFileAndCancel | 214 #define MAYBE_SelectFileAndCancel SelectFileAndCancel |
| 215 #endif | 215 #endif |
| 216 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, | 216 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, |
| 217 MAYBE_SelectFileAndCancel) { | 217 MAYBE_SelectFileAndCancel) { |
| 218 // Add tmp mount point even though this test won't use it directly. | 218 // Add tmp mount point even though this test won't use it directly. |
| 219 // We need this to make sure that at least one top-level directory exists | 219 // We need this to make sure that at least one top-level directory exists |
| 220 // in the file browser. | 220 // in the file browser. |
| 221 FilePath tmp_dir("/tmp"); | 221 FilePath tmp_dir; |
| 222 PathService::Get(base::DIR_TEMP, &tmp_dir); | |
| 223 ScopedTempDir downloads_dir; | |
| 224 ASSERT_TRUE(downloads_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | |
| 225 tmp_dir = downloads_dir.path().Append("Downloads"); | |
| 226 ASSERT_TRUE(file_util::CreateDirectory(tmp_dir)); | |
| 222 AddMountPoint(tmp_dir); | 227 AddMountPoint(tmp_dir); |
| 223 | 228 |
| 224 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | 229 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); |
| 225 | 230 |
| 226 // FilePath() for default path. | 231 // FilePath() for default path. |
| 227 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); | 232 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); |
| 228 | 233 |
| 229 // Press cancel button. | 234 // Press cancel button. |
| 230 CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 235 CloseDialog(DIALOG_BTN_CANCEL, owning_window); |
| 231 | 236 |
| 232 // Listener should have been informed of the cancellation. | 237 // Listener should have been informed of the cancellation. |
| 233 ASSERT_FALSE(listener_->file_selected()); | 238 ASSERT_FALSE(listener_->file_selected()); |
| 234 ASSERT_TRUE(listener_->canceled()); | 239 ASSERT_TRUE(listener_->canceled()); |
| 235 ASSERT_EQ(this, listener_->params()); | 240 ASSERT_EQ(this, listener_->params()); |
| 236 } | 241 } |
| 237 | 242 |
| 238 // TODO(jamescook): Make dialog work on non-ChromeOS platforms. crbug.com/97424 | 243 // TODO(jamescook): Make dialog work on non-ChromeOS platforms. crbug.com/97424 |
| 239 #if !defined(OS_CHROMEOS) | 244 #if !defined(OS_CHROMEOS) |
| 240 #define MAYBE_SelectFileAndOpen DISABLED_SelectFileAndOpen | 245 #define MAYBE_SelectFileAndOpen DISABLED_SelectFileAndOpen |
| 241 #else | 246 #else |
| 242 #define MAYBE_SelectFileAndOpen SelectFileAndOpen | 247 #define MAYBE_SelectFileAndOpen SelectFileAndOpen |
| 243 #endif | 248 #endif |
| 244 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, | 249 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, |
| 245 MAYBE_SelectFileAndOpen) { | 250 MAYBE_SelectFileAndOpen) { |
| 246 // Allow the tmp directory to be mounted. We explicitly use /tmp because | 251 // Allow the tmp directory to be mounted. We explicitly use /tmp because |
| 247 // it it whitelisted for file system access on Chrome OS. | 252 // it is whitelisted for file system access on Chrome OS. |
| 248 FilePath tmp_dir("/tmp"); | 253 // File manager looks for Downloads mount point, so use this name. |
| 254 FilePath tmp_dir; | |
|
sky
2011/12/07 16:39:16
How about a little refactoring so this code isn't
zel
2011/12/07 19:37:55
Right, please move this to the test fixture instea
| |
| 255 PathService::Get(base::DIR_TEMP, &tmp_dir); | |
| 256 ScopedTempDir downloads_dir; | |
| 257 ASSERT_TRUE(downloads_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | |
| 258 tmp_dir = downloads_dir.path().Append("Downloads"); | |
| 259 ASSERT_TRUE(file_util::CreateDirectory(tmp_dir)); | |
| 249 AddMountPoint(tmp_dir); | 260 AddMountPoint(tmp_dir); |
| 250 | 261 |
| 251 // Create a directory with a single file in it. ScopedTempDir will delete | 262 // Create a directory with a single file in it. ScopedTempDir will delete |
| 252 // itself and our temp file when it goes out of scope. | 263 // itself and our temp file when it goes out of scope. |
| 253 ScopedTempDir scoped_temp_dir; | 264 ScopedTempDir scoped_temp_dir; |
| 254 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | 265 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); |
| 255 FilePath temp_dir = scoped_temp_dir.path(); | 266 FilePath temp_dir = scoped_temp_dir.path(); |
| 256 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); | 267 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); |
| 257 | 268 |
| 258 // Create an empty file to give us something to select. | 269 // Create an empty file to give us something to select. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 282 | 293 |
| 283 // TODO(jamescook): Make dialog work on non-ChromeOS platforms. crbug.com/97424 | 294 // TODO(jamescook): Make dialog work on non-ChromeOS platforms. crbug.com/97424 |
| 284 #if !defined(OS_CHROMEOS) | 295 #if !defined(OS_CHROMEOS) |
| 285 #define MAYBE_SelectFileAndSave DISABLED_SelectFileAndSave | 296 #define MAYBE_SelectFileAndSave DISABLED_SelectFileAndSave |
| 286 #else | 297 #else |
| 287 #define MAYBE_SelectFileAndSave SelectFileAndSave | 298 #define MAYBE_SelectFileAndSave SelectFileAndSave |
| 288 #endif | 299 #endif |
| 289 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, | 300 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, |
| 290 MAYBE_SelectFileAndSave) { | 301 MAYBE_SelectFileAndSave) { |
| 291 // Allow the tmp directory to be mounted. We explicitly use /tmp because | 302 // Allow the tmp directory to be mounted. We explicitly use /tmp because |
| 292 // it it whitelisted for file system access on Chrome OS. | 303 // it is whitelisted for file system access on Chrome OS. |
| 293 FilePath tmp_dir("/tmp"); | 304 // File manager looks for Downloads mount point, so use this name. |
| 305 FilePath tmp_dir; | |
| 306 PathService::Get(base::DIR_TEMP, &tmp_dir); | |
| 307 ScopedTempDir downloads_dir; | |
| 308 ASSERT_TRUE(downloads_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | |
| 309 tmp_dir = downloads_dir.path().Append("Downloads"); | |
| 310 ASSERT_TRUE(file_util::CreateDirectory(tmp_dir)); | |
| 294 AddMountPoint(tmp_dir); | 311 AddMountPoint(tmp_dir); |
| 295 | 312 |
| 296 // Create a directory with a single file in it. ScopedTempDir will delete | 313 // Create a directory with a single file in it. ScopedTempDir will delete |
| 297 // itself and our temp file when it goes out of scope. | 314 // itself and our temp file when it goes out of scope. |
| 298 ScopedTempDir scoped_temp_dir; | 315 ScopedTempDir scoped_temp_dir; |
| 299 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | 316 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(tmp_dir)); |
| 300 FilePath temp_dir = scoped_temp_dir.path(); | 317 FilePath temp_dir = scoped_temp_dir.path(); |
| 301 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); | 318 FilePath test_file = temp_dir.AppendASCII("file_manager_test.html"); |
| 302 | 319 |
| 303 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | 320 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 324 #if !defined(OS_CHROMEOS) | 341 #if !defined(OS_CHROMEOS) |
| 325 #define MAYBE_OpenSingletonTabAndCancel DISABLED_OpenSingletonTabAndCancel | 342 #define MAYBE_OpenSingletonTabAndCancel DISABLED_OpenSingletonTabAndCancel |
| 326 #else | 343 #else |
| 327 #define MAYBE_OpenSingletonTabAndCancel OpenSingletonTabAndCancel | 344 #define MAYBE_OpenSingletonTabAndCancel OpenSingletonTabAndCancel |
| 328 #endif | 345 #endif |
| 329 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, | 346 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, |
| 330 MAYBE_OpenSingletonTabAndCancel) { | 347 MAYBE_OpenSingletonTabAndCancel) { |
| 331 // Add tmp mount point even though this test won't use it directly. | 348 // Add tmp mount point even though this test won't use it directly. |
| 332 // We need this to make sure that at least one top-level directory exists | 349 // We need this to make sure that at least one top-level directory exists |
| 333 // in the file browser. | 350 // in the file browser. |
| 334 FilePath tmp_dir("/tmp"); | 351 FilePath tmp_dir; |
| 352 PathService::Get(base::DIR_TEMP, &tmp_dir); | |
| 353 ScopedTempDir downloads_dir; | |
| 354 ASSERT_TRUE(downloads_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | |
| 355 tmp_dir = downloads_dir.path().Append("Downloads"); | |
| 356 ASSERT_TRUE(file_util::CreateDirectory(tmp_dir)); | |
| 335 AddMountPoint(tmp_dir); | 357 AddMountPoint(tmp_dir); |
| 336 | 358 |
| 337 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | 359 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); |
| 338 | 360 |
| 339 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); | 361 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); |
| 340 | 362 |
| 341 // Open a singleton tab in background. | 363 // Open a singleton tab in background. |
| 342 browser::NavigateParams p(browser(), GURL("www.google.com"), | 364 browser::NavigateParams p(browser(), GURL("www.google.com"), |
| 343 content::PAGE_TRANSITION_LINK); | 365 content::PAGE_TRANSITION_LINK); |
| 344 p.window_action = browser::NavigateParams::SHOW_WINDOW; | 366 p.window_action = browser::NavigateParams::SHOW_WINDOW; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 358 #if !defined(OS_CHROMEOS) | 380 #if !defined(OS_CHROMEOS) |
| 359 #define MAYBE_OpenTwoDialogs DISABLED_OpenTwoDialogs | 381 #define MAYBE_OpenTwoDialogs DISABLED_OpenTwoDialogs |
| 360 #else | 382 #else |
| 361 #define MAYBE_OpenTwoDialogs OpenTwoDialogs | 383 #define MAYBE_OpenTwoDialogs OpenTwoDialogs |
| 362 #endif | 384 #endif |
| 363 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, | 385 IN_PROC_BROWSER_TEST_F(SelectFileDialogExtensionBrowserTest, |
| 364 MAYBE_OpenTwoDialogs) { | 386 MAYBE_OpenTwoDialogs) { |
| 365 // Add tmp mount point even though this test won't use it directly. | 387 // Add tmp mount point even though this test won't use it directly. |
| 366 // We need this to make sure that at least one top-level directory exists | 388 // We need this to make sure that at least one top-level directory exists |
| 367 // in the file browser. | 389 // in the file browser. |
| 368 FilePath tmp_dir("/tmp"); | 390 FilePath tmp_dir; |
| 391 PathService::Get(base::DIR_TEMP, &tmp_dir); | |
| 392 ScopedTempDir downloads_dir; | |
| 393 ASSERT_TRUE(downloads_dir.CreateUniqueTempDirUnderPath(tmp_dir)); | |
| 394 tmp_dir = downloads_dir.path().Append("Downloads"); | |
| 395 ASSERT_TRUE(file_util::CreateDirectory(tmp_dir)); | |
| 369 AddMountPoint(tmp_dir); | 396 AddMountPoint(tmp_dir); |
| 370 | 397 |
| 371 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); | 398 gfx::NativeWindow owning_window = browser()->window()->GetNativeHandle(); |
| 372 | 399 |
| 373 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); | 400 OpenDialog(SelectFileDialog::SELECT_OPEN_FILE, FilePath(), owning_window, ""); |
| 374 | 401 |
| 375 TryOpeningSecondDialog(owning_window); | 402 TryOpeningSecondDialog(owning_window); |
| 376 | 403 |
| 377 // Second dialog should not be running. | 404 // Second dialog should not be running. |
| 378 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); | 405 ASSERT_FALSE(second_dialog_->IsRunning(owning_window)); |
| 379 | 406 |
| 380 // Click cancel button. | 407 // Click cancel button. |
| 381 CloseDialog(DIALOG_BTN_CANCEL, owning_window); | 408 CloseDialog(DIALOG_BTN_CANCEL, owning_window); |
| 382 | 409 |
| 383 // Listener should have been informed of the cancellation. | 410 // Listener should have been informed of the cancellation. |
| 384 ASSERT_FALSE(listener_->file_selected()); | 411 ASSERT_FALSE(listener_->file_selected()); |
| 385 ASSERT_TRUE(listener_->canceled()); | 412 ASSERT_TRUE(listener_->canceled()); |
| 386 ASSERT_EQ(this, listener_->params()); | 413 ASSERT_EQ(this, listener_->params()); |
| 387 } | 414 } |
| OLD | NEW |