Commit 1bb5022a authored by Byoungkown's avatar Byoungkown Committed by Commit Bot

[variations] Use base::size() instead of arraysize

arraysize is deprecated, we should use base::size() instead.
This cl clears a presubmit warnings.

Bug: 837308
Change-Id: I5479c0f16e6df0b43b617c0e15c6c28527c41cbd
Reviewed-on: https://chromium-review.googlesource.com/1213622Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Byoungkwon Ko <codeimpl@gmail.com>
Cr-Commit-Position: refs/heads/master@{#590160}
parent 59af5e55
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <string> #include <string>
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h"
#include "components/prefs/testing_pref_service.h" #include "components/prefs/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -31,11 +32,11 @@ TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) { ...@@ -31,11 +32,11 @@ TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) {
// one. Loop over the trial names twice, to test that caching returns the // one. Loop over the trial names twice, to test that caching returns the
// expected results. // expected results.
PermutedEntropyProvider provider(kEntropyValue, kMaxLowEntropySize); PermutedEntropyProvider provider(kEntropyValue, kMaxLowEntropySize);
for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) { for (size_t i = 0; i < 2 * base::size(kTestTrialNames); ++i) {
CachingPermutedEntropyProvider cached_provider( CachingPermutedEntropyProvider cached_provider(
&prefs, kEntropyValue, kMaxLowEntropySize); &prefs, kEntropyValue, kMaxLowEntropySize);
const std::string trial_name = const std::string trial_name =
kTestTrialNames[i % arraysize(kTestTrialNames)]; kTestTrialNames[i % base::size(kTestTrialNames)];
EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0), EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0),
cached_provider.GetEntropyForTrial(trial_name, 0)); cached_provider.GetEntropyForTrial(trial_name, 0));
} }
...@@ -43,9 +44,9 @@ TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) { ...@@ -43,9 +44,9 @@ TEST(CachingPermutedEntropyProviderTest, HasConsistentResults) {
// Now, do the same test re-using the same caching provider. // Now, do the same test re-using the same caching provider.
CachingPermutedEntropyProvider cached_provider( CachingPermutedEntropyProvider cached_provider(
&prefs, kEntropyValue, kMaxLowEntropySize); &prefs, kEntropyValue, kMaxLowEntropySize);
for (size_t i = 0; i < 2 * arraysize(kTestTrialNames); ++i) { for (size_t i = 0; i < 2 * base::size(kTestTrialNames); ++i) {
const std::string trial_name = const std::string trial_name =
kTestTrialNames[i % arraysize(kTestTrialNames)]; kTestTrialNames[i % base::size(kTestTrialNames)];
EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0), EXPECT_DOUBLE_EQ(provider.GetEntropyForTrial(trial_name, 0),
cached_provider.GetEntropyForTrial(trial_name, 0)); cached_provider.GetEntropyForTrial(trial_name, 0));
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/guid.h" #include "base/guid.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "components/variations/hashing.h" #include "components/variations/hashing.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -210,7 +211,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationSHA1) { ...@@ -210,7 +211,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationSHA1) {
base::FieldTrial::ONE_TIME_RANDOMIZED, nullptr), base::FieldTrial::ONE_TIME_RANDOMIZED, nullptr),
}; };
for (size_t i = 0; i < arraysize(trials); ++i) { for (size_t i = 0; i < base::size(trials); ++i) {
for (int j = 0; j < 100; ++j) for (int j = 0; j < 100; ++j)
trials[i]->AppendGroup(std::string(), 1); trials[i]->AppendGroup(std::string(), 1);
} }
...@@ -240,7 +241,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationPermuted) { ...@@ -240,7 +241,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationPermuted) {
base::FieldTrial::ONE_TIME_RANDOMIZED, nullptr), base::FieldTrial::ONE_TIME_RANDOMIZED, nullptr),
}; };
for (size_t i = 0; i < arraysize(trials); ++i) { for (size_t i = 0; i < base::size(trials); ++i) {
for (int j = 0; j < 100; ++j) for (int j = 0; j < 100; ++j)
trials[i]->AppendGroup(std::string(), 1); trials[i]->AppendGroup(std::string(), 1);
} }
...@@ -267,7 +268,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedPermuted) { ...@@ -267,7 +268,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedPermuted) {
base::FieldTrial::ONE_TIME_RANDOMIZED, kCustomSeed, nullptr, nullptr), base::FieldTrial::ONE_TIME_RANDOMIZED, kCustomSeed, nullptr, nullptr),
}; };
for (size_t i = 0; i < arraysize(trials); ++i) { for (size_t i = 0; i < base::size(trials); ++i) {
for (int j = 0; j < 100; ++j) for (int j = 0; j < 100; ++j)
trials[i]->AppendGroup(std::string(), 1); trials[i]->AppendGroup(std::string(), 1);
} }
...@@ -294,7 +295,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedSHA1) { ...@@ -294,7 +295,7 @@ TEST(EntropyProviderTest, UseOneTimeRandomizationWithCustomSeedSHA1) {
base::FieldTrial::ONE_TIME_RANDOMIZED, kCustomSeed, nullptr, nullptr), base::FieldTrial::ONE_TIME_RANDOMIZED, kCustomSeed, nullptr, nullptr),
}; };
for (size_t i = 0; i < arraysize(trials); ++i) { for (size_t i = 0; i < base::size(trials); ++i) {
for (int j = 0; j < 100; ++j) for (int j = 0; j < 100; ++j)
trials[i]->AppendGroup(std::string(), 1); trials[i]->AppendGroup(std::string(), 1);
} }
...@@ -310,7 +311,7 @@ TEST(EntropyProviderTest, SHA1Entropy) { ...@@ -310,7 +311,7 @@ TEST(EntropyProviderTest, SHA1Entropy) {
GenerateSHA1Entropy("there", "1") }; GenerateSHA1Entropy("there", "1") };
EXPECT_NE(results[0], results[1]); EXPECT_NE(results[0], results[1]);
for (size_t i = 0; i < arraysize(results); ++i) { for (size_t i = 0; i < base::size(results); ++i) {
EXPECT_LE(0.0, results[i]); EXPECT_LE(0.0, results[i]);
EXPECT_GT(1.0, results[i]); EXPECT_GT(1.0, results[i]);
} }
...@@ -327,7 +328,7 @@ TEST(EntropyProviderTest, PermutedEntropy) { ...@@ -327,7 +328,7 @@ TEST(EntropyProviderTest, PermutedEntropy) {
GeneratePermutedEntropy(4321, kMaxLowEntropySize, "1") }; GeneratePermutedEntropy(4321, kMaxLowEntropySize, "1") };
EXPECT_NE(results[0], results[1]); EXPECT_NE(results[0], results[1]);
for (size_t i = 0; i < arraysize(results); ++i) { for (size_t i = 0; i < base::size(results); ++i) {
EXPECT_LE(0.0, results[i]); EXPECT_LE(0.0, results[i]);
EXPECT_GT(1.0, results[i]); EXPECT_GT(1.0, results[i]);
} }
...@@ -352,14 +353,14 @@ TEST(EntropyProviderTest, PermutedEntropyProviderResults) { ...@@ -352,14 +353,14 @@ TEST(EntropyProviderTest, PermutedEntropyProviderResults) {
} }
TEST(EntropyProviderTest, SHA1EntropyIsUniform) { TEST(EntropyProviderTest, SHA1EntropyIsUniform) {
for (size_t i = 0; i < arraysize(kTestTrialNames); ++i) { for (size_t i = 0; i < base::size(kTestTrialNames); ++i) {
SHA1EntropyGenerator entropy_generator(kTestTrialNames[i]); SHA1EntropyGenerator entropy_generator(kTestTrialNames[i]);
PerformEntropyUniformityTest(kTestTrialNames[i], entropy_generator); PerformEntropyUniformityTest(kTestTrialNames[i], entropy_generator);
} }
} }
TEST(EntropyProviderTest, PermutedEntropyIsUniform) { TEST(EntropyProviderTest, PermutedEntropyIsUniform) {
for (size_t i = 0; i < arraysize(kTestTrialNames); ++i) { for (size_t i = 0; i < base::size(kTestTrialNames); ++i) {
PermutedEntropyGenerator entropy_generator(kTestTrialNames[i]); PermutedEntropyGenerator entropy_generator(kTestTrialNames[i]);
PerformEntropyUniformityTest(kTestTrialNames[i], entropy_generator); PerformEntropyUniformityTest(kTestTrialNames[i], entropy_generator);
} }
...@@ -394,7 +395,7 @@ TEST(EntropyProviderTest, SeededRandGeneratorIsUniform) { ...@@ -394,7 +395,7 @@ TEST(EntropyProviderTest, SeededRandGeneratorIsUniform) {
const int kMinAttempts = 1000; const int kMinAttempts = 1000;
const int kMaxAttempts = 1000000; const int kMaxAttempts = 1000000;
for (size_t i = 0; i < arraysize(kTestTrialNames); ++i) { for (size_t i = 0; i < base::size(kTestTrialNames); ++i) {
const uint32_t seed = HashName(kTestTrialNames[i]); const uint32_t seed = HashName(kTestTrialNames[i]);
internal::SeededRandGenerator rand_generator(seed); internal::SeededRandGenerator rand_generator(seed);
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/field_trial.h" #include "base/metrics/field_trial.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/variations/variations_associated_data.h" #include "components/variations/variations_associated_data.h"
...@@ -75,7 +76,7 @@ TEST(ExperimentLabelsTest, ExtractNonVariationLabels) { ...@@ -75,7 +76,7 @@ TEST(ExperimentLabelsTest, ExtractNonVariationLabels) {
"experiment3=123|Tue, 21 Jan 2014 15:30:21 GMT"}, "experiment3=123|Tue, 21 Jan 2014 15:30:21 GMT"},
}; };
for (size_t i = 0; i < arraysize(test_cases); ++i) { for (size_t i = 0; i < base::size(test_cases); ++i) {
std::string non_variation_labels = base::UTF16ToUTF8( std::string non_variation_labels = base::UTF16ToUTF8(
ExtractNonVariationLabels( ExtractNonVariationLabels(
base::ASCIIToUTF16(test_cases[i].input_label))); base::ASCIIToUTF16(test_cases[i].input_label)));
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <stdint.h> #include <stdint.h>
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace variations { namespace variations {
...@@ -26,7 +27,7 @@ TEST(HashingTest, HashName) { ...@@ -26,7 +27,7 @@ TEST(HashingTest, HashName) {
{"abcdefghijklmonpqrstuvwxyz", 787728696u}, {"abcdefghijklmonpqrstuvwxyz", 787728696u},
{"0123456789ABCDEF", 348858318U}}; {"0123456789ABCDEF", 348858318U}};
for (size_t i = 0; i < arraysize(known_hashes); ++i) { for (size_t i = 0; i < base::size(known_hashes); ++i) {
EXPECT_EQ(known_hashes[i].hash_value, HashName(known_hashes[i].name)); EXPECT_EQ(known_hashes[i].hash_value, HashName(known_hashes[i].name));
} }
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "components/google/core/common/google_util.h" #include "components/google/core/common/google_util.h"
#include "components/variations/variations_http_header_provider.h" #include "components/variations/variations_http_header_provider.h"
...@@ -73,12 +74,12 @@ bool IsGoogleDomain(const GURL& url) { ...@@ -73,12 +74,12 @@ bool IsGoogleDomain(const GURL& url) {
// Some domains don't have international TLD extensions, so testing for them // Some domains don't have international TLD extensions, so testing for them
// is very straight forward. // is very straight forward.
const std::string host = url.host(); const std::string host = url.host();
for (size_t i = 0; i < arraysize(kSuffixesToSetHeadersFor); ++i) { for (size_t i = 0; i < base::size(kSuffixesToSetHeadersFor); ++i) {
if (base::EndsWith(host, kSuffixesToSetHeadersFor[i], if (base::EndsWith(host, kSuffixesToSetHeadersFor[i],
base::CompareCase::INSENSITIVE_ASCII)) base::CompareCase::INSENSITIVE_ASCII))
return true; return true;
} }
for (size_t i = 0; i < arraysize(kHostsToSetHeadersFor); ++i) { for (size_t i = 0; i < base::size(kHostsToSetHeadersFor); ++i) {
if (base::LowerCaseEqualsASCII(host, kHostsToSetHeadersFor[i])) if (base::LowerCaseEqualsASCII(host, kHostsToSetHeadersFor[i]))
return true; return true;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <stddef.h> #include <stddef.h>
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -146,7 +147,7 @@ TEST(VariationsHttpHeadersTest, ShouldAppendHeaders) { ...@@ -146,7 +147,7 @@ TEST(VariationsHttpHeadersTest, ShouldAppendHeaders) {
{"https://a.b.googleweblight.com", false}, {"https://a.b.googleweblight.com", false},
}; };
for (size_t i = 0; i < arraysize(cases); ++i) { for (size_t i = 0; i < base::size(cases); ++i) {
const GURL url(cases[i].url); const GURL url(cases[i].url);
EXPECT_EQ(cases[i].should_append_headers, ShouldAppendVariationHeaders(url)) EXPECT_EQ(cases[i].should_append_headers, ShouldAppendVariationHeaders(url))
<< url; << url;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/sha1.h" #include "base/sha1.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -459,7 +460,7 @@ TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) { ...@@ -459,7 +460,7 @@ TEST_F(VariationsServiceTest, SeedNotStoredWhenNonOKStatus) {
&prefs_, &network_tracker_), &prefs_, &network_tracker_),
&prefs_, GetMetricsStateManager(), true); &prefs_, GetMetricsStateManager(), true);
service.set_intercepts_fetch(false); service.set_intercepts_fetch(false);
for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { for (size_t i = 0; i < base::size(non_ok_status_codes); ++i) {
EXPECT_TRUE(prefs_.FindPreference(prefs::kVariationsCompressedSeed) EXPECT_TRUE(prefs_.FindPreference(prefs::kVariationsCompressedSeed)
->IsDefaultValue()); ->IsDefaultValue());
service.test_url_loader_factory()->ClearResponses(); service.test_url_loader_factory()->ClearResponses();
...@@ -512,7 +513,7 @@ TEST_F(VariationsServiceTest, InstanceManipulations) { ...@@ -512,7 +513,7 @@ TEST_F(VariationsServiceTest, InstanceManipulations) {
std::string serialized_seed = SerializeSeed(CreateTestSeed()); std::string serialized_seed = SerializeSeed(CreateTestSeed());
VariationsService::EnableFetchForTesting(); VariationsService::EnableFetchForTesting();
for (size_t i = 0; i < arraysize(cases); ++i) { for (size_t i = 0; i < base::size(cases); ++i) {
TestVariationsService service( TestVariationsService service(
std::make_unique<web_resource::TestRequestAllowedNotifier>( std::make_unique<web_resource::TestRequestAllowedNotifier>(
&prefs_, &network_tracker_), &prefs_, &network_tracker_),
...@@ -592,7 +593,7 @@ TEST_F(VariationsServiceTest, Observer) { ...@@ -592,7 +593,7 @@ TEST_F(VariationsServiceTest, Observer) {
{1, 0, 1, 0, 1}, {1, 0, 1, 0, 1},
}; };
for (size_t i = 0; i < arraysize(cases); ++i) { for (size_t i = 0; i < base::size(cases); ++i) {
TestVariationsServiceObserver observer; TestVariationsServiceObserver observer;
service.AddObserver(&observer); service.AddObserver(&observer);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
...@@ -641,7 +642,7 @@ TEST_F(VariationsSeedProcessorTest, FeatureEnabledOrDisableByTrial) { ...@@ -641,7 +642,7 @@ TEST_F(VariationsSeedProcessorTest, FeatureEnabledOrDisableByTrial) {
{nullptr, kFeatureOffByDefault.name, false, true}, {nullptr, kFeatureOffByDefault.name, false, true},
}; };
for (size_t i = 0; i < arraysize(test_cases); i++) { for (size_t i = 0; i < base::size(test_cases); i++) {
const auto& test_case = test_cases[i]; const auto& test_case = test_cases[i];
SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]", i)); SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]", i));
...@@ -760,7 +761,7 @@ TEST_F(VariationsSeedProcessorTest, FeatureAssociationAndForcing) { ...@@ -760,7 +761,7 @@ TEST_F(VariationsSeedProcessorTest, FeatureAssociationAndForcing) {
kForcedOffGroup, false, true}, kForcedOffGroup, false, true},
}; };
for (size_t i = 0; i < arraysize(test_cases); i++) { for (size_t i = 0; i < base::size(test_cases); i++) {
const auto& test_case = test_cases[i]; const auto& test_case = test_cases[i];
const int group = test_case.one_hundred_percent_group; const int group = test_case.one_hundred_percent_group;
SCOPED_TRACE(base::StringPrintf( SCOPED_TRACE(base::StringPrintf(
...@@ -833,7 +834,7 @@ TEST_F(VariationsSeedProcessorTest, FeaturesInExpiredStudies) { ...@@ -833,7 +834,7 @@ TEST_F(VariationsSeedProcessorTest, FeaturesInExpiredStudies) {
{kEnabledFeature, false, year_later, false}, {kEnabledFeature, false, year_later, false},
}; };
for (size_t i = 0; i < arraysize(test_cases); i++) { for (size_t i = 0; i < base::size(test_cases); i++) {
const auto& test_case = test_cases[i]; const auto& test_case = test_cases[i];
SCOPED_TRACE( SCOPED_TRACE(
base::StringPrintf("Test[%" PRIuS "]: %s", i, test_case.feature.name)); base::StringPrintf("Test[%" PRIuS "]: %s", i, test_case.feature.name));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment