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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 3479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3490 #define INTERRUPT_REASON(name, value) \ | 3490 #define INTERRUPT_REASON(name, value) \ |
3491 EXPECT_EQ(InterruptReasonContentToExtension( \ | 3491 EXPECT_EQ(InterruptReasonContentToExtension( \ |
3492 content::DOWNLOAD_INTERRUPT_REASON_##name), \ | 3492 content::DOWNLOAD_INTERRUPT_REASON_##name), \ |
3493 api::INTERRUPT_REASON_##name); \ | 3493 api::INTERRUPT_REASON_##name); \ |
3494 EXPECT_EQ(InterruptReasonExtensionToContent( \ | 3494 EXPECT_EQ(InterruptReasonExtensionToContent( \ |
3495 api::INTERRUPT_REASON_##name), \ | 3495 api::INTERRUPT_REASON_##name), \ |
3496 content::DOWNLOAD_INTERRUPT_REASON_##name); | 3496 content::DOWNLOAD_INTERRUPT_REASON_##name); |
3497 #include "content/public/browser/download_interrupt_reason_values.h" | 3497 #include "content/public/browser/download_interrupt_reason_values.h" |
3498 #undef INTERRUPT_REASON | 3498 #undef INTERRUPT_REASON |
3499 } | 3499 } |
| 3500 |
| 3501 TEST(ExtensionDetermineDownloadFilenameInternal, |
| 3502 ExtensionDetermineDownloadFilenameInternal) { |
| 3503 |
| 3504 std::string winner_id; |
| 3505 base::FilePath filename; |
| 3506 extensions::api::downloads::FilenameConflictAction conflict_action = |
| 3507 api::FILENAME_CONFLICT_ACTION_UNIQUIFY; |
| 3508 extensions::ExtensionWarningSet warnings; |
| 3509 |
| 3510 // Empty incumbent determiner |
| 3511 warnings.clear(); |
| 3512 ExtensionDownloadsEventRouter::DetermineFilenameInternal( |
| 3513 base::FilePath(FILE_PATH_LITERAL("a")), |
| 3514 api::FILENAME_CONFLICT_ACTION_OVERWRITE, |
| 3515 "suggester", |
| 3516 base::Time::Now(), |
| 3517 "", |
| 3518 base::Time(), |
| 3519 &winner_id, |
| 3520 &filename, |
| 3521 &conflict_action, |
| 3522 &warnings); |
| 3523 EXPECT_EQ("suggester", winner_id); |
| 3524 EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value()); |
| 3525 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action); |
| 3526 EXPECT_TRUE(warnings.empty()); |
| 3527 |
| 3528 // Incumbent wins |
| 3529 warnings.clear(); |
| 3530 ExtensionDownloadsEventRouter::DetermineFilenameInternal( |
| 3531 base::FilePath(FILE_PATH_LITERAL("b")), |
| 3532 api::FILENAME_CONFLICT_ACTION_PROMPT, |
| 3533 "suggester", |
| 3534 base::Time::Now() - base::TimeDelta::FromDays(1), |
| 3535 "incumbent", |
| 3536 base::Time::Now(), |
| 3537 &winner_id, |
| 3538 &filename, |
| 3539 &conflict_action, |
| 3540 &warnings); |
| 3541 EXPECT_EQ("incumbent", winner_id); |
| 3542 EXPECT_EQ(FILE_PATH_LITERAL("a"), filename.value()); |
| 3543 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_OVERWRITE, conflict_action); |
| 3544 EXPECT_FALSE(warnings.empty()); |
| 3545 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict, |
| 3546 warnings.begin()->warning_type()); |
| 3547 EXPECT_EQ("suggester", warnings.begin()->extension_id()); |
| 3548 |
| 3549 // Suggester wins |
| 3550 warnings.clear(); |
| 3551 ExtensionDownloadsEventRouter::DetermineFilenameInternal( |
| 3552 base::FilePath(FILE_PATH_LITERAL("b")), |
| 3553 api::FILENAME_CONFLICT_ACTION_PROMPT, |
| 3554 "suggester", |
| 3555 base::Time::Now(), |
| 3556 "incumbent", |
| 3557 base::Time::Now() - base::TimeDelta::FromDays(1), |
| 3558 &winner_id, |
| 3559 &filename, |
| 3560 &conflict_action, |
| 3561 &warnings); |
| 3562 EXPECT_EQ("suggester", winner_id); |
| 3563 EXPECT_EQ(FILE_PATH_LITERAL("b"), filename.value()); |
| 3564 EXPECT_EQ(api::FILENAME_CONFLICT_ACTION_PROMPT, conflict_action); |
| 3565 EXPECT_FALSE(warnings.empty()); |
| 3566 EXPECT_EQ(extensions::ExtensionWarning::kDownloadFilenameConflict, |
| 3567 warnings.begin()->warning_type()); |
| 3568 EXPECT_EQ("incumbent", warnings.begin()->extension_id()); |
| 3569 } |
OLD | NEW |