#include "components/variations/net/variations_http_headers.h"
#include <string>
#include "base/containers/flat_map.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_command_line.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/variations/net/variations_flags.h"
#include "components/variations/variations.mojom.h"
#include "net/base/isolation_info.h"
#include "net/cookies/site_for_cookies.h"
#include "services/network/public/cpp/resource_request.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace variations {
namespace {
network::ResourceRequest CreateResourceRequest(
const std::string& request_initiator_url,
bool is_outermost_main_frame,
bool has_trusted_params,
const std::string& isolation_info_top_frame_origin_url,
const std::string& isolation_info_frame_origin_url) { … }
void AppendVariationsHeader(const GURL& destination,
Owner owner,
network::ResourceRequest* request) { … }
}
TEST(VariationsHttpHeadersTest, ShouldAppendVariationsHeader) { … }
#if BUILDFLAG(IS_IOS)
TEST(VariationsHttpHeadersTest, ShouldAppendVariationsHeaderLocalhost) {
base::test::ScopedCommandLine scoped_command_line;
scoped_command_line.GetProcessCommandLine()->AppendSwitch(
variations::kAppendVariationsHeadersToLocalhostForTesting);
struct {
const char* url;
bool should_append_headers;
} cases[] = {
{"https://127.0.0.1", true},
{"http://127.0.0.1", true},
{"https://127.0.0.1:12345", true},
{"http://127.0.0.1:12345", true},
};
for (const auto& c : cases) {
const GURL url(c.url);
EXPECT_EQ(c.should_append_headers,
ShouldAppendVariationsHeaderForTesting(url, "Append"))
<< url;
}
}
#endif
struct PopulateRequestContextHistogramData { … };
class PopulateRequestContextHistogramTest
: public testing::TestWithParam<PopulateRequestContextHistogramData> { … };
const PopulateRequestContextHistogramData
PopulateRequestContextHistogramTest::kCases[] = …;
TEST(VariationsHttpHeadersTest, PopulateUrlValidationResultHistograms) { … }
TEST(VariationsHttpHeadersTest, PopulateDomainOwnerHistogram) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(PopulateRequestContextHistogramTest, PopulateRequestContextHistogram) { … }
}