Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_util.h" | |
| 11 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 12 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 12 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 13 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 13 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 14 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 14 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 15 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 15 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| 16 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 17 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 20 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 GURL main_frame_url_; | 283 GURL main_frame_url_; |
| 283 | 284 |
| 284 DISALLOW_COPY_AND_ASSIGN(PrefetchingObserver); | 285 DISALLOW_COPY_AND_ASSIGN(PrefetchingObserver); |
| 285 }; | 286 }; |
| 286 | 287 |
| 287 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { | 288 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { |
| 288 protected: | 289 protected: |
| 289 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 290 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
| 290 | 291 |
| 291 void SetUpCommandLine(base::CommandLine* command_line) override { | 292 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 292 command_line->AppendSwitchASCII( | 293 command_line->AppendSwitchASCII("force-fieldtrials", "trial/group"); |
| 293 switches::kSpeculativeResourcePrefetching, | 294 std::string parameter = base::StringPrintf( |
| 294 switches::kSpeculativeResourcePrefetchingEnabledExternal); | 295 "trial.group:%s/%s", kModeParamName, kExternalPrefetchingMode); |
| 296 command_line->AppendSwitchASCII("force-fieldtrial-params", parameter); | |
| 297 std::string enabled_feature = base::StringPrintf( | |
| 298 "%s<trial", kSpeculativeResourcePrefetchingFeatureName); | |
| 299 command_line->AppendSwitchASCII("enable-features", enabled_feature); | |
|
droger
2017/01/25 17:27:11
Optional:
You may be able to do this without usin
Benoit L
2017/01/26 09:58:15
This works in unit tests, but not in browser tests
| |
| 295 } | 300 } |
| 296 | 301 |
| 297 void SetUpOnMainThread() override { | 302 void SetUpOnMainThread() override { |
| 298 // Resolving all hosts to local allows us to have | 303 // Resolving all hosts to local allows us to have |
| 299 // cross domains navigations (matching url_visit_count_, etc). | 304 // cross domains navigations (matching url_visit_count_, etc). |
| 300 host_resolver()->AddRule("*", "127.0.0.1"); | 305 host_resolver()->AddRule("*", "127.0.0.1"); |
| 301 embedded_test_server()->RegisterRequestHandler( | 306 embedded_test_server()->RegisterRequestHandler( |
| 302 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, | 307 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, |
| 303 base::Unretained(this))); | 308 base::Unretained(this))); |
| 304 embedded_test_server()->RegisterRequestHandler( | 309 embedded_test_server()->RegisterRequestHandler( |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 TryToPrefetchURL(initial_url); | 872 TryToPrefetchURL(initial_url); |
| 868 NavigateToURLAndCheckSubresources(initial_url); | 873 NavigateToURLAndCheckSubresources(initial_url); |
| 869 ClearCache(); | 874 ClearCache(); |
| 870 // But the predictor database contains all subresources for the endpoint url | 875 // But the predictor database contains all subresources for the endpoint url |
| 871 // so this prefetch works. | 876 // so this prefetch works. |
| 872 PrefetchURL(GetURL(kHtmlSubresourcesPath)); | 877 PrefetchURL(GetURL(kHtmlSubresourcesPath)); |
| 873 NavigateToURLAndCheckSubresourcesAllCached(GetURL(kHtmlSubresourcesPath)); | 878 NavigateToURLAndCheckSubresourcesAllCached(GetURL(kHtmlSubresourcesPath)); |
| 874 } | 879 } |
| 875 | 880 |
| 876 } // namespace predictors | 881 } // namespace predictors |
| OLD | NEW |