| 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 "chrome/browser/download/download_item_model.h" | 5 #include "chrome/browser/download/download_item_model.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 using ::testing::Mock; | 24 using ::testing::Mock; |
| 25 using ::testing::NiceMock; | 25 using ::testing::NiceMock; |
| 26 using ::testing::Return; | 26 using ::testing::Return; |
| 27 using ::testing::ReturnRefOfCopy; | 27 using ::testing::ReturnRefOfCopy; |
| 28 using ::testing::SetArgPointee; | 28 using ::testing::SetArgPointee; |
| 29 using ::testing::_; | 29 using ::testing::_; |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Create a char array that has as many elements as there are download | 33 // Create a char array that has as many elements as there are download |
| 34 // interrupt reasons. We can then use that in a COMPILE_ASSERT to make sure | 34 // interrupt reasons. We can then use that in a static_assert to make sure |
| 35 // that all the interrupt reason codes are accounted for. The reason codes are | 35 // that all the interrupt reason codes are accounted for. The reason codes are |
| 36 // unfortunately sparse, making this necessary. | 36 // unfortunately sparse, making this necessary. |
| 37 char kInterruptReasonCounter[] = { | 37 char kInterruptReasonCounter[] = { |
| 38 0, // content::DOWNLOAD_INTERRUPT_REASON_NONE | 38 0, // content::DOWNLOAD_INTERRUPT_REASON_NONE |
| 39 #define INTERRUPT_REASON(name,value) 0, | 39 #define INTERRUPT_REASON(name,value) 0, |
| 40 #include "content/public/browser/download_interrupt_reason_values.h" | 40 #include "content/public/browser/download_interrupt_reason_values.h" |
| 41 #undef INTERRUPT_REASON | 41 #undef INTERRUPT_REASON |
| 42 }; | 42 }; |
| 43 const size_t kInterruptReasonCount = arraysize(kInterruptReasonCounter); | 43 const size_t kInterruptReasonCount = arraysize(kInterruptReasonCounter); |
| 44 | 44 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 "Failed - Needs authorization" }, | 163 "Failed - Needs authorization" }, |
| 164 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, | 164 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, |
| 165 "Failed - Bad certificate" }, | 165 "Failed - Bad certificate" }, |
| 166 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, | 166 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, |
| 167 "Cancelled" }, | 167 "Cancelled" }, |
| 168 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, | 168 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, |
| 169 "Failed - Shutdown" }, | 169 "Failed - Shutdown" }, |
| 170 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, | 170 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, |
| 171 "Failed - Crash" }, | 171 "Failed - Crash" }, |
| 172 }; | 172 }; |
| 173 COMPILE_ASSERT(kInterruptReasonCount == arraysize(kTestCases), | 173 static_assert(kInterruptReasonCount == arraysize(kTestCases), |
| 174 interrupt_reason_mismatch); | 174 "interrupt reason mismatch"); |
| 175 | 175 |
| 176 SetupDownloadItemDefaults(); | 176 SetupDownloadItemDefaults(); |
| 177 for (unsigned i = 0; i < arraysize(kTestCases); ++i) { | 177 for (unsigned i = 0; i < arraysize(kTestCases); ++i) { |
| 178 const TestCase& test_case = kTestCases[i]; | 178 const TestCase& test_case = kTestCases[i]; |
| 179 SetupInterruptedDownloadItem(test_case.reason); | 179 SetupInterruptedDownloadItem(test_case.reason); |
| 180 EXPECT_STREQ(test_case.expected_status, | 180 EXPECT_STREQ(test_case.expected_status, |
| 181 base::UTF16ToUTF8(model().GetStatusText()).c_str()); | 181 base::UTF16ToUTF8(model().GetStatusText()).c_str()); |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 "foo.bar\nNeeds authorization" }, | 239 "foo.bar\nNeeds authorization" }, |
| 240 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, | 240 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, |
| 241 "foo.bar\nBad certificate" }, | 241 "foo.bar\nBad certificate" }, |
| 242 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, | 242 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, |
| 243 "foo.bar" }, | 243 "foo.bar" }, |
| 244 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, | 244 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, |
| 245 "foo.bar\nShutdown" }, | 245 "foo.bar\nShutdown" }, |
| 246 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, | 246 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, |
| 247 "foo.bar\nCrash" }, | 247 "foo.bar\nCrash" }, |
| 248 }; | 248 }; |
| 249 COMPILE_ASSERT(kInterruptReasonCount == arraysize(kTestCases), | 249 static_assert(kInterruptReasonCount == arraysize(kTestCases), |
| 250 interrupt_reason_mismatch); | 250 "interrupt reason mismatch"); |
| 251 | 251 |
| 252 // Large tooltip width. Should be large enough to accommodate the entire | 252 // Large tooltip width. Should be large enough to accommodate the entire |
| 253 // tooltip without truncation. | 253 // tooltip without truncation. |
| 254 const int kLargeTooltipWidth = 1000; | 254 const int kLargeTooltipWidth = 1000; |
| 255 | 255 |
| 256 // Small tooltip width. Small enough to require truncation of most | 256 // Small tooltip width. Small enough to require truncation of most |
| 257 // tooltips. Used to test eliding logic. | 257 // tooltips. Used to test eliding logic. |
| 258 const int kSmallTooltipWidth = 40; | 258 const int kSmallTooltipWidth = 40; |
| 259 | 259 |
| 260 const gfx::FontList& font_list = | 260 const gfx::FontList& font_list = |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 EXPECT_CALL(item(), GetAutoOpened()) | 417 EXPECT_CALL(item(), GetAutoOpened()) |
| 418 .WillRepeatedly(Return(test_case.auto_opened)); | 418 .WillRepeatedly(Return(test_case.auto_opened)); |
| 419 | 419 |
| 420 EXPECT_EQ(test_case.expected_result, | 420 EXPECT_EQ(test_case.expected_result, |
| 421 model().ShouldRemoveFromShelfWhenComplete()) | 421 model().ShouldRemoveFromShelfWhenComplete()) |
| 422 << "Test case: " << i; | 422 << "Test case: " << i; |
| 423 Mock::VerifyAndClearExpectations(&item()); | 423 Mock::VerifyAndClearExpectations(&item()); |
| 424 Mock::VerifyAndClearExpectations(&model()); | 424 Mock::VerifyAndClearExpectations(&model()); |
| 425 } | 425 } |
| 426 } | 426 } |
| OLD | NEW |