Commit 2c28f7c1 authored by Tarun Bansal's avatar Tarun Bansal Committed by Commit Bot

Resource loading hints browsertests for experimental hints

Add few browser tests that create component info with
experimental and/or default loading hints. Then, load a webpage
to verify that the resources specified by experimental/default
hints are blocked based on the finch experiment settings.

Change-Id: Id2d20d6f696d8de88a8cf0ed65a319ed67e9a500
Bug: 900699
Reviewed-on: https://chromium-review.googlesource.com/c/1314135
Commit-Queue: Tarun Bansal <tbansal@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605377}
parent 43d76b65
...@@ -71,6 +71,86 @@ TestComponentCreator::CreateComponentInfoWithPageHints( ...@@ -71,6 +71,86 @@ TestComponentCreator::CreateComponentInfoWithPageHints(
return WriteConfigToFileAndReturnComponentInfo(config); return WriteConfigToFileAndReturnComponentInfo(config);
} }
optimization_guide::ComponentInfo
TestComponentCreator::CreateComponentInfoWithExperimentalPageHints(
optimization_guide::proto::OptimizationType optimization_type,
const std::vector<std::string>& page_hint_host_suffixes,
const std::vector<std::string>& experimental_resource_patterns) {
optimization_guide::proto::Configuration config;
for (const auto& page_hint_site : page_hint_host_suffixes) {
optimization_guide::proto::Hint* hint = config.add_hints();
hint->set_key(page_hint_site);
hint->set_key_representation(optimization_guide::proto::HOST_SUFFIX);
optimization_guide::proto::PageHint* page_hint = hint->add_page_hints();
page_hint->set_page_pattern("*");
optimization_guide::proto::Optimization* optimization =
page_hint->add_whitelisted_optimizations();
optimization->set_optimization_type(optimization_type);
optimization->set_experiment_name(kFooExperimentName);
for (auto resource_blocking_pattern : experimental_resource_patterns) {
optimization_guide::proto::ResourceLoadingHint* resource_loading_hint =
optimization->add_resource_loading_hints();
resource_loading_hint->set_loading_optimization_type(
optimization_guide::proto::LOADING_BLOCK_RESOURCE);
resource_loading_hint->set_resource_pattern(resource_blocking_pattern);
}
}
return WriteConfigToFileAndReturnComponentInfo(config);
}
optimization_guide::ComponentInfo
TestComponentCreator::CreateComponentInfoWithMixPageHints(
optimization_guide::proto::OptimizationType optimization_type,
const std::vector<std::string>& page_hint_host_suffixes,
const std::vector<std::string>& experimental_resource_patterns,
const std::vector<std::string>& default_resource_patterns) {
optimization_guide::proto::Configuration config;
for (const auto& page_hint_site : page_hint_host_suffixes) {
optimization_guide::proto::Hint* hint = config.add_hints();
hint->set_key(page_hint_site);
hint->set_key_representation(optimization_guide::proto::HOST_SUFFIX);
optimization_guide::proto::PageHint* page_hint = hint->add_page_hints();
page_hint->set_page_pattern("*");
// Add experimental patterns first so they get higher priority.
{
optimization_guide::proto::Optimization* optimization =
page_hint->add_whitelisted_optimizations();
optimization->set_optimization_type(optimization_type);
optimization->set_experiment_name(kFooExperimentName);
for (auto resource_blocking_pattern : experimental_resource_patterns) {
optimization_guide::proto::ResourceLoadingHint* resource_loading_hint =
optimization->add_resource_loading_hints();
resource_loading_hint->set_loading_optimization_type(
optimization_guide::proto::LOADING_BLOCK_RESOURCE);
resource_loading_hint->set_resource_pattern(resource_blocking_pattern);
}
}
{
optimization_guide::proto::Optimization* optimization =
page_hint->add_whitelisted_optimizations();
optimization->set_optimization_type(optimization_type);
for (auto resource_blocking_pattern : default_resource_patterns) {
optimization_guide::proto::ResourceLoadingHint* resource_loading_hint =
optimization->add_resource_loading_hints();
resource_loading_hint->set_loading_optimization_type(
optimization_guide::proto::LOADING_BLOCK_RESOURCE);
resource_loading_hint->set_resource_pattern(resource_blocking_pattern);
}
}
}
return WriteConfigToFileAndReturnComponentInfo(config);
}
base::FilePath TestComponentCreator::GetFilePath(std::string file_path_suffix) { base::FilePath TestComponentCreator::GetFilePath(std::string file_path_suffix) {
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
EXPECT_TRUE(scoped_temp_dir_->IsValid() || EXPECT_TRUE(scoped_temp_dir_->IsValid() ||
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
namespace optimization_guide { namespace optimization_guide {
namespace testing { namespace testing {
// Experiment name used for experimental resource loading hints.
static const char kFooExperimentName[] = "foo_experiment";
// Helper class to create test OptimizationHints components for testing. // Helper class to create test OptimizationHints components for testing.
// //
// All temporary files and paths are cleaned up when this instance goes out of // All temporary files and paths are cleaned up when this instance goes out of
...@@ -31,14 +34,42 @@ class TestComponentCreator { ...@@ -31,14 +34,42 @@ class TestComponentCreator {
optimization_guide::ComponentInfo CreateComponentInfoWithTopLevelWhitelist( optimization_guide::ComponentInfo CreateComponentInfoWithTopLevelWhitelist(
optimization_guide::proto::OptimizationType optimization_type, optimization_guide::proto::OptimizationType optimization_type,
const std::vector<std::string>& whitelisted_host_suffixes); const std::vector<std::string>& whitelisted_host_suffixes);
// Creates component data based on |whitelisted_host_suffixes| with page hints // Creates component data based on |whitelisted_host_suffixes| with page hints
// for type |optimization_type| blocking resources specified by // for type |optimization_type| blocking resources specified by
// |resource_patterns|.and returns the ComponentInfo for it. // |resource_patterns|, and returns the ComponentInfo for it.
optimization_guide::ComponentInfo CreateComponentInfoWithPageHints( optimization_guide::ComponentInfo CreateComponentInfoWithPageHints(
optimization_guide::proto::OptimizationType optimization_type, optimization_guide::proto::OptimizationType optimization_type,
const std::vector<std::string>& whitelisted_host_suffixes, const std::vector<std::string>& whitelisted_host_suffixes,
const std::vector<std::string>& resource_patterns); const std::vector<std::string>& resource_patterns);
// Creates component data based on |whitelisted_host_suffixes| with page hints
// for type |optimization_type| blocking resources specified by
// |experimental_resource_patterns|, and returns the ComponentInfo for it.
// The loading hints are set as experimental with experiment name set to
// kFooExperimentName.
// Creates component data for testing with experimental optimizations. It
// creates a PageHint (with page pattern "*" for each key in
// |whitelisted_host_suffixes| that each has resource blocking patterns from
// |experimental_resource_patterns|.
optimization_guide::ComponentInfo
CreateComponentInfoWithExperimentalPageHints(
optimization_guide::proto::OptimizationType optimization_type,
const std::vector<std::string>& whitelisted_host_suffixes,
const std::vector<std::string>& experimental_resource_patterns);
// Creates component data for testing with both default and experimental
// optimizations. It creates a PageHint (with page pattern "*" for each key in
// |whitelisted_host_suffixes| that each has resource blocking patterns from
// |default_resource_patterns| and |experimental_resource_patterns|. The
// experimental hints are guarded behind experiment kFooExperimentName.
optimization_guide::ComponentInfo CreateComponentInfoWithMixPageHints(
optimization_guide::proto::OptimizationType optimization_type,
const std::vector<std::string>& whitelisted_host_suffixes,
const std::vector<std::string>& experimental_resource_patterns,
const std::vector<std::string>& default_resource_patterns);
private: private:
// Returns the scoped temp directory path with the |file_path_suffix| that is // Returns the scoped temp directory path with the |file_path_suffix| that is
// valid for the lifetime of this instance. // valid for the lifetime of this instance.
......
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