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

Side by Side Diff: chrome/browser/autocomplete/bookmark_provider_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/autocomplete/bookmark_provider.h" 5 #include "chrome/browser/autocomplete/bookmark_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 void BookmarkProviderTest::SetUp() { 88 void BookmarkProviderTest::SetUp() {
89 profile_.reset(new TestingProfile()); 89 profile_.reset(new TestingProfile());
90 DCHECK(profile_.get()); 90 DCHECK(profile_.get());
91 provider_ = new BookmarkProvider(profile_.get()); 91 provider_ = new BookmarkProvider(profile_.get());
92 DCHECK(provider_.get()); 92 DCHECK(provider_.get());
93 provider_->set_bookmark_model_for_testing(model_.get()); 93 provider_->set_bookmark_model_for_testing(model_.get());
94 94
95 const BookmarkNode* other_node = model_->other_node(); 95 const BookmarkNode* other_node = model_->other_node();
96 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(bookmark_provider_test_data); ++i) { 96 for (size_t i = 0; i < arraysize(bookmark_provider_test_data); ++i) {
97 const BookmarksTestInfo& cur(bookmark_provider_test_data[i]); 97 const BookmarksTestInfo& cur(bookmark_provider_test_data[i]);
98 const GURL url(cur.url); 98 const GURL url(cur.url);
99 model_->AddURL(other_node, other_node->child_count(), 99 model_->AddURL(other_node, other_node->child_count(),
100 base::ASCIIToUTF16(cur.title), url); 100 base::ASCIIToUTF16(cur.title), url);
101 } 101 }
102 } 102 }
103 103
104 // Structures and functions supporting the BookmarkProviderTest.Positions 104 // Structures and functions supporting the BookmarkProviderTest.Positions
105 // unit test. 105 // unit test.
106 106
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 {"frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, 254 {"frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}},
255 {"frankly frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}}, 255 {"frankly frankly", 1, {{{0, 7}, {8, 15}, {0, 0}}}},
256 {"foobar foo", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, 256 {"foobar foo", 1, {{{0, 6}, {7, 13}, {0, 0}}}},
257 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}}, 257 {"foo foobar", 1, {{{0, 6}, {7, 13}, {0, 0}}}},
258 // This ensures that leading whitespace in the title is removed. 258 // This ensures that leading whitespace in the title is removed.
259 {"hello", 1, {{{0, 5}, {7, 12}, {0, 0}}}}, 259 {"hello", 1, {{{0, 5}, {7, 12}, {0, 0}}}},
260 // This ensures that empty titles yield empty classifications. 260 // This ensures that empty titles yield empty classifications.
261 {"emptytitle", 1, {}}, 261 {"emptytitle", 1, {}},
262 }; 262 };
263 263
264 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 264 for (size_t i = 0; i < arraysize(query_data); ++i) {
265 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 265 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
266 base::string16::npos, std::string(), GURL(), 266 base::string16::npos, std::string(), GURL(),
267 metrics::OmniboxEventProto::INVALID_SPEC, false, 267 metrics::OmniboxEventProto::INVALID_SPEC, false,
268 false, false, true, 268 false, false, true,
269 ChromeAutocompleteSchemeClassifier(profile_.get())); 269 ChromeAutocompleteSchemeClassifier(profile_.get()));
270 provider_->Start(input, false); 270 provider_->Start(input, false);
271 const ACMatches& matches(provider_->matches()); 271 const ACMatches& matches(provider_->matches());
272 // Validate number of results is as expected. 272 // Validate number of results is as expected.
273 EXPECT_LE(matches.size(), query_data[i].match_count) 273 EXPECT_LE(matches.size(), query_data[i].match_count)
274 << "One or more of the following matches were unexpected:\n" 274 << "One or more of the following matches were unexpected:\n"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 // Ranking of prefix matches with URL boost. 335 // Ranking of prefix matches with URL boost.
336 {"burn worm", 3, {"burning worms #1", // boosted 336 {"burn worm", 3, {"burning worms #1", // boosted
337 "worming burns #10", // boosted but longer title 337 "worming burns #10", // boosted but longer title
338 "burning worms #2"}}, // not boosted 338 "burning worms #2"}}, // not boosted
339 // A query of "worm burn" will have the same results. 339 // A query of "worm burn" will have the same results.
340 {"worm burn", 3, {"burning worms #1", // boosted 340 {"worm burn", 3, {"burning worms #1", // boosted
341 "worming burns #10", // boosted but longer title 341 "worming burns #10", // boosted but longer title
342 "burning worms #2"}}, // not boosted 342 "burning worms #2"}}, // not boosted
343 }; 343 };
344 344
345 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 345 for (size_t i = 0; i < arraysize(query_data); ++i) {
346 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 346 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
347 base::string16::npos, std::string(), GURL(), 347 base::string16::npos, std::string(), GURL(),
348 metrics::OmniboxEventProto::INVALID_SPEC, false, 348 metrics::OmniboxEventProto::INVALID_SPEC, false,
349 false, false, true, 349 false, false, true,
350 ChromeAutocompleteSchemeClassifier(profile_.get())); 350 ChromeAutocompleteSchemeClassifier(profile_.get()));
351 provider_->Start(input, false); 351 provider_->Start(input, false);
352 const ACMatches& matches(provider_->matches()); 352 const ACMatches& matches(provider_->matches());
353 // Validate number and content of results is as expected. 353 // Validate number and content of results is as expected.
354 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size()); 354 for (size_t j = 0; j < std::max(query_data[i].match_count, matches.size());
355 ++j) { 355 ++j) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 { "versi", "chrome://version", false, "" }, 390 { "versi", "chrome://version", false, "" },
391 { "abou", "chrome://omnibox", false, "" }, 391 { "abou", "chrome://omnibox", false, "" },
392 { "about:om", "chrome://omnibox", true, "nibox" } 392 { "about:om", "chrome://omnibox", true, "nibox" }
393 // Note: when adding a new URL to this test, be sure to add it to the list 393 // Note: when adding a new URL to this test, be sure to add it to the list
394 // of bookmarks at the top of the file as well. All items in this list 394 // of bookmarks at the top of the file as well. All items in this list
395 // need to be in the bookmarks list because BookmarkProvider's 395 // need to be in the bookmarks list because BookmarkProvider's
396 // TitleMatchToACMatch() has an assertion that verifies the URL is 396 // TitleMatchToACMatch() has an assertion that verifies the URL is
397 // actually bookmarked. 397 // actually bookmarked.
398 }; 398 };
399 399
400 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 400 for (size_t i = 0; i < arraysize(query_data); ++i) {
401 const std::string description = "for query=" + query_data[i].query + 401 const std::string description = "for query=" + query_data[i].query +
402 " and url=" + query_data[i].url; 402 " and url=" + query_data[i].url;
403 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 403 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
404 base::string16::npos, std::string(), GURL(), 404 base::string16::npos, std::string(), GURL(),
405 metrics::OmniboxEventProto::INVALID_SPEC, false, 405 metrics::OmniboxEventProto::INVALID_SPEC, false,
406 false, false, true, 406 false, false, true,
407 ChromeAutocompleteSchemeClassifier(profile_.get())); 407 ChromeAutocompleteSchemeClassifier(profile_.get()));
408 const base::string16 fixed_up_input( 408 const base::string16 fixed_up_input(
409 provider_->FixupUserInput(input).second); 409 provider_->FixupUserInput(input).second);
410 BookmarkNode node(GURL(query_data[i].url)); 410 BookmarkNode node(GURL(query_data[i].url));
(...skipping 23 matching lines...) Expand all
434 { "foo http", "http://www.foobar.com", "0:3,4:1,11:3,14:1" }, 434 { "foo http", "http://www.foobar.com", "0:3,4:1,11:3,14:1" },
435 { "blah", "blah.com", "0:3,4:1" }, 435 { "blah", "blah.com", "0:3,4:1" },
436 { "http blah", "http://blah.com", "0:3,4:1,7:3,11:1" }, 436 { "http blah", "http://blah.com", "0:3,4:1,7:3,11:1" },
437 { "dom", "www.domain.com/http/", "0:1,4:3,7:1" }, 437 { "dom", "www.domain.com/http/", "0:1,4:3,7:1" },
438 { "dom http", "http://www.domain.com/http/", 438 { "dom http", "http://www.domain.com/http/",
439 "0:3,4:1,11:3,14:1,22:3,26:1" }, 439 "0:3,4:1,11:3,14:1,22:3,26:1" },
440 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" }, 440 { "rep", "www.repeat.com/1/repeat/2/", "0:1,4:3,7:1,17:3,20:1" },
441 { "versi", "chrome://version", "0:1,9:3,14:1" } 441 { "versi", "chrome://version", "0:1,9:3,14:1" }
442 }; 442 };
443 443
444 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(query_data); ++i) { 444 for (size_t i = 0; i < arraysize(query_data); ++i) {
445 std::string description = "for query=" + query_data[i].query; 445 std::string description = "for query=" + query_data[i].query;
446 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query), 446 AutocompleteInput input(base::ASCIIToUTF16(query_data[i].query),
447 base::string16::npos, std::string(), GURL(), 447 base::string16::npos, std::string(), GURL(),
448 metrics::OmniboxEventProto::INVALID_SPEC, false, 448 metrics::OmniboxEventProto::INVALID_SPEC, false,
449 false, false, true, 449 false, false, true,
450 ChromeAutocompleteSchemeClassifier(profile_.get())); 450 ChromeAutocompleteSchemeClassifier(profile_.get()));
451 provider_->Start(input, false); 451 provider_->Start(input, false);
452 const ACMatches& matches(provider_->matches()); 452 const ACMatches& matches(provider_->matches());
453 ASSERT_EQ(1U, matches.size()) << description; 453 ASSERT_EQ(1U, matches.size()) << description;
454 const AutocompleteMatch& match = matches[0]; 454 const AutocompleteMatch& match = matches[0];
(...skipping 10 matching lines...) Expand all
465 ASSERT_EQ(2U, chunks.size()) << description; 465 ASSERT_EQ(2U, chunks.size()) << description;
466 size_t offset; 466 size_t offset;
467 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description; 467 EXPECT_TRUE(base::StringToSizeT(chunks[0], &offset)) << description;
468 EXPECT_EQ(offset, match.contents_class[i].offset) << description; 468 EXPECT_EQ(offset, match.contents_class[i].offset) << description;
469 int style; 469 int style;
470 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description; 470 EXPECT_TRUE(base::StringToInt(chunks[1], &style)) << description;
471 EXPECT_EQ(style, match.contents_class[i].style) << description; 471 EXPECT_EQ(style, match.contents_class[i].style) << description;
472 } 472 }
473 } 473 }
474 } 474 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698