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

Side by Side Diff: content/browser/tab_contents/navigation_controller_unittest.cc

Issue 8983010: Convert WebContents to return a content::NavigationController instead of the implementation. Upda... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 1473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1484 std::vector<NavigationEntry*> entries; 1484 std::vector<NavigationEntry*> entries;
1485 NavigationEntry* entry = NavigationController::CreateNavigationEntry( 1485 NavigationEntry* entry = NavigationController::CreateNavigationEntry(
1486 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, 1486 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false,
1487 std::string(), browser_context()); 1487 std::string(), browser_context());
1488 entry->SetPageID(0); 1488 entry->SetPageID(0);
1489 entry->SetTitle(ASCIIToUTF16("Title")); 1489 entry->SetTitle(ASCIIToUTF16("Title"));
1490 entry->SetContentState("state"); 1490 entry->SetContentState("state");
1491 entries.push_back(entry); 1491 entries.push_back(entry);
1492 TabContents our_contents( 1492 TabContents our_contents(
1493 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); 1493 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL);
1494 NavigationController& our_controller = our_contents.GetController(); 1494 NavigationController& our_controller = our_contents.GetControllerImpl();
1495 our_controller.Restore(0, true, &entries); 1495 our_controller.Restore(0, true, &entries);
1496 ASSERT_EQ(0u, entries.size()); 1496 ASSERT_EQ(0u, entries.size());
1497 1497
1498 // Before navigating to the restored entry, it should have a restore_type 1498 // Before navigating to the restored entry, it should have a restore_type
1499 // and no SiteInstance. 1499 // and no SiteInstance.
1500 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION, 1500 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION,
1501 NavigationEntryImpl::FromNavigationEntry( 1501 NavigationEntryImpl::FromNavigationEntry(
1502 our_controller.GetEntryAtIndex(0))->restore_type()); 1502 our_controller.GetEntryAtIndex(0))->restore_type());
1503 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry( 1503 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry(
1504 our_controller.GetEntryAtIndex(0))->site_instance()); 1504 our_controller.GetEntryAtIndex(0))->site_instance());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1551 std::vector<NavigationEntry*> entries; 1551 std::vector<NavigationEntry*> entries;
1552 NavigationEntry* entry = NavigationController::CreateNavigationEntry( 1552 NavigationEntry* entry = NavigationController::CreateNavigationEntry(
1553 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false, 1553 url, content::Referrer(), content::PAGE_TRANSITION_RELOAD, false,
1554 std::string(), browser_context()); 1554 std::string(), browser_context());
1555 entry->SetPageID(0); 1555 entry->SetPageID(0);
1556 entry->SetTitle(ASCIIToUTF16("Title")); 1556 entry->SetTitle(ASCIIToUTF16("Title"));
1557 entry->SetContentState("state"); 1557 entry->SetContentState("state");
1558 entries.push_back(entry); 1558 entries.push_back(entry);
1559 TabContents our_contents( 1559 TabContents our_contents(
1560 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL); 1560 browser_context(), NULL, MSG_ROUTING_NONE, NULL, NULL);
1561 NavigationController& our_controller = our_contents.GetController(); 1561 NavigationController& our_controller = our_contents.GetControllerImpl();
1562 our_controller.Restore(0, true, &entries); 1562 our_controller.Restore(0, true, &entries);
1563 ASSERT_EQ(0u, entries.size()); 1563 ASSERT_EQ(0u, entries.size());
1564 1564
1565 // Before navigating to the restored entry, it should have a restore_type 1565 // Before navigating to the restored entry, it should have a restore_type
1566 // and no SiteInstance. 1566 // and no SiteInstance.
1567 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION, 1567 EXPECT_EQ(NavigationEntryImpl::RESTORE_LAST_SESSION,
1568 NavigationEntryImpl::FromNavigationEntry( 1568 NavigationEntryImpl::FromNavigationEntry(
1569 our_controller.GetEntryAtIndex(0))->restore_type()); 1569 our_controller.GetEntryAtIndex(0))->restore_type());
1570 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry( 1570 EXPECT_FALSE(NavigationEntryImpl::FromNavigationEntry(
1571 our_controller.GetEntryAtIndex(0))->site_instance()); 1571 our_controller.GetEntryAtIndex(0))->site_instance());
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 // Tests CopyStateFromAndPrune with 2 urls in source, 1 in dest. 2005 // Tests CopyStateFromAndPrune with 2 urls in source, 1 in dest.
2006 TEST_F(NavigationControllerTest, CopyStateFromAndPrune) { 2006 TEST_F(NavigationControllerTest, CopyStateFromAndPrune) {
2007 const GURL url1("http://foo1"); 2007 const GURL url1("http://foo1");
2008 const GURL url2("http://foo2"); 2008 const GURL url2("http://foo2");
2009 const GURL url3("http://foo3"); 2009 const GURL url3("http://foo3");
2010 2010
2011 NavigateAndCommit(url1); 2011 NavigateAndCommit(url1);
2012 NavigateAndCommit(url2); 2012 NavigateAndCommit(url2);
2013 2013
2014 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 2014 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
2015 NavigationController& other_controller = other_contents->GetController(); 2015 NavigationController& other_controller = other_contents->GetControllerImpl();
2016 other_contents->NavigateAndCommit(url3); 2016 other_contents->NavigateAndCommit(url3);
2017 other_contents->ExpectSetHistoryLengthAndPrune( 2017 other_contents->ExpectSetHistoryLengthAndPrune(
2018 NavigationEntryImpl::FromNavigationEntry( 2018 NavigationEntryImpl::FromNavigationEntry(
2019 other_controller.GetEntryAtIndex(0))->site_instance(), 2, 2019 other_controller.GetEntryAtIndex(0))->site_instance(), 2,
2020 other_controller.GetEntryAtIndex(0)->GetPageID()); 2020 other_controller.GetEntryAtIndex(0)->GetPageID());
2021 other_controller.CopyStateFromAndPrune(&controller()); 2021 other_controller.CopyStateFromAndPrune(&controller());
2022 2022
2023 // other_controller should now contain the 3 urls: url1, url2 and url3. 2023 // other_controller should now contain the 3 urls: url1, url2 and url3.
2024 2024
2025 ASSERT_EQ(3, other_controller.GetEntryCount()); 2025 ASSERT_EQ(3, other_controller.GetEntryCount());
(...skipping 10 matching lines...) Expand all
2036 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) { 2036 TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) {
2037 const GURL url1("http://foo1"); 2037 const GURL url1("http://foo1");
2038 const GURL url2("http://foo2"); 2038 const GURL url2("http://foo2");
2039 const GURL url3("http://foo3"); 2039 const GURL url3("http://foo3");
2040 2040
2041 NavigateAndCommit(url1); 2041 NavigateAndCommit(url1);
2042 NavigateAndCommit(url2); 2042 NavigateAndCommit(url2);
2043 controller().GoBack(); 2043 controller().GoBack();
2044 2044
2045 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 2045 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
2046 NavigationController& other_controller = other_contents->GetController(); 2046 NavigationController& other_controller = other_contents->GetControllerImpl();
2047 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); 2047 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
2048 other_controller.CopyStateFromAndPrune(&controller()); 2048 other_controller.CopyStateFromAndPrune(&controller());
2049 2049
2050 // other_controller should now contain the 1 url: url1. 2050 // other_controller should now contain the 1 url: url1.
2051 2051
2052 ASSERT_EQ(1, other_controller.GetEntryCount()); 2052 ASSERT_EQ(1, other_controller.GetEntryCount());
2053 2053
2054 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); 2054 ASSERT_EQ(0, other_controller.GetCurrentEntryIndex());
2055 2055
2056 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 2056 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
2057 } 2057 }
2058 2058
2059 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in 2059 // Test CopyStateFromAndPrune with 2 urls, the first selected and nothing in
2060 // the target. 2060 // the target.
2061 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) { 2061 TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) {
2062 const GURL url1("http://foo1"); 2062 const GURL url1("http://foo1");
2063 const GURL url2("http://foo2"); 2063 const GURL url2("http://foo2");
2064 const GURL url3("http://foo3"); 2064 const GURL url3("http://foo3");
2065 2065
2066 NavigateAndCommit(url1); 2066 NavigateAndCommit(url1);
2067 NavigateAndCommit(url2); 2067 NavigateAndCommit(url2);
2068 controller().GoBack(); 2068 controller().GoBack();
2069 2069
2070 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 2070 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents());
2071 NavigationController& other_controller = other_contents->GetController(); 2071 NavigationController& other_controller = other_contents->GetControllerImpl();
2072 other_controller.LoadURL( 2072 other_controller.LoadURL(
2073 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 2073 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
2074 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1); 2074 other_contents->ExpectSetHistoryLengthAndPrune(NULL, 1, -1);
2075 other_controller.CopyStateFromAndPrune(&controller()); 2075 other_controller.CopyStateFromAndPrune(&controller());
2076 2076
2077 // other_controller should now contain 1 entry for url1, and a pending entry 2077 // other_controller should now contain 1 entry for url1, and a pending entry
2078 // for url3. 2078 // for url3.
2079 2079
2080 ASSERT_EQ(1, other_controller.GetEntryCount()); 2080 ASSERT_EQ(1, other_controller.GetEntryCount());
2081 2081
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 TabNavigation nav(0, url0, GURL(), string16(), 2415 TabNavigation nav(0, url0, GURL(), string16(),
2416 webkit_glue::CreateHistoryStateForURL(url0), 2416 webkit_glue::CreateHistoryStateForURL(url0),
2417 content::PAGE_TRANSITION_LINK); 2417 content::PAGE_TRANSITION_LINK);
2418 session_helper_.AssertNavigationEquals(nav, 2418 session_helper_.AssertNavigationEquals(nav,
2419 windows_[0]->tabs[0]->navigations[0]); 2419 windows_[0]->tabs[0]->navigations[0]);
2420 nav.set_url(url2); 2420 nav.set_url(url2);
2421 session_helper_.AssertNavigationEquals(nav, 2421 session_helper_.AssertNavigationEquals(nav,
2422 windows_[0]->tabs[0]->navigations[1]); 2422 windows_[0]->tabs[0]->navigations[1]);
2423 } 2423 }
2424 */ 2424 */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698