| 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 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 15 |
| 16 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | |
| 17 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" | 16 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
| 18 #include "chrome/browser/predictors/resource_prefetch_predictor.h" | 17 #include "chrome/browser/predictors/resource_prefetch_predictor.h" |
| 19 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" | 18 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" |
| 20 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" | 19 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 24 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 24 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/ui_test_utils.h" | 25 #include "chrome/test/base/ui_test_utils.h" |
| 26 #include "content/public/browser/browsing_data_remover.h" |
| 27 #include "net/base/host_port_pair.h" | 27 #include "net/base/host_port_pair.h" |
| 28 #include "net/base/url_util.h" | 28 #include "net/base/url_util.h" |
| 29 #include "net/dns/mock_host_resolver.h" | 29 #include "net/dns/mock_host_resolver.h" |
| 30 #include "net/test/embedded_test_server/http_request.h" | 30 #include "net/test/embedded_test_server/http_request.h" |
| 31 #include "net/test/embedded_test_server/http_response.h" | 31 #include "net/test/embedded_test_server/http_response.h" |
| 32 #include "net/test/embedded_test_server/request_handler_util.h" | 32 #include "net/test/embedded_test_server/request_handler_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" | 33 #include "testing/gmock/include/gmock/gmock.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 35 |
| 36 namespace predictors { | 36 namespace predictors { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 void OnPredictorInitialized() override { run_loop_.Quit(); } | 119 void OnPredictorInitialized() override { run_loop_.Quit(); } |
| 120 | 120 |
| 121 void Wait() { run_loop_.Run(); } | 121 void Wait() { run_loop_.Run(); } |
| 122 | 122 |
| 123 private: | 123 private: |
| 124 base::RunLoop run_loop_; | 124 base::RunLoop run_loop_; |
| 125 | 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(InitializationObserver); | 126 DISALLOW_COPY_AND_ASSIGN(InitializationObserver); |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 class BrowsingDataRemoverObserver : public BrowsingDataRemover::Observer { | 129 class BrowsingDataRemoverObserver |
| 130 : public content::BrowsingDataRemover::Observer { |
| 130 public: | 131 public: |
| 131 explicit BrowsingDataRemoverObserver(BrowsingDataRemover* remover) | 132 explicit BrowsingDataRemoverObserver(content::BrowsingDataRemover* remover) |
| 132 : remover_(remover) { | 133 : remover_(remover) { |
| 133 remover_->AddObserver(this); | 134 remover_->AddObserver(this); |
| 134 } | 135 } |
| 135 ~BrowsingDataRemoverObserver() override { remover_->RemoveObserver(this); } | 136 ~BrowsingDataRemoverObserver() override { remover_->RemoveObserver(this); } |
| 136 | 137 |
| 137 void OnBrowsingDataRemoverDone() override { run_loop_.Quit(); } | 138 void OnBrowsingDataRemoverDone() override { run_loop_.Quit(); } |
| 138 | 139 |
| 139 void Wait() { run_loop_.Run(); } | 140 void Wait() { run_loop_.Run(); } |
| 140 | 141 |
| 141 private: | 142 private: |
| 142 BrowsingDataRemover* remover_; | 143 content::BrowsingDataRemover* remover_; |
| 143 base::RunLoop run_loop_; | 144 base::RunLoop run_loop_; |
| 144 | 145 |
| 145 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverObserver); | 146 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverObserver); |
| 146 }; | 147 }; |
| 147 | 148 |
| 148 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; | 149 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; |
| 149 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; | 150 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; |
| 150 | 151 |
| 151 void RemoveDuplicateSubresources(std::vector<URLRequestSummary>* subresources) { | 152 void RemoveDuplicateSubresources(std::vector<URLRequestSummary>* subresources) { |
| 152 std::stable_sort(subresources->begin(), subresources->end(), | 153 std::stable_sort(subresources->begin(), subresources->end(), |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 for (const auto& edge : redirect_chain) { | 485 for (const auto& edge : redirect_chain) { |
| 485 auto result = redirects_.insert(std::make_pair(current, edge)); | 486 auto result = redirects_.insert(std::make_pair(current, edge)); |
| 486 EXPECT_TRUE(result.second) << current << " already has a redirect."; | 487 EXPECT_TRUE(result.second) << current << " already has a redirect."; |
| 487 current = edge.url; | 488 current = edge.url; |
| 488 } | 489 } |
| 489 } | 490 } |
| 490 | 491 |
| 491 void ClearResources() { resources_.clear(); } | 492 void ClearResources() { resources_.clear(); } |
| 492 | 493 |
| 493 void ClearCache() { | 494 void ClearCache() { |
| 494 BrowsingDataRemover* remover = | 495 content::BrowsingDataRemover* remover = |
| 495 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile()); | 496 content::BrowserContext::GetBrowsingDataRemover(browser()->profile()); |
| 496 BrowsingDataRemoverObserver observer(remover); | 497 BrowsingDataRemoverObserver observer(remover); |
| 497 remover->RemoveAndReply( | 498 remover->RemoveAndReply( |
| 498 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_CACHE, | 499 base::Time(), base::Time::Max(), |
| 499 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &observer); | 500 content::BrowsingDataRemover::DATA_TYPE_CACHE, |
| 501 content::BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &observer); |
| 500 observer.Wait(); | 502 observer.Wait(); |
| 501 | 503 |
| 502 for (auto& kv : resources_) | 504 for (auto& kv : resources_) |
| 503 kv.second.request.was_cached = false; | 505 kv.second.request.was_cached = false; |
| 504 } | 506 } |
| 505 | 507 |
| 506 // Shortcuts for convenience. | 508 // Shortcuts for convenience. |
| 507 GURL GetURL(const std::string& path) const { | 509 GURL GetURL(const std::string& path) const { |
| 508 return embedded_test_server()->GetURL(path); | 510 return embedded_test_server()->GetURL(path); |
| 509 } | 511 } |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 AddResourcesFromSubresourceHtml(); | 964 AddResourcesFromSubresourceHtml(); |
| 963 | 965 |
| 964 NavigateToURLAndCheckSubresources(initial_url); | 966 NavigateToURLAndCheckSubresources(initial_url); |
| 965 ClearCache(); | 967 ClearCache(); |
| 966 NavigateToURLAndCheckSubresources(initial_url); | 968 NavigateToURLAndCheckSubresources(initial_url); |
| 967 ClearCache(); | 969 ClearCache(); |
| 968 NavigateToURLAndCheckPrefetching(initial_url); | 970 NavigateToURLAndCheckPrefetching(initial_url); |
| 969 } | 971 } |
| 970 | 972 |
| 971 } // namespace predictors | 973 } // namespace predictors |
| OLD | NEW |