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 <algorithm> | 5 #include <algorithm> |
6 #include <cstddef> | 6 #include <cstddef> |
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 "base/strings/string_util.h" |
12 #include "base/test/histogram_tester.h" | 12 #include "base/test/histogram_tester.h" |
13 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 13 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 14 #include "chrome/browser/predictors/loading_data_collector.h" |
14 #include "chrome/browser/predictors/loading_predictor.h" | 15 #include "chrome/browser/predictors/loading_predictor.h" |
15 #include "chrome/browser/predictors/loading_predictor_factory.h" | 16 #include "chrome/browser/predictors/loading_predictor_factory.h" |
16 #include "chrome/browser/predictors/loading_stats_collector.h" | 17 #include "chrome/browser/predictors/loading_stats_collector.h" |
17 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 18 #include "chrome/browser/predictors/loading_test_util.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
24 #include "content/public/browser/browsing_data_remover.h" | 25 #include "content/public/browser/browsing_data_remover.h" |
25 #include "net/base/host_port_pair.h" | 26 #include "net/base/host_port_pair.h" |
26 #include "net/base/url_util.h" | 27 #include "net/base/url_util.h" |
27 #include "net/dns/mock_host_resolver.h" | 28 #include "net/dns/mock_host_resolver.h" |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 server->RegisterRequestMonitor(base::Bind( | 361 server->RegisterRequestMonitor(base::Bind( |
361 &ResourcePrefetchPredictorBrowserTest::MonitorResourceRequest, | 362 &ResourcePrefetchPredictorBrowserTest::MonitorResourceRequest, |
362 base::Unretained(this))); | 363 base::Unretained(this))); |
363 ASSERT_TRUE(server->Start()); | 364 ASSERT_TRUE(server->Start()); |
364 } | 365 } |
365 | 366 |
366 predictor_ = LoadingPredictorFactory::GetForProfile(browser()->profile()); | 367 predictor_ = LoadingPredictorFactory::GetForProfile(browser()->profile()); |
367 ASSERT_TRUE(predictor_); | 368 ASSERT_TRUE(predictor_); |
368 resource_prefetch_predictor_ = predictor_->resource_prefetch_predictor(); | 369 resource_prefetch_predictor_ = predictor_->resource_prefetch_predictor(); |
369 // URLs from the test server contain a port number. | 370 // URLs from the test server contain a port number. |
370 ResourcePrefetchPredictor::SetAllowPortInUrlsForTesting(true); | 371 LoadingDataCollector::SetAllowPortInUrlsForTesting(true); |
371 EnsurePredictorInitialized(); | 372 EnsurePredictorInitialized(); |
372 histogram_tester_.reset(new base::HistogramTester()); | 373 histogram_tester_.reset(new base::HistogramTester()); |
373 } | 374 } |
374 | 375 |
375 void TearDownOnMainThread() override { | 376 void TearDownOnMainThread() override { |
376 ResourcePrefetchPredictor::SetAllowPortInUrlsForTesting(false); | 377 LoadingDataCollector::SetAllowPortInUrlsForTesting(false); |
377 } | 378 } |
378 | 379 |
379 void TestLearningAndPrefetching( | 380 void TestLearningAndPrefetching( |
380 const GURL& main_frame_url, | 381 const GURL& main_frame_url, |
381 bool match_before_first_contentful_paint = false) { | 382 bool match_before_first_contentful_paint = false) { |
382 // Navigate to |main_frame_url| and check all the expectations. | 383 // Navigate to |main_frame_url| and check all the expectations. |
383 NavigateToURLAndCheckSubresources(main_frame_url, | 384 NavigateToURLAndCheckSubresources(main_frame_url, |
384 WindowOpenDisposition::CURRENT_TAB, | 385 WindowOpenDisposition::CURRENT_TAB, |
385 match_before_first_contentful_paint); | 386 match_before_first_contentful_paint); |
386 ClearCache(); | 387 ClearCache(); |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 AddResourcesFromSubresourceHtml(); | 1009 AddResourcesFromSubresourceHtml(); |
1009 | 1010 |
1010 NavigateToURLAndCheckSubresources(initial_url); | 1011 NavigateToURLAndCheckSubresources(initial_url); |
1011 ClearCache(); | 1012 ClearCache(); |
1012 NavigateToURLAndCheckSubresources(initial_url); | 1013 NavigateToURLAndCheckSubresources(initial_url); |
1013 ClearCache(); | 1014 ClearCache(); |
1014 NavigateToURLAndCheckPrefetching(initial_url); | 1015 NavigateToURLAndCheckPrefetching(initial_url); |
1015 } | 1016 } |
1016 | 1017 |
1017 } // namespace predictors | 1018 } // namespace predictors |
OLD | NEW |