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

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

Issue 2928033003: predictors: move ResourcePrefetcher handling to LoadingPredictor. (Closed)
Patch Set: Comments. Created 3 years, 5 months 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
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 <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"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 bool match_navigation_id_; 281 bool match_navigation_id_;
282 bool match_before_first_contentful_paint_; 282 bool match_before_first_contentful_paint_;
283 std::set<NavigationID> current_navigation_ids_; 283 std::set<NavigationID> current_navigation_ids_;
284 284
285 DISALLOW_COPY_AND_ASSIGN(LearningObserver); 285 DISALLOW_COPY_AND_ASSIGN(LearningObserver);
286 }; 286 };
287 287
288 // Helper class to track and allow waiting for a single OnPrefetchingFinished 288 // Helper class to track and allow waiting for a single OnPrefetchingFinished
289 // event. Checks also that {Start,Stop}Prefetching are called with the right 289 // event. Checks also that {Start,Stop}Prefetching are called with the right
290 // argument. 290 // argument.
291 class PrefetchingObserver : public TestObserver { 291 class PrefetchingObserver : public TestLoadingObserver {
292 public: 292 public:
293 PrefetchingObserver(ResourcePrefetchPredictor* predictor, 293 PrefetchingObserver(LoadingPredictor* predictor,
294 const GURL& expected_main_frame_url, 294 const GURL& expected_main_frame_url)
295 bool is_learning_allowed) 295 : TestLoadingObserver(predictor),
296 : TestObserver(predictor), 296 main_frame_url_(expected_main_frame_url) {}
297 main_frame_url_(expected_main_frame_url),
298 is_learning_allowed_(is_learning_allowed) {}
299 297
300 // TestObserver: 298 // LoadingTestObserver:
301 void OnNavigationLearned(size_t url_visit_count,
alexilin 2017/07/03 14:55:02 It's not really good that we throw this check away
Benoit L 2017/07/03 15:43:15 Done.
302 const PageRequestSummary& summary) override {
303 if (!is_learning_allowed_)
304 ADD_FAILURE() << "Prefetching shouldn't activate learning";
305 }
306
307 void OnPrefetchingStarted(const GURL& main_frame_url) override { 299 void OnPrefetchingStarted(const GURL& main_frame_url) override {
308 EXPECT_EQ(main_frame_url_, main_frame_url); 300 EXPECT_EQ(main_frame_url_, main_frame_url);
309 } 301 }
310 302
311 void OnPrefetchingStopped(const GURL& main_frame_url) override { 303 void OnPrefetchingStopped(const GURL& main_frame_url) override {
312 EXPECT_EQ(main_frame_url_, main_frame_url); 304 EXPECT_EQ(main_frame_url_, main_frame_url);
313 } 305 }
314 306
315 void OnPrefetchingFinished(const GURL& main_frame_url) override { 307 void OnPrefetchingFinished(const GURL& main_frame_url) override {
316 EXPECT_EQ(main_frame_url_, main_frame_url); 308 EXPECT_EQ(main_frame_url_, main_frame_url);
317 run_loop_.Quit(); 309 run_loop_.Quit();
318 } 310 }
319 311
320 void Wait() { run_loop_.Run(); } 312 void Wait() { run_loop_.Run(); }
321 313
322 private: 314 private:
323 base::RunLoop run_loop_; 315 base::RunLoop run_loop_;
324 GURL main_frame_url_; 316 GURL main_frame_url_;
325 bool is_learning_allowed_;
326 317
327 DISALLOW_COPY_AND_ASSIGN(PrefetchingObserver); 318 DISALLOW_COPY_AND_ASSIGN(PrefetchingObserver);
328 }; 319 };
329 320
330 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest { 321 class ResourcePrefetchPredictorBrowserTest : public InProcessBrowserTest {
331 protected: 322 protected:
332 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary; 323 using URLRequestSummary = ResourcePrefetchPredictor::URLRequestSummary;
333 324
334 void SetUpCommandLine(base::CommandLine* command_line) override { 325 void SetUpCommandLine(base::CommandLine* command_line) override {
335 command_line->AppendSwitchASCII("force-fieldtrials", "trial/group"); 326 command_line->AppendSwitchASCII("force-fieldtrials", "trial/group");
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 430
440 for (auto& kv : resources_) { 431 for (auto& kv : resources_) {
441 if (kv.second.is_observable) 432 if (kv.second.is_observable)
442 kv.second.request.was_cached = true; 433 kv.second.request.was_cached = true;
443 } 434 }
444 for (const auto& nav : observer.current_navigation_ids()) 435 for (const auto& nav : observer.current_navigation_ids())
445 navigation_id_history_.insert(nav); 436 navigation_id_history_.insert(nav);
446 } 437 }
447 438
448 void NavigateToURLAndCheckPrefetching(const GURL& main_frame_url) { 439 void NavigateToURLAndCheckPrefetching(const GURL& main_frame_url) {
449 PrefetchingObserver observer(resource_prefetch_predictor_, main_frame_url, 440 PrefetchingObserver observer(predictor_, main_frame_url);
450 true);
451 ui_test_utils::NavigateToURL(browser(), main_frame_url); 441 ui_test_utils::NavigateToURL(browser(), main_frame_url);
452 observer.Wait(); 442 observer.Wait();
453 for (auto& kv : resources_) { 443 for (auto& kv : resources_) {
454 if (kv.second.is_observable) 444 if (kv.second.is_observable)
455 kv.second.request.was_cached = true; 445 kv.second.request.was_cached = true;
456 } 446 }
457 } 447 }
458 448
459 void PrefetchURL(const GURL& main_frame_url) { 449 void PrefetchURL(const GURL& main_frame_url) {
460 PrefetchingObserver observer(resource_prefetch_predictor_, main_frame_url, 450 PrefetchingObserver observer(predictor_, main_frame_url);
461 false);
462 predictor_->PrepareForPageLoad(main_frame_url, HintOrigin::EXTERNAL); 451 predictor_->PrepareForPageLoad(main_frame_url, HintOrigin::EXTERNAL);
463 observer.Wait(); 452 observer.Wait();
464 for (auto& kv : resources_) { 453 for (auto& kv : resources_) {
465 if (kv.second.is_observable) 454 if (kv.second.is_observable)
466 kv.second.request.was_cached = true; 455 kv.second.request.was_cached = true;
467 } 456 }
468 } 457 }
469 458
470 void TryToPrefetchURL(const GURL& main_frame_url) { 459 void TryToPrefetchURL(const GURL& main_frame_url) {
471 predictor_->PrepareForPageLoad(main_frame_url, HintOrigin::EXTERNAL); 460 predictor_->PrepareForPageLoad(main_frame_url, HintOrigin::EXTERNAL);
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 AddResourcesFromSubresourceHtml(); 998 AddResourcesFromSubresourceHtml();
1010 999
1011 NavigateToURLAndCheckSubresources(initial_url); 1000 NavigateToURLAndCheckSubresources(initial_url);
1012 ClearCache(); 1001 ClearCache();
1013 NavigateToURLAndCheckSubresources(initial_url); 1002 NavigateToURLAndCheckSubresources(initial_url);
1014 ClearCache(); 1003 ClearCache();
1015 NavigateToURLAndCheckPrefetching(initial_url); 1004 NavigateToURLAndCheckPrefetching(initial_url);
1016 } 1005 }
1017 1006
1018 } // namespace predictors 1007 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698