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

Side by Side Diff: chrome/browser/prerender/prerender_unittest.cc

Issue 2614473002: [NoStatePrefetch] Cancel repeated prefetches with FINAL_STATUS_DUPLICATE (Closed)
Patch Set: more comments Created 3 years, 11 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 774
775 GURL second_url("http://example2.com"); 775 GURL second_url("http://example2.com");
776 DummyPrerenderContents* second_prerender_contents = 776 DummyPrerenderContents* second_prerender_contents =
777 prerender_manager()->CreateNextPrerenderContents( 777 prerender_manager()->CreateNextPrerenderContents(
778 second_url, FINAL_STATUS_MANAGER_SHUTDOWN); 778 second_url, FINAL_STATUS_MANAGER_SHUTDOWN);
779 EXPECT_TRUE(AddSimplePrerender(second_url)); 779 EXPECT_TRUE(AddSimplePrerender(second_url));
780 EXPECT_EQ(second_prerender_contents, 780 EXPECT_EQ(second_prerender_contents,
781 prerender_manager()->FindEntry(second_url)); 781 prerender_manager()->FindEntry(second_url));
782 } 782 }
783 783
784 // Prefetching the same URL twice during |time_to_live| results in a duplicate
785 // and is aborted.
786 TEST_F(PrerenderTest, NoStatePrefetchDuplicate) {
787 const GURL kUrl("http://www.google.com/");
788 const TimeDelta kTimeToLive = TimeDelta::FromSeconds(300);
789 const TimeDelta kTestAdvance = TimeDelta::FromSeconds(100);
790
791 RestorePrerenderMode restore_prerender_mode;
792 prerender_manager()->SetMode(
793 PrerenderManager::PRERENDER_MODE_NOSTATE_PREFETCH);
794 base::SimpleTestTickClock* tick_clock =
795 OverridePrerenderManagerTimeTicks(prerender_manager());
796 prerender_manager()->mutable_config().time_to_live = kTimeToLive;
797
798 // Prefetch the url once.
799 prerender_manager()->CreateNextPrerenderContents(
800 kUrl, ORIGIN_OMNIBOX, FINAL_STATUS_MANAGER_SHUTDOWN);
801 EXPECT_TRUE(
802 prerender_manager()->AddPrerenderFromOmnibox(kUrl, nullptr, gfx::Size()));
803
804 prerender_manager()->CreateNextPrerenderContents(
805 kUrl, ORIGIN_OMNIBOX, FINAL_STATUS_MANAGER_SHUTDOWN);
806
807 // Prefetching again before time_to_live aborts, because it is a duplicate.
808 tick_clock->Advance(kTestAdvance);
809 EXPECT_FALSE(
810 prerender_manager()->AddPrerenderFromOmnibox(kUrl, nullptr, gfx::Size()));
811
812 // Prefetching after time_to_live succeeds.
813 tick_clock->Advance(prerender_manager()->config().time_to_live);
814 EXPECT_TRUE(
815 prerender_manager()->AddPrerenderFromOmnibox(kUrl, nullptr, gfx::Size()));
816 }
784 817
785 // Make sure that if we prerender more requests than we support, that we launch 818 // Make sure that if we prerender more requests than we support, that we launch
786 // them in the order given up until we reach MaxConcurrency, at which point we 819 // them in the order given up until we reach MaxConcurrency, at which point we
787 // queue them and launch them in the order given. As well, insure that limits 820 // queue them and launch them in the order given. As well, insure that limits
788 // are enforced for the system as a whole and on a per launcher basis. 821 // are enforced for the system as a whole and on a per launcher basis.
789 TEST_F(PrerenderTest, MaxConcurrencyTest) { 822 TEST_F(PrerenderTest, MaxConcurrencyTest) {
790 struct TestConcurrency { 823 struct TestConcurrency {
791 size_t max_link_concurrency; 824 size_t max_link_concurrency;
792 size_t max_link_concurrency_per_launcher; 825 size_t max_link_concurrency_per_launcher;
793 }; 826 };
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 prerender_contents->SetPrerenderMode(PREFETCH_ONLY); 1949 prerender_contents->SetPrerenderMode(PREFETCH_ONLY);
1917 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("GET")); 1950 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("GET"));
1918 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("HEAD")); 1951 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("HEAD"));
1919 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("OPTIONS")); 1952 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("OPTIONS"));
1920 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("POST")); 1953 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("POST"));
1921 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("TRACE")); 1954 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("TRACE"));
1922 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("WHATEVER")); 1955 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("WHATEVER"));
1923 } 1956 }
1924 1957
1925 } // namespace prerender 1958 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698