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

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

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 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) 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "content/browser/mock_content_browser_client.h" 7 #include "content/browser/mock_content_browser_client.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 8 #include "content/browser/renderer_host/render_view_host_impl.h"
9 #include "content/browser/renderer_host/test_render_view_host.h" 9 #include "content/browser/renderer_host/test_render_view_host.h"
10 #include "content/browser/site_instance_impl.h" 10 #include "content/browser/site_instance_impl.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 old_client_(NULL), 272 old_client_(NULL),
273 old_browser_client_(NULL) { 273 old_browser_client_(NULL) {
274 } 274 }
275 275
276 virtual void SetUp() { 276 virtual void SetUp() {
277 // These tests treat tabcontentstest as a privileged WebUI scheme. 277 // These tests treat tabcontentstest as a privileged WebUI scheme.
278 // We must register it similarly to kChromeUIScheme. 278 // We must register it similarly to kChromeUIScheme.
279 url_util::AddStandardScheme("tabcontentstest"); 279 url_util::AddStandardScheme("tabcontentstest");
280 280
281 old_client_ = content::GetContentClient(); 281 old_client_ = content::GetContentClient();
282 old_browser_client_ = content::GetContentClient()->browser();
282 content::SetContentClient(&client_); 283 content::SetContentClient(&client_);
283 old_browser_client_ = content::GetContentClient()->browser();
284 content::GetContentClient()->set_browser(&browser_client_); 284 content::GetContentClient()->set_browser(&browser_client_);
285 RenderViewHostTestHarness::SetUp(); 285 RenderViewHostImplTestHarness::SetUp();
286 } 286 }
287 287
288 virtual void TearDown() { 288 virtual void TearDown() {
289 content::GetContentClient()->set_browser(old_browser_client_); 289 content::GetContentClient()->set_browser(old_browser_client_);
290 content::SetContentClient(old_client_); 290 content::SetContentClient(old_client_);
291 RenderViewHostTestHarness::TearDown(); 291 RenderViewHostImplTestHarness::TearDown();
292 } 292 }
293 293
294 private: 294 private:
295 TabContentsTestClient client_; 295 TabContentsTestClient client_;
296 TabContentsTestBrowserClient browser_client_; 296 TabContentsTestBrowserClient browser_client_;
297 content::TestBrowserThread ui_thread_; 297 content::TestBrowserThread ui_thread_;
298 content::ContentClient* old_client_; 298 content::ContentClient* old_client_;
299 content::ContentBrowserClient* old_browser_client_; 299 content::ContentBrowserClient* old_browser_client_;
300 }; 300 };
301 301
(...skipping 1552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1854 TestInterstitialPage* interstitial = 1854 TestInterstitialPage* interstitial =
1855 new TestInterstitialPage(contents(), true, url2, &state, &deleted); 1855 new TestInterstitialPage(contents(), true, url2, &state, &deleted);
1856 TestInterstitialPageStateGuard state_guard(interstitial); 1856 TestInterstitialPageStateGuard state_guard(interstitial);
1857 interstitial->Show(); 1857 interstitial->Show();
1858 interstitial->TestDidNavigate(1, url2); 1858 interstitial->TestDidNavigate(1, url2);
1859 EXPECT_TRUE(interstitial->is_showing()); 1859 EXPECT_TRUE(interstitial->is_showing());
1860 EXPECT_EQ(2, controller().GetEntryCount()); 1860 EXPECT_EQ(2, controller().GetEntryCount());
1861 1861
1862 // Create another NavigationController. 1862 // Create another NavigationController.
1863 GURL url3("http://foo2"); 1863 GURL url3("http://foo2");
1864 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1864 scoped_ptr<TestTabContents> other_contents(
1865 static_cast<TestTabContents*>(CreateTestWebContents()));
1865 NavigationControllerImpl& other_controller = 1866 NavigationControllerImpl& other_controller =
1866 other_contents->GetControllerImpl(); 1867 other_contents->GetControllerImpl();
1867 other_contents->NavigateAndCommit(url3); 1868 other_contents->NavigateAndCommit(url3);
1868 other_contents->ExpectSetHistoryLengthAndPrune( 1869 other_contents->ExpectSetHistoryLengthAndPrune(
1869 NavigationEntryImpl::FromNavigationEntry( 1870 NavigationEntryImpl::FromNavigationEntry(
1870 other_controller.GetEntryAtIndex(0))->site_instance(), 1, 1871 other_controller.GetEntryAtIndex(0))->site_instance(), 1,
1871 other_controller.GetEntryAtIndex(0)->GetPageID()); 1872 other_controller.GetEntryAtIndex(0)->GetPageID());
1872 other_controller.CopyStateFromAndPrune(&controller()); 1873 other_controller.CopyStateFromAndPrune(&controller());
1873 1874
1874 // The merged controller should only have two entries: url1 and url2. 1875 // The merged controller should only have two entries: url1 and url2.
1875 ASSERT_EQ(2, other_controller.GetEntryCount()); 1876 ASSERT_EQ(2, other_controller.GetEntryCount());
1876 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex()); 1877 EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
1877 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 1878 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
1878 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL()); 1879 EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
1879 1880
1880 // And the merged controller shouldn't be showing an interstitial. 1881 // And the merged controller shouldn't be showing an interstitial.
1881 EXPECT_FALSE(other_contents->ShowingInterstitialPage()); 1882 EXPECT_FALSE(other_contents->ShowingInterstitialPage());
1882 } 1883 }
1883 1884
1884 // Makes sure that CopyStateFromAndPrune does the right thing if the object 1885 // Makes sure that CopyStateFromAndPrune does the right thing if the object
1885 // CopyStateFromAndPrune is invoked on is showing an interstitial. 1886 // CopyStateFromAndPrune is invoked on is showing an interstitial.
1886 TEST_F(TabContentsTest, CopyStateFromAndPruneTargetInterstitial) { 1887 TEST_F(TabContentsTest, CopyStateFromAndPruneTargetInterstitial) {
1887 // Navigate to a page. 1888 // Navigate to a page.
1888 GURL url1("http://www.google.com"); 1889 GURL url1("http://www.google.com");
1889 contents()->NavigateAndCommit(url1); 1890 contents()->NavigateAndCommit(url1);
1890 1891
1891 // Create another NavigationController. 1892 // Create another NavigationController.
1892 scoped_ptr<TestTabContents> other_contents(CreateTestTabContents()); 1893 scoped_ptr<TestTabContents> other_contents(
1894 static_cast<TestTabContents*>(CreateTestWebContents()));
1893 NavigationControllerImpl& other_controller = 1895 NavigationControllerImpl& other_controller =
1894 other_contents->GetControllerImpl(); 1896 other_contents->GetControllerImpl();
1895 1897
1896 // Navigate it to url2. 1898 // Navigate it to url2.
1897 GURL url2("http://foo2"); 1899 GURL url2("http://foo2");
1898 other_contents->NavigateAndCommit(url2); 1900 other_contents->NavigateAndCommit(url2);
1899 1901
1900 // Show an interstitial. 1902 // Show an interstitial.
1901 TestInterstitialPage::InterstitialState state = 1903 TestInterstitialPage::InterstitialState state =
1902 TestInterstitialPage::UNDECIDED; 1904 TestInterstitialPage::UNDECIDED;
(...skipping 22 matching lines...) Expand all
1925 // It should have a transient entry. 1927 // It should have a transient entry.
1926 EXPECT_TRUE(other_controller.GetTransientEntry()); 1928 EXPECT_TRUE(other_controller.GetTransientEntry());
1927 1929
1928 // And the interstitial should be showing. 1930 // And the interstitial should be showing.
1929 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); 1931 EXPECT_TRUE(other_contents->ShowingInterstitialPage());
1930 1932
1931 // And the interstitial should do a reload on don't proceed. 1933 // And the interstitial should do a reload on don't proceed.
1932 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( 1934 EXPECT_TRUE(static_cast<InterstitialPageImpl*>(
1933 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); 1935 other_contents->GetInterstitialPage())->reload_on_dont_proceed());
1934 } 1936 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/render_view_host_manager_unittest.cc ('k') | content/browser/tab_contents/test_tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698