Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/download/download_commands.h" | 5 #include "chrome/browser/download/download_commands.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "content/public/test/mock_download_item.h" | 9 #include "content/public/test/mock_download_item.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using content::DownloadItem; | 13 using content::DownloadItem; |
| 14 using ::testing::Mock; | 14 using ::testing::Mock; |
| 15 using ::testing::NiceMock; | 15 using ::testing::NiceMock; |
| 16 using ::testing::Return; | 16 using ::testing::Return; |
| 17 using ::testing::ReturnRefOfCopy; | 17 using ::testing::ReturnRefOfCopy; |
| 18 using ::testing::_; | 18 using ::testing::_; |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Default target path for a mock download item in DownloadItemModelTest. | 22 // Default target path for a mock download item in DownloadItemModelTest. |
| 23 const base::FilePath::CharType kDefaultTargetFilePath[] = | 23 const base::FilePath::CharType kDefaultTargetFilePath[] = |
| 24 FILE_PATH_LITERAL("/foo/bar/foo.bar"); | 24 FILE_PATH_LITERAL("/foo/bar/foo.bar"); |
| 25 | 25 |
| 26 // Default URL for a mock download item in DownloadCommandsTest. | 26 // Default URL for a mock download item in DownloadCommandsTest. |
| 27 const char kDefaultURL[] = "http://example.com/foo.bar"; | 27 const char kDefaultURL[] = "http://example.com/foo.bar"; |
| 28 | 28 |
| 29 } // namespace | |
| 30 | |
| 29 class DownloadCommandsTest : public testing::Test { | 31 class DownloadCommandsTest : public testing::Test { |
| 30 public: | 32 public: |
| 31 DownloadCommandsTest() : commands_(&item_) {} | 33 DownloadCommandsTest() : commands_(&item_) {} |
| 32 | 34 |
| 33 virtual ~DownloadCommandsTest() { | 35 virtual ~DownloadCommandsTest() { |
| 34 } | 36 } |
| 35 | 37 |
| 36 protected: | 38 protected: |
| 37 // Sets up defaults for the download item. | 39 // Sets up defaults for the download item. |
| 38 void SetUp() override { | 40 void SetUp() override { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 75 |
| 74 DownloadCommands& commands() { | 76 DownloadCommands& commands() { |
| 75 return commands_; | 77 return commands_; |
| 76 } | 78 } |
| 77 | 79 |
| 78 private: | 80 private: |
| 79 NiceMock<content::MockDownloadItem> item_; | 81 NiceMock<content::MockDownloadItem> item_; |
| 80 DownloadCommands commands_; | 82 DownloadCommands commands_; |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 } // namespace | |
| 84 | |
| 85 TEST_F(DownloadCommandsTest, InProgress) { | 85 TEST_F(DownloadCommandsTest, InProgress) { |
| 86 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::SHOW_IN_FOLDER)); | 86 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::SHOW_IN_FOLDER)); |
| 87 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::CANCEL)); | 87 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::CANCEL)); |
| 88 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::PAUSE)); | 88 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::PAUSE)); |
| 89 EXPECT_FALSE(IsCommandEnabled(DownloadCommands::RESUME)); | 89 EXPECT_FALSE(IsCommandEnabled(DownloadCommands::RESUME)); |
| 90 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::ALWAYS_OPEN_TYPE)); | 90 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::ALWAYS_OPEN_TYPE)); |
| 91 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::OPEN_WHEN_COMPLETE)); | 91 EXPECT_TRUE(IsCommandEnabled(DownloadCommands::OPEN_WHEN_COMPLETE)); |
| 92 | 92 |
| 93 EXPECT_FALSE(IsCommandChecked(DownloadCommands::OPEN_WHEN_COMPLETE)); | 93 EXPECT_FALSE(IsCommandChecked(DownloadCommands::OPEN_WHEN_COMPLETE)); |
| 94 EXPECT_FALSE(IsCommandChecked(DownloadCommands::ALWAYS_OPEN_TYPE)); | 94 EXPECT_FALSE(IsCommandChecked(DownloadCommands::ALWAYS_OPEN_TYPE)); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 // Pause. | 147 // Pause. |
| 148 EXPECT_CALL(item(), Pause()).Times(1); | 148 EXPECT_CALL(item(), Pause()).Times(1); |
| 149 commands().ExecuteCommand(DownloadCommands::PAUSE); | 149 commands().ExecuteCommand(DownloadCommands::PAUSE); |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST_F(DownloadCommandsTest, DoResume) { | 152 TEST_F(DownloadCommandsTest, DoResume) { |
| 153 // Resume. | 153 // Resume. |
| 154 EXPECT_CALL(item(), Resume()).Times(1); | 154 EXPECT_CALL(item(), Resume()).Times(1); |
| 155 commands().ExecuteCommand(DownloadCommands::RESUME); | 155 commands().ExecuteCommand(DownloadCommands::RESUME); |
| 156 } | 156 } |
| 157 | |
| 158 TEST_F(DownloadCommandsTest, LearnMoreInterruptedURL) { | |
| 159 EXPECT_CALL(item(), GetLastReason()) | |
| 160 .WillOnce( | |
| 161 Return(content::DOWNLOAD_INTERRUPT_REASON_NETWORK_DISCONNECTED)); | |
| 162 GURL learn_more_url = commands().GetLearnMoreURLForInterruptedDownload(); | |
| 163 EXPECT_EQ("p=ui_download_errors&ctx=22", learn_more_url.query()); | |
|
Randy Smith (Not in Mondays)
2015/04/21 17:28:37
I'd rather compare against the download interrupt
asanka
2015/04/22 16:58:47
Done.
| |
| 164 } | |
| OLD | NEW |