Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: chrome/browser/download/download_item_model_unittest.cc

Issue 655413002: Convert ARRAYSIZE_UNSAFE -> arraysize in chrome/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 23 matching lines...) Expand all
34 // Create a char array that has as many elements as there are download 34 // Create a char array that has as many elements as there are download
35 // interrupt reasons. We can then use that in a COMPILE_ASSERT to make sure 35 // interrupt reasons. We can then use that in a COMPILE_ASSERT to make sure
36 // that all the interrupt reason codes are accounted for. The reason codes are 36 // that all the interrupt reason codes are accounted for. The reason codes are
37 // unfortunately sparse, making this necessary. 37 // unfortunately sparse, making this necessary.
38 char kInterruptReasonCounter[] = { 38 char kInterruptReasonCounter[] = {
39 0, // content::DOWNLOAD_INTERRUPT_REASON_NONE 39 0, // content::DOWNLOAD_INTERRUPT_REASON_NONE
40 #define INTERRUPT_REASON(name,value) 0, 40 #define INTERRUPT_REASON(name,value) 0,
41 #include "content/public/browser/download_interrupt_reason_values.h" 41 #include "content/public/browser/download_interrupt_reason_values.h"
42 #undef INTERRUPT_REASON 42 #undef INTERRUPT_REASON
43 }; 43 };
44 const size_t kInterruptReasonCount = ARRAYSIZE_UNSAFE(kInterruptReasonCounter); 44 const size_t kInterruptReasonCount = arraysize(kInterruptReasonCounter);
45 45
46 // Default target path for a mock download item in DownloadItemModelTest. 46 // Default target path for a mock download item in DownloadItemModelTest.
47 const base::FilePath::CharType kDefaultTargetFilePath[] = 47 const base::FilePath::CharType kDefaultTargetFilePath[] =
48 FILE_PATH_LITERAL("/foo/bar/foo.bar"); 48 FILE_PATH_LITERAL("/foo/bar/foo.bar");
49 49
50 const base::FilePath::CharType kDefaultDisplayFileName[] = 50 const base::FilePath::CharType kDefaultDisplayFileName[] =
51 FILE_PATH_LITERAL("foo.bar"); 51 FILE_PATH_LITERAL("foo.bar");
52 52
53 // Default URL for a mock download item in DownloadItemModelTest. 53 // Default URL for a mock download item in DownloadItemModelTest.
54 const char kDefaultURL[] = "http://example.com/foo.bar"; 54 const char kDefaultURL[] = "http://example.com/foo.bar";
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 "Failed - Needs authorization" }, 164 "Failed - Needs authorization" },
165 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, 165 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM,
166 "Failed - Bad certificate" }, 166 "Failed - Bad certificate" },
167 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, 167 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED,
168 "Cancelled" }, 168 "Cancelled" },
169 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, 169 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN,
170 "Failed - Shutdown" }, 170 "Failed - Shutdown" },
171 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, 171 { content::DOWNLOAD_INTERRUPT_REASON_CRASH,
172 "Failed - Crash" }, 172 "Failed - Crash" },
173 }; 173 };
174 COMPILE_ASSERT(kInterruptReasonCount == ARRAYSIZE_UNSAFE(kTestCases), 174 COMPILE_ASSERT(kInterruptReasonCount == arraysize(kTestCases),
175 interrupt_reason_mismatch); 175 interrupt_reason_mismatch);
176 176
177 SetupDownloadItemDefaults(); 177 SetupDownloadItemDefaults();
178 for (unsigned i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 178 for (unsigned i = 0; i < arraysize(kTestCases); ++i) {
179 const TestCase& test_case = kTestCases[i]; 179 const TestCase& test_case = kTestCases[i];
180 SetupInterruptedDownloadItem(test_case.reason); 180 SetupInterruptedDownloadItem(test_case.reason);
181 EXPECT_STREQ(test_case.expected_status, 181 EXPECT_STREQ(test_case.expected_status,
182 base::UTF16ToUTF8(model().GetStatusText()).c_str()); 182 base::UTF16ToUTF8(model().GetStatusText()).c_str());
183 } 183 }
184 } 184 }
185 185
186 // Note: This test is currently skipped on Android. See http://crbug.com/139398 186 // Note: This test is currently skipped on Android. See http://crbug.com/139398
187 TEST_F(DownloadItemModelTest, InterruptTooltip) { 187 TEST_F(DownloadItemModelTest, InterruptTooltip) {
188 // Test that we have the correct interrupt tooltip for downloads that are in 188 // Test that we have the correct interrupt tooltip for downloads that are in
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 "foo.bar\nNeeds authorization" }, 240 "foo.bar\nNeeds authorization" },
241 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM, 241 { content::DOWNLOAD_INTERRUPT_REASON_SERVER_CERT_PROBLEM,
242 "foo.bar\nBad certificate" }, 242 "foo.bar\nBad certificate" },
243 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED, 243 { content::DOWNLOAD_INTERRUPT_REASON_USER_CANCELED,
244 "foo.bar" }, 244 "foo.bar" },
245 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN, 245 { content::DOWNLOAD_INTERRUPT_REASON_USER_SHUTDOWN,
246 "foo.bar\nShutdown" }, 246 "foo.bar\nShutdown" },
247 { content::DOWNLOAD_INTERRUPT_REASON_CRASH, 247 { content::DOWNLOAD_INTERRUPT_REASON_CRASH,
248 "foo.bar\nCrash" }, 248 "foo.bar\nCrash" },
249 }; 249 };
250 COMPILE_ASSERT(kInterruptReasonCount == ARRAYSIZE_UNSAFE(kTestCases), 250 COMPILE_ASSERT(kInterruptReasonCount == arraysize(kTestCases),
251 interrupt_reason_mismatch); 251 interrupt_reason_mismatch);
252 252
253 // Large tooltip width. Should be large enough to accommodate the entire 253 // Large tooltip width. Should be large enough to accommodate the entire
254 // tooltip without truncation. 254 // tooltip without truncation.
255 const int kLargeTooltipWidth = 1000; 255 const int kLargeTooltipWidth = 1000;
256 256
257 // Small tooltip width. Small enough to require truncation of most 257 // Small tooltip width. Small enough to require truncation of most
258 // tooltips. Used to test eliding logic. 258 // tooltips. Used to test eliding logic.
259 const int kSmallTooltipWidth = 40; 259 const int kSmallTooltipWidth = 40;
260 260
261 const gfx::FontList& font_list = 261 const gfx::FontList& font_list =
262 ui::ResourceBundle::GetSharedInstance().GetFontList( 262 ui::ResourceBundle::GetSharedInstance().GetFontList(
263 ui::ResourceBundle::BaseFont); 263 ui::ResourceBundle::BaseFont);
264 SetupDownloadItemDefaults(); 264 SetupDownloadItemDefaults();
265 for (unsigned i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) { 265 for (unsigned i = 0; i < arraysize(kTestCases); ++i) {
266 const TestCase& test_case = kTestCases[i]; 266 const TestCase& test_case = kTestCases[i];
267 SetupInterruptedDownloadItem(test_case.reason); 267 SetupInterruptedDownloadItem(test_case.reason);
268 268
269 // GetTooltipText() elides the tooltip so that the text would fit within a 269 // GetTooltipText() elides the tooltip so that the text would fit within a
270 // given width. The following test would fail if kLargeTooltipWidth isn't 270 // given width. The following test would fail if kLargeTooltipWidth isn't
271 // large enough to accomodate all the strings. 271 // large enough to accomodate all the strings.
272 EXPECT_STREQ( 272 EXPECT_STREQ(
273 test_case.expected_tooltip, 273 test_case.expected_tooltip,
274 base::UTF16ToUTF8(model().GetTooltipText(font_list, 274 base::UTF16ToUTF8(model().GetTooltipText(font_list,
275 kLargeTooltipWidth)).c_str()); 275 kLargeTooltipWidth)).c_str());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 { 0, 0, false, true, true, "0 B, Paused" }, 328 { 0, 0, false, true, true, "0 B, Paused" },
329 { 1, 0, false, true, true, "1 B, Paused" }, 329 { 1, 0, false, true, true, "1 B, Paused" },
330 { 0, 2, false, true, true, "0/2 B, Paused" }, 330 { 0, 2, false, true, true, "0/2 B, Paused" },
331 { 1, 2, false, true, true, "1/2 B, Paused" }, 331 { 1, 2, false, true, true, "1/2 B, Paused" },
332 { 0, 2, true, true, true, "0/2 B, Paused" }, 332 { 0, 2, true, true, true, "0/2 B, Paused" },
333 { 1, 2, true, true, true, "1/2 B, Paused" }, 333 { 1, 2, true, true, true, "1/2 B, Paused" },
334 }; 334 };
335 335
336 SetupDownloadItemDefaults(); 336 SetupDownloadItemDefaults();
337 337
338 for (unsigned i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { 338 for (unsigned i = 0; i < arraysize(kTestCases); i++) {
339 const TestCase& test_case = kTestCases[i]; 339 const TestCase& test_case = kTestCases[i];
340 Mock::VerifyAndClearExpectations(&item()); 340 Mock::VerifyAndClearExpectations(&item());
341 Mock::VerifyAndClearExpectations(&model()); 341 Mock::VerifyAndClearExpectations(&model());
342 EXPECT_CALL(item(), GetReceivedBytes()) 342 EXPECT_CALL(item(), GetReceivedBytes())
343 .WillRepeatedly(Return(test_case.received_bytes)); 343 .WillRepeatedly(Return(test_case.received_bytes));
344 EXPECT_CALL(item(), GetTotalBytes()) 344 EXPECT_CALL(item(), GetTotalBytes())
345 .WillRepeatedly(Return(test_case.total_bytes)); 345 .WillRepeatedly(Return(test_case.total_bytes));
346 EXPECT_CALL(item(), TimeRemaining(_)) 346 EXPECT_CALL(item(), TimeRemaining(_))
347 .WillRepeatedly(testing::DoAll( 347 .WillRepeatedly(testing::DoAll(
348 testing::SetArgPointee<0>(base::TimeDelta::FromSeconds(10)), 348 testing::SetArgPointee<0>(base::TimeDelta::FromSeconds(10)),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 { DownloadItem::CANCELLED, true , false, false, false}, 400 { DownloadItem::CANCELLED, true , false, false, false},
401 { DownloadItem::CANCELLED, true , true , false, false}, 401 { DownloadItem::CANCELLED, true , true , false, false},
402 { DownloadItem::INTERRUPTED, false, false, false, false}, 402 { DownloadItem::INTERRUPTED, false, false, false, false},
403 { DownloadItem::INTERRUPTED, false, true , false, false}, 403 { DownloadItem::INTERRUPTED, false, true , false, false},
404 { DownloadItem::INTERRUPTED, true , false, false, false}, 404 { DownloadItem::INTERRUPTED, true , false, false, false},
405 { DownloadItem::INTERRUPTED, true , true , false, false} 405 { DownloadItem::INTERRUPTED, true , true , false, false}
406 }; 406 };
407 407
408 SetupDownloadItemDefaults(); 408 SetupDownloadItemDefaults();
409 409
410 for (unsigned i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); i++) { 410 for (unsigned i = 0; i < arraysize(kTestCases); i++) {
411 const TestCase& test_case = kTestCases[i]; 411 const TestCase& test_case = kTestCases[i];
412 EXPECT_CALL(item(), GetOpenWhenComplete()) 412 EXPECT_CALL(item(), GetOpenWhenComplete())
413 .WillRepeatedly(Return(test_case.is_auto_open)); 413 .WillRepeatedly(Return(test_case.is_auto_open));
414 EXPECT_CALL(item(), GetState()) 414 EXPECT_CALL(item(), GetState())
415 .WillRepeatedly(Return(test_case.state)); 415 .WillRepeatedly(Return(test_case.state));
416 EXPECT_CALL(item(), IsDangerous()) 416 EXPECT_CALL(item(), IsDangerous())
417 .WillRepeatedly(Return(test_case.is_dangerous)); 417 .WillRepeatedly(Return(test_case.is_dangerous));
418 EXPECT_CALL(item(), GetAutoOpened()) 418 EXPECT_CALL(item(), GetAutoOpened())
419 .WillRepeatedly(Return(test_case.auto_opened)); 419 .WillRepeatedly(Return(test_case.auto_opened));
420 420
421 EXPECT_EQ(test_case.expected_result, 421 EXPECT_EQ(test_case.expected_result,
422 model().ShouldRemoveFromShelfWhenComplete()) 422 model().ShouldRemoveFromShelfWhenComplete())
423 << "Test case: " << i; 423 << "Test case: " << i;
424 Mock::VerifyAndClearExpectations(&item()); 424 Mock::VerifyAndClearExpectations(&item());
425 Mock::VerifyAndClearExpectations(&model()); 425 Mock::VerifyAndClearExpectations(&model());
426 } 426 }
427 } 427 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | chrome/browser/download/download_target_determiner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698