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 "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/browsing_data/browsing_data_remover.h" | 14 |
15 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
16 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" | 15 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
17 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 16 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
18 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 17 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
19 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 18 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
23 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/test/base/in_process_browser_test.h" | 23 #include "chrome/test/base/in_process_browser_test.h" |
25 #include "chrome/test/base/ui_test_utils.h" | 24 #include "chrome/test/base/ui_test_utils.h" |
| 25 #include "content/public/browser/browsing_data_remover.h" |
26 #include "net/base/host_port_pair.h" | 26 #include "net/base/host_port_pair.h" |
27 #include "net/dns/mock_host_resolver.h" | 27 #include "net/dns/mock_host_resolver.h" |
28 #include "net/test/embedded_test_server/http_request.h" | 28 #include "net/test/embedded_test_server/http_request.h" |
29 #include "net/test/embedded_test_server/http_response.h" | 29 #include "net/test/embedded_test_server/http_response.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 namespace predictors { | 33 namespace predictors { |
34 | 34 |
35 namespace { | 35 namespace { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 void OnPredictorInitialized() override { run_loop_.Quit(); } | 109 void OnPredictorInitialized() override { run_loop_.Quit(); } |
110 | 110 |
111 void Wait() { run_loop_.Run(); } | 111 void Wait() { run_loop_.Run(); } |
112 | 112 |
113 private: | 113 private: |
114 base::RunLoop run_loop_; | 114 base::RunLoop run_loop_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(InitializationObserver); | 116 DISALLOW_COPY_AND_ASSIGN(InitializationObserver); |
117 }; | 117 }; |
118 | 118 |
119 class BrowsingDataRemoverObserver : public BrowsingDataRemover::Observer { | 119 class BrowsingDataRemoverObserver |
| 120 : public content::BrowsingDataRemover::Observer { |
120 public: | 121 public: |
121 explicit BrowsingDataRemoverObserver(BrowsingDataRemover* remover) | 122 explicit BrowsingDataRemoverObserver(content::BrowsingDataRemover* remover) |
122 : remover_(remover) { | 123 : remover_(remover) { |
123 remover_->AddObserver(this); | 124 remover_->AddObserver(this); |
124 } | 125 } |
125 ~BrowsingDataRemoverObserver() override { remover_->RemoveObserver(this); } | 126 ~BrowsingDataRemoverObserver() override { remover_->RemoveObserver(this); } |
126 | 127 |
127 void OnBrowsingDataRemoverDone() override { run_loop_.Quit(); } | 128 void OnBrowsingDataRemoverDone() override { run_loop_.Quit(); } |
128 | 129 |
129 void Wait() { run_loop_.Run(); } | 130 void Wait() { run_loop_.Run(); } |
130 | 131 |
131 private: | 132 private: |
132 BrowsingDataRemover* remover_; | 133 content::BrowsingDataRemover* remover_; |
133 base::RunLoop run_loop_; | 134 base::RunLoop run_loop_; |
134 | 135 |
135 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverObserver); | 136 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverObserver); |
136 }; | 137 }; |
137 | 138 |
138 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; | 139 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
139 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 140 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
140 | 141 |
141 void RemoveDuplicateSubresources(std::vector<URLRequestSummary>* subresources) { | 142 void RemoveDuplicateSubresources(std::vector<URLRequestSummary>* subresources) { |
142 std::stable_sort(subresources->begin(), subresources->end(), | 143 std::stable_sort(subresources->begin(), subresources->end(), |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 for (const auto& edge : redirect_chain) { | 466 for (const auto& edge : redirect_chain) { |
466 auto result = redirects_.insert(std::make_pair(current, edge)); | 467 auto result = redirects_.insert(std::make_pair(current, edge)); |
467 EXPECT_TRUE(result.second) << current << " already has a redirect."; | 468 EXPECT_TRUE(result.second) << current << " already has a redirect."; |
468 current = edge.url; | 469 current = edge.url; |
469 } | 470 } |
470 } | 471 } |
471 | 472 |
472 void ClearResources() { resources_.clear(); } | 473 void ClearResources() { resources_.clear(); } |
473 | 474 |
474 void ClearCache() { | 475 void ClearCache() { |
475 BrowsingDataRemover* remover = | 476 content::BrowsingDataRemover* remover = |
476 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 477 content::BrowserContext::GetBrowsingDataRemover(browser()->profile()); |
477 BrowsingDataRemoverObserver observer(remover); | 478 BrowsingDataRemoverObserver observer(remover); |
478 remover->RemoveAndReply( | 479 remover->RemoveAndReply( |
479 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_CACHE, | 480 base::Time(), base::Time::Max(), |
480 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &observer); | 481 content::BrowsingDataRemover::DATA_TYPE_CACHE, |
| 482 content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &observer); |
481 observer.Wait(); | 483 observer.Wait(); |
482 | 484 |
483 for (auto& kv : resources_) | 485 for (auto& kv : resources_) |
484 kv.second.request.was_cached = false; | 486 kv.second.request.was_cached = false; |
485 } | 487 } |
486 | 488 |
487 // Shortcut for convenience. | 489 // Shortcut for convenience. |
488 GURL GetURL(const std::string& path) const { | 490 GURL GetURL(const std::string& path) const { |
489 return embedded_test_server()->GetURL(path); | 491 return embedded_test_server()->GetURL(path); |
490 } | 492 } |
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 net::HIGHEST); | 980 net::HIGHEST); |
979 | 981 |
980 NavigateToURLAndCheckSubresources(initial_url); | 982 NavigateToURLAndCheckSubresources(initial_url); |
981 ClearCache(); | 983 ClearCache(); |
982 NavigateToURLAndCheckSubresources(initial_url); | 984 NavigateToURLAndCheckSubresources(initial_url); |
983 ClearCache(); | 985 ClearCache(); |
984 NavigateToURLAndCheckPrefetching(initial_url); | 986 NavigateToURLAndCheckPrefetching(initial_url); |
985 } | 987 } |
986 | 988 |
987 } // namespace predictors | 989 } // namespace predictors |
OLD | NEW |