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