| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/strings/stringprintf.h" |
| 6 #include "content/browser/frame_host/navigation_controller_impl.h" | 7 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 7 #include "content/browser/frame_host/navigation_entry_impl.h" | 8 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 8 #include "content/public/browser/web_contents.h" | 9 #include "content/public/browser/web_contents.h" |
| 10 #include "content/public/test/browser_test_utils.h" |
| 9 #include "content/public/test/content_browser_test.h" | 11 #include "content/public/test/content_browser_test.h" |
| 10 #include "content/public/test/content_browser_test_utils.h" | 12 #include "content/public/test/content_browser_test_utils.h" |
| 11 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
| 12 | 14 |
| 13 namespace content { | 15 namespace content { |
| 14 | 16 |
| 15 class NavigationControllerBrowserTest : public ContentBrowserTest { | 17 class NavigationControllerBrowserTest : public ContentBrowserTest { |
| 16 }; | 18 }; |
| 17 | 19 |
| 18 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { | 20 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, LoadDataWithBaseURL) { |
| 19 const GURL base_url("http://baseurl"); | 21 const GURL base_url("http://baseurl"); |
| 20 const GURL history_url("http://historyurl"); | 22 const GURL history_url("http://historyurl"); |
| 21 const std::string data = "<html><body>foo</body></html>"; | 23 const std::string data = "<html><body>foo</body></html>"; |
| 22 | 24 |
| 23 const NavigationController& controller = | 25 const NavigationController& controller = |
| 24 shell()->web_contents()->GetController(); | 26 shell()->web_contents()->GetController(); |
| 25 // load data. Blocks until it is done. | 27 // Load data. Blocks until it is done. |
| 26 content::LoadDataWithBaseURL(shell(), history_url, data, base_url); | 28 content::LoadDataWithBaseURL(shell(), history_url, data, base_url); |
| 27 | 29 |
| 28 // We should use history_url instead of the base_url as the original url of | 30 // We should use history_url instead of the base_url as the original url of |
| 29 // this navigation entry, because base_url is only used for resolving relative | 31 // this navigation entry, because base_url is only used for resolving relative |
| 30 // paths in the data, or enforcing same origin policy. | 32 // paths in the data, or enforcing same origin policy. |
| 31 EXPECT_EQ(controller.GetVisibleEntry()->GetOriginalRequestURL(), history_url); | 33 EXPECT_EQ(controller.GetVisibleEntry()->GetOriginalRequestURL(), history_url); |
| 32 } | 34 } |
| 35 |
| 36 // The renderer uses the position in the history list as a clue to whether a |
| 37 // navigation is stale. In the case where the entry limit is reached and the |
| 38 // history list is pruned, make sure that there is no mismatch that would cause |
| 39 // it to start incorrectly rejecting navigations as stale. See |
| 40 // http://crbug.com/89798. |
| 41 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 42 DontIgnoreBackAfterNavEntryLimit) { |
| 43 NavigationController& controller = |
| 44 shell()->web_contents()->GetController(); |
| 45 |
| 46 const int kMaxEntryCount = |
| 47 static_cast<int>(NavigationControllerImpl::max_entry_count()); |
| 48 |
| 49 // Load up to the max count, all entries should be there. |
| 50 for (int url_index = 0; url_index < kMaxEntryCount; ++url_index) { |
| 51 GURL url(base::StringPrintf("data:text/html,page%d", url_index)); |
| 52 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 53 } |
| 54 |
| 55 EXPECT_EQ(controller.GetEntryCount(), kMaxEntryCount); |
| 56 |
| 57 // Navigate twice more more. |
| 58 for (int url_index = kMaxEntryCount; |
| 59 url_index < kMaxEntryCount + 2; ++url_index) { |
| 60 GURL url(base::StringPrintf("data:text/html,page%d", url_index)); |
| 61 EXPECT_TRUE(NavigateToURL(shell(), url)); |
| 62 } |
| 63 |
| 64 // We expect http://www.a.com/0 and /1 to be gone. |
| 65 EXPECT_EQ(kMaxEntryCount, controller.GetEntryCount()); |
| 66 EXPECT_EQ(GURL("data:text/html,page2"), |
| 67 controller.GetEntryAtIndex(0)->GetURL()); |
| 68 |
| 69 // Now try to go back. This should not hang. |
| 70 ASSERT_TRUE(controller.CanGoBack()); |
| 71 controller.GoBack(); |
| 72 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 73 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount)), |
| 74 controller.GetLastCommittedEntry()->GetURL()); |
| 75 } |
| 76 |
| 33 } // namespace content | 77 } // namespace content |
| 34 | 78 |
| OLD | NEW |