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
3 // found in the LICENSE file.
6 #include "base/strings/stringprintf.h"
7 #include "content/browser/frame_host/navigation_controller_impl.h"
8 #include "content/browser/frame_host/navigation_entry_impl.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/test/browser_test_utils.h"
11 #include "content/public/test/content_browser_test.h"
12 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/shell/browser/shell.h"
17 class NavigationControllerBrowserTest
: public ContentBrowserTest
{
20 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest
, LoadDataWithBaseURL
) {
21 const GURL
base_url("http://baseurl");
22 const GURL
history_url("http://historyurl");
23 const std::string data
= "<html><body>foo</body></html>";
25 const NavigationController
& controller
=
26 shell()->web_contents()->GetController();
27 // Load data. Blocks until it is done.
28 content::LoadDataWithBaseURL(shell(), history_url
, data
, base_url
);
30 // We should use history_url instead of the base_url as the original url of
31 // this navigation entry, because base_url is only used for resolving relative
32 // paths in the data, or enforcing same origin policy.
33 EXPECT_EQ(controller
.GetVisibleEntry()->GetOriginalRequestURL(), history_url
);
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();
46 const int kMaxEntryCount
=
47 static_cast<int>(NavigationControllerImpl::max_entry_count());
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
));
55 EXPECT_EQ(controller
.GetEntryCount(), kMaxEntryCount
);
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
));
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());
69 // Now try to go back. This should not hang.
70 ASSERT_TRUE(controller
.CanGoBack());
72 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
74 // This should have successfully gone back.
75 EXPECT_EQ(GURL(base::StringPrintf("data:text/html,page%d", kMaxEntryCount
)),
76 controller
.GetLastCommittedEntry()->GetURL());
79 } // namespace content