OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
32 #include "chrome/common/prerender_types.h" | 32 #include "chrome/common/prerender_types.h" |
33 #include "chrome/test/base/testing_browser_process.h" | 33 #include "chrome/test/base/testing_browser_process.h" |
34 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
35 #include "components/content_settings/core/common/pref_names.h" | 35 #include "components/content_settings/core/common/pref_names.h" |
36 #include "components/prefs/pref_service.h" | 36 #include "components/prefs/pref_service.h" |
37 #include "components/variations/variations_associated_data.h" | 37 #include "components/variations/variations_associated_data.h" |
38 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
39 #include "content/public/test/test_browser_thread.h" | 39 #include "content/public/test/test_browser_thread.h" |
40 #include "net/base/network_change_notifier.h" | 40 #include "net/base/network_change_notifier.h" |
| 41 #include "net/http/http_cache.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 42 #include "testing/gtest/include/gtest/gtest.h" |
42 #include "ui/gfx/geometry/rect.h" | 43 #include "ui/gfx/geometry/rect.h" |
43 #include "ui/gfx/geometry/size.h" | 44 #include "ui/gfx/geometry/size.h" |
44 #include "url/gurl.h" | 45 #include "url/gurl.h" |
45 | 46 |
46 using base::Time; | 47 using base::Time; |
47 using base::TimeDelta; | 48 using base::TimeDelta; |
48 using base::TimeTicks; | 49 using base::TimeTicks; |
49 using content::BrowserThread; | 50 using content::BrowserThread; |
50 using content::Referrer; | 51 using content::Referrer; |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 | 775 |
775 GURL second_url("http://example2.com"); | 776 GURL second_url("http://example2.com"); |
776 DummyPrerenderContents* second_prerender_contents = | 777 DummyPrerenderContents* second_prerender_contents = |
777 prerender_manager()->CreateNextPrerenderContents( | 778 prerender_manager()->CreateNextPrerenderContents( |
778 second_url, FINAL_STATUS_MANAGER_SHUTDOWN); | 779 second_url, FINAL_STATUS_MANAGER_SHUTDOWN); |
779 EXPECT_TRUE(AddSimplePrerender(second_url)); | 780 EXPECT_TRUE(AddSimplePrerender(second_url)); |
780 EXPECT_EQ(second_prerender_contents, | 781 EXPECT_EQ(second_prerender_contents, |
781 prerender_manager()->FindEntry(second_url)); | 782 prerender_manager()->FindEntry(second_url)); |
782 } | 783 } |
783 | 784 |
| 785 // Prefetching the same URL twice during |time_to_live| results in a duplicate |
| 786 // and is aborted. |
| 787 TEST_F(PrerenderTest, NoStatePrefetchDuplicate) { |
| 788 const GURL kUrl("http://www.google.com/"); |
| 789 |
| 790 RestorePrerenderMode restore_prerender_mode; |
| 791 prerender_manager()->SetMode( |
| 792 PrerenderManager::PRERENDER_MODE_NOSTATE_PREFETCH); |
| 793 base::SimpleTestTickClock* tick_clock = |
| 794 OverridePrerenderManagerTimeTicks(prerender_manager()); |
| 795 |
| 796 // Prefetch the url once. |
| 797 prerender_manager()->CreateNextPrerenderContents( |
| 798 kUrl, ORIGIN_OMNIBOX, FINAL_STATUS_MANAGER_SHUTDOWN); |
| 799 EXPECT_TRUE( |
| 800 prerender_manager()->AddPrerenderFromOmnibox(kUrl, nullptr, gfx::Size())); |
| 801 |
| 802 prerender_manager()->CreateNextPrerenderContents( |
| 803 kUrl, ORIGIN_OMNIBOX, FINAL_STATUS_MANAGER_SHUTDOWN); |
| 804 |
| 805 // Prefetching again before time_to_live aborts, because it is a duplicate. |
| 806 tick_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 807 EXPECT_FALSE( |
| 808 prerender_manager()->AddPrerenderFromOmnibox(kUrl, nullptr, gfx::Size())); |
| 809 |
| 810 // Prefetching after time_to_live succeeds. |
| 811 tick_clock->Advance( |
| 812 base::TimeDelta::FromMinutes(net::HttpCache::kPrefetchReuseMins)); |
| 813 EXPECT_TRUE( |
| 814 prerender_manager()->AddPrerenderFromOmnibox(kUrl, nullptr, gfx::Size())); |
| 815 } |
784 | 816 |
785 // Make sure that if we prerender more requests than we support, that we launch | 817 // 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 | 818 // 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 | 819 // 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. | 820 // are enforced for the system as a whole and on a per launcher basis. |
789 TEST_F(PrerenderTest, MaxConcurrencyTest) { | 821 TEST_F(PrerenderTest, MaxConcurrencyTest) { |
790 struct TestConcurrency { | 822 struct TestConcurrency { |
791 size_t max_link_concurrency; | 823 size_t max_link_concurrency; |
792 size_t max_link_concurrency_per_launcher; | 824 size_t max_link_concurrency_per_launcher; |
793 }; | 825 }; |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 prerender_contents->SetPrerenderMode(PREFETCH_ONLY); | 1948 prerender_contents->SetPrerenderMode(PREFETCH_ONLY); |
1917 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("GET")); | 1949 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("GET")); |
1918 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("HEAD")); | 1950 EXPECT_TRUE(prerender_contents->IsValidHttpMethod("HEAD")); |
1919 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("OPTIONS")); | 1951 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("OPTIONS")); |
1920 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("POST")); | 1952 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("POST")); |
1921 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("TRACE")); | 1953 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("TRACE")); |
1922 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("WHATEVER")); | 1954 EXPECT_FALSE(prerender_contents->IsValidHttpMethod("WHATEVER")); |
1923 } | 1955 } |
1924 | 1956 |
1925 } // namespace prerender | 1957 } // namespace prerender |
OLD | NEW |