Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: chrome/browser/predictors/resource_prefetch_predictor_browsertest.cc

Issue 2596893002: predictors: Wait for the cache cleaning synchronously. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "chrome/browser/browsing_data/browsing_data_helper.h"
7 #include "chrome/browser/browsing_data/browsing_data_remover.h"
8 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
6 #include "chrome/browser/predictors/resource_prefetch_predictor.h" 9 #include "chrome/browser/predictors/resource_prefetch_predictor.h"
7 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h" 10 #include "chrome/browser/predictors/resource_prefetch_predictor_factory.h"
8 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h" 11 #include "chrome/browser/predictors/resource_prefetch_predictor_test_util.h"
9 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
14 #include "chrome/test/base/in_process_browser_test.h" 16 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
16 #include "content/public/browser/render_frame_host.h" 18 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/render_process_host.h" 19 #include "content/public/browser/render_process_host.h"
18 #include "net/test/embedded_test_server/http_request.h" 20 #include "net/test/embedded_test_server/http_request.h"
19 #include "net/test/embedded_test_server/http_response.h" 21 #include "net/test/embedded_test_server/http_response.h"
20 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 void OnPredictorInitialized() override { run_loop_.Quit(); } 87 void OnPredictorInitialized() override { run_loop_.Quit(); }
86 88
87 void Wait() { run_loop_.Run(); } 89 void Wait() { run_loop_.Run(); }
88 90
89 private: 91 private:
90 base::RunLoop run_loop_; 92 base::RunLoop run_loop_;
91 93
92 DISALLOW_COPY_AND_ASSIGN(InitializationObserver); 94 DISALLOW_COPY_AND_ASSIGN(InitializationObserver);
93 }; 95 };
94 96
97 class BrowsingDataRemoverObserver : public BrowsingDataRemover::Observer {
98 public:
99 explicit BrowsingDataRemoverObserver(BrowsingDataRemover* remover)
100 : remover_(remover) {
101 remover_->AddObserver(this);
102 }
103 ~BrowsingDataRemoverObserver() override { remover_->RemoveObserver(this); }
104
105 void OnBrowsingDataRemoverDone() override { run_loop_.Quit(); }
106
107 void Wait() { run_loop_.Run(); }
108
109 private:
110 BrowsingDataRemover* remover_;
111 base::RunLoop run_loop_;
112
113 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverObserver);
114 };
115
95 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary; 116 using PageRequestSummary = ResourcePrefetchPredictor::PageRequestSummary;
96 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; 117 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
97 118
98 void RemoveDuplicateSubresources(std::vector<URLRequestSummary>* subresources) { 119 void RemoveDuplicateSubresources(std::vector<URLRequestSummary>* subresources) {
99 std::stable_sort(subresources->begin(), subresources->end(), 120 std::stable_sort(subresources->begin(), subresources->end(),
100 [](const URLRequestSummary& x, const URLRequestSummary& y) { 121 [](const URLRequestSummary& x, const URLRequestSummary& y) {
101 return x.resource_url < y.resource_url; 122 return x.resource_url < y.resource_url;
102 }); 123 });
103 subresources->erase( 124 subresources->erase(
104 std::unique(subresources->begin(), subresources->end(), 125 std::unique(subresources->begin(), subresources->end(),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 DISALLOW_COPY_AND_ASSIGN(PrefetchingObserver); 236 DISALLOW_COPY_AND_ASSIGN(PrefetchingObserver);
216 }; 237 };
217 238
218 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { 239 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest {
219 protected: 240 protected:
220 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; 241 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
221 242
222 void SetUpCommandLine(base::CommandLine* command_line) override { 243 void SetUpCommandLine(base::CommandLine* command_line) override {
223 command_line->AppendSwitchASCII( 244 command_line->AppendSwitchASCII(
224 switches::kSpeculativeResourcePrefetching, 245 switches::kSpeculativeResourcePrefetching,
225 switches::kSpeculativeResourcePrefetchingEnabled); 246 switches::kSpeculativeResourcePrefetchingEnabledExternal);
226 } 247 }
227 248
228 void SetUpOnMainThread() override { 249 void SetUpOnMainThread() override {
229 embedded_test_server()->RegisterRequestHandler( 250 embedded_test_server()->RegisterRequestHandler(
230 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest, 251 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleRedirectRequest,
231 base::Unretained(this))); 252 base::Unretained(this)));
232 embedded_test_server()->RegisterRequestHandler( 253 embedded_test_server()->RegisterRequestHandler(
233 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest, 254 base::Bind(&ResourcePrefetchPredictorBrowserTest::HandleResourceRequest,
234 base::Unretained(this))); 255 base::Unretained(this)));
235 ASSERT_TRUE(embedded_test_server()->Start()); 256 ASSERT_TRUE(embedded_test_server()->Start());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 ASSERT_FALSE(redirect_chain.empty()); 346 ASSERT_FALSE(redirect_chain.empty());
326 GURL current = initial_url; 347 GURL current = initial_url;
327 for (const auto& edge : redirect_chain) { 348 for (const auto& edge : redirect_chain) {
328 auto result = redirects_.insert(std::make_pair(current, edge)); 349 auto result = redirects_.insert(std::make_pair(current, edge));
329 EXPECT_TRUE(result.second) << current << " already has a redirect."; 350 EXPECT_TRUE(result.second) << current << " already has a redirect.";
330 current = edge.url; 351 current = edge.url;
331 } 352 }
332 } 353 }
333 354
334 void ClearCache() { 355 void ClearCache() {
335 chrome::ClearCache(browser()); 356 BrowsingDataRemover* remover =
357 BrowsingDataRemoverFactory::GetForBrowserContext(browser()->profile());
358 BrowsingDataRemoverObserver observer(remover);
359 remover->RemoveAndReply(BrowsingDataRemover::Unbounded(),
360 BrowsingDataRemover::REMOVE_CACHE,
361 BrowsingDataHelper::UNPROTECTED_WEB, &observer);
362 observer.Wait();
363
336 for (auto& kv : resources_) 364 for (auto& kv : resources_)
337 kv.second.request.was_cached = false; 365 kv.second.request.was_cached = false;
338 } 366 }
339 367
340 // Shortcut for convenience. 368 // Shortcut for convenience.
341 GURL GetURL(const std::string& path) const { 369 GURL GetURL(const std::string& path) const {
342 return embedded_test_server()->GetURL(path); 370 return embedded_test_server()->GetURL(path);
343 } 371 }
344 372
345 void EnableHttpsServer() { 373 void EnableHttpsServer() {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET, 613 AddResource(GetURL(kStylePath2), content::RESOURCE_TYPE_STYLESHEET,
586 net::HIGHEST); 614 net::HIGHEST);
587 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM); 615 AddResource(GetURL(kScriptPath2), content::RESOURCE_TYPE_SCRIPT, net::MEDIUM);
588 // Included from <iframe src="html_subresources.html"> and not recored. 616 // Included from <iframe src="html_subresources.html"> and not recored.
589 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath), 617 AddUnrecordedResources({GetURL(kImagePath), GetURL(kStylePath),
590 GetURL(kScriptPath), GetURL(kFontPath)}); 618 GetURL(kScriptPath), GetURL(kFontPath)});
591 TestLearningAndPrefetching(GetURL(kHtmlIframePath)); 619 TestLearningAndPrefetching(GetURL(kHtmlIframePath));
592 } 620 }
593 621
594 } // namespace predictors 622 } // namespace predictors
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698