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

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

Issue 9473001: Extract minimal RenderViewHost interface for embedders, leaving (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to LKGR. 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.h" 8 #include "content/browser/renderer_host/render_view_host.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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 InitNavigateParams(&params, page_id, url, content::PAGE_TRANSITION_TYPED); 176 InitNavigateParams(&params, page_id, url, content::PAGE_TRANSITION_TYPED);
177 DidNavigate(GetRenderViewHostForTesting(), params); 177 DidNavigate(GetRenderViewHostForTesting(), params);
178 } 178 }
179 179
180 void TestRenderViewGone(base::TerminationStatus status, int error_code) { 180 void TestRenderViewGone(base::TerminationStatus status, int error_code) {
181 RenderViewGone(GetRenderViewHostForTesting(), status, error_code); 181 RenderViewGone(GetRenderViewHostForTesting(), status, error_code);
182 } 182 }
183 183
184 bool is_showing() const { 184 bool is_showing() const {
185 return static_cast<content::TestRenderWidgetHostView*>( 185 return static_cast<content::TestRenderWidgetHostView*>(
186 GetRenderViewHostForTesting()->view())->is_showing(); 186 GetRenderViewHostForTesting()->GetView())->is_showing();
187 } 187 }
188 188
189 void ClearStates() { 189 void ClearStates() {
190 state_ = NULL; 190 state_ = NULL;
191 deleted_ = NULL; 191 deleted_ = NULL;
192 delegate_ = NULL; 192 delegate_ = NULL;
193 } 193 }
194 194
195 void CommandReceived() { 195 void CommandReceived() {
196 command_received_count_++; 196 command_received_count_++;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 NavigationControllerImpl& cont = 299 NavigationControllerImpl& cont =
300 static_cast<NavigationControllerImpl&>(controller()); 300 static_cast<NavigationControllerImpl&>(controller());
301 const char kUrl[] = "view-source:tabcontentstest://blah"; 301 const char kUrl[] = "view-source:tabcontentstest://blah";
302 const GURL kGURL(kUrl); 302 const GURL kGURL(kUrl);
303 303
304 process()->sink().ClearMessages(); 304 process()->sink().ClearMessages();
305 305
306 cont.LoadURL( 306 cont.LoadURL(
307 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED, 307 kGURL, content::Referrer(), content::PAGE_TRANSITION_TYPED,
308 std::string()); 308 std::string());
309 rvh()->delegate()->RenderViewCreated(rvh()); 309 rvh()->GetDelegate()->RenderViewCreated(rvh());
310 // Did we get the expected message? 310 // Did we get the expected message?
311 EXPECT_TRUE(process()->sink().GetFirstMessageMatching( 311 EXPECT_TRUE(process()->sink().GetFirstMessageMatching(
312 ViewMsg_EnableViewSourceMode::ID)); 312 ViewMsg_EnableViewSourceMode::ID));
313 313
314 ViewHostMsg_FrameNavigate_Params params; 314 ViewHostMsg_FrameNavigate_Params params;
315 InitNavigateParams(&params, 0, kGURL, content::PAGE_TRANSITION_TYPED); 315 InitNavigateParams(&params, 0, kGURL, content::PAGE_TRANSITION_TYPED);
316 content::LoadCommittedDetails details; 316 content::LoadCommittedDetails details;
317 cont.RendererDidNavigate(params, &details); 317 cont.RendererDidNavigate(params, &details);
318 // Also check title and url. 318 // Also check title and url.
319 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle()); 319 EXPECT_EQ(ASCIIToUTF16(kUrl), contents()->GetTitle());
(...skipping 26 matching lines...) Expand all
346 TEST_F(TabContentsTest, SimpleNavigation) { 346 TEST_F(TabContentsTest, SimpleNavigation) {
347 TestRenderViewHost* orig_rvh = rvh(); 347 TestRenderViewHost* orig_rvh = rvh();
348 SiteInstance* instance1 = contents()->GetSiteInstance(); 348 SiteInstance* instance1 = contents()->GetSiteInstance();
349 EXPECT_TRUE(contents()->pending_rvh() == NULL); 349 EXPECT_TRUE(contents()->pending_rvh() == NULL);
350 350
351 // Navigate to URL 351 // Navigate to URL
352 const GURL url("http://www.google.com"); 352 const GURL url("http://www.google.com");
353 controller().LoadURL( 353 controller().LoadURL(
354 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 354 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
355 EXPECT_FALSE(contents()->cross_navigation_pending()); 355 EXPECT_FALSE(contents()->cross_navigation_pending());
356 EXPECT_EQ(instance1, orig_rvh->site_instance()); 356 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance());
357 // Controller's pending entry will have a NULL site instance until we assign 357 // Controller's pending entry will have a NULL site instance until we assign
358 // it in DidNavigate. 358 // it in DidNavigate.
359 EXPECT_TRUE( 359 EXPECT_TRUE(
360 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())-> 360 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())->
361 site_instance() == NULL); 361 site_instance() == NULL);
362 362
363 // DidNavigate from the page 363 // DidNavigate from the page
364 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED); 364 contents()->TestDidNavigate(orig_rvh, 1, url, content::PAGE_TRANSITION_TYPED);
365 EXPECT_FALSE(contents()->cross_navigation_pending()); 365 EXPECT_FALSE(contents()->cross_navigation_pending());
366 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost()); 366 EXPECT_EQ(orig_rvh, contents()->GetRenderViewHost());
367 EXPECT_EQ(instance1, orig_rvh->site_instance()); 367 EXPECT_EQ(instance1, orig_rvh->GetSiteInstance());
368 // Controller's entry should now have the SiteInstance, or else we won't be 368 // Controller's entry should now have the SiteInstance, or else we won't be
369 // able to find it later. 369 // able to find it later.
370 EXPECT_EQ( 370 EXPECT_EQ(
371 instance1, 371 instance1,
372 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())-> 372 NavigationEntryImpl::FromNavigationEntry(controller().GetActiveEntry())->
373 site_instance()); 373 site_instance());
374 } 374 }
375 375
376 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars. 376 // Test that we reject NavigateToEntry if the url is over content::kMaxURLChars.
377 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) { 377 TEST_F(TabContentsTest, NavigateToExcessivelyLongURL) {
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 TestRenderViewHost* ntp_rvh = rvh(); 711 TestRenderViewHost* ntp_rvh = rvh();
712 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED); 712 contents()->TestDidNavigate(ntp_rvh, 1, url1, content::PAGE_TRANSITION_TYPED);
713 NavigationEntry* entry1 = controller().GetLastCommittedEntry(); 713 NavigationEntry* entry1 = controller().GetLastCommittedEntry();
714 SiteInstance* instance1 = contents()->GetSiteInstance(); 714 SiteInstance* instance1 = contents()->GetSiteInstance();
715 715
716 EXPECT_FALSE(contents()->cross_navigation_pending()); 716 EXPECT_FALSE(contents()->cross_navigation_pending());
717 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost()); 717 EXPECT_EQ(ntp_rvh, contents()->GetRenderViewHost());
718 EXPECT_EQ(url1, entry1->GetURL()); 718 EXPECT_EQ(url1, entry1->GetURL());
719 EXPECT_EQ(instance1, 719 EXPECT_EQ(instance1,
720 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance()); 720 NavigationEntryImpl::FromNavigationEntry(entry1)->site_instance());
721 EXPECT_TRUE(ntp_rvh->enabled_bindings() & content::BINDINGS_POLICY_WEB_UI); 721 EXPECT_TRUE(ntp_rvh->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI);
722 722
723 // Navigate to new site. 723 // Navigate to new site.
724 const GURL url2("http://www.google.com"); 724 const GURL url2("http://www.google.com");
725 controller().LoadURL( 725 controller().LoadURL(
726 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 726 url2, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
727 EXPECT_TRUE(contents()->cross_navigation_pending()); 727 EXPECT_TRUE(contents()->cross_navigation_pending());
728 TestRenderViewHost* google_rvh = contents()->pending_rvh(); 728 TestRenderViewHost* google_rvh = contents()->pending_rvh();
729 729
730 // Simulate beforeunload approval. 730 // Simulate beforeunload approval.
731 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack()); 731 EXPECT_TRUE(ntp_rvh->is_waiting_for_beforeunload_ack());
732 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true)); 732 ntp_rvh->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK(0, true));
733 733
734 // DidNavigate from the pending page. 734 // DidNavigate from the pending page.
735 contents()->TestDidNavigate( 735 contents()->TestDidNavigate(
736 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED); 736 google_rvh, 1, url2, content::PAGE_TRANSITION_TYPED);
737 NavigationEntry* entry2 = controller().GetLastCommittedEntry(); 737 NavigationEntry* entry2 = controller().GetLastCommittedEntry();
738 SiteInstance* instance2 = contents()->GetSiteInstance(); 738 SiteInstance* instance2 = contents()->GetSiteInstance();
739 739
740 EXPECT_FALSE(contents()->cross_navigation_pending()); 740 EXPECT_FALSE(contents()->cross_navigation_pending());
741 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost()); 741 EXPECT_EQ(google_rvh, contents()->GetRenderViewHost());
742 EXPECT_NE(instance1, instance2); 742 EXPECT_NE(instance1, instance2);
743 EXPECT_FALSE(contents()->pending_rvh()); 743 EXPECT_FALSE(contents()->pending_rvh());
744 EXPECT_EQ(url2, entry2->GetURL()); 744 EXPECT_EQ(url2, entry2->GetURL());
745 EXPECT_EQ(instance2, 745 EXPECT_EQ(instance2,
746 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance()); 746 NavigationEntryImpl::FromNavigationEntry(entry2)->site_instance());
747 EXPECT_FALSE(google_rvh->enabled_bindings() & 747 EXPECT_FALSE(google_rvh->GetEnabledBindings() &
748 content::BINDINGS_POLICY_WEB_UI); 748 content::BINDINGS_POLICY_WEB_UI);
749 749
750 // Navigate to third page on same site. 750 // Navigate to third page on same site.
751 const GURL url3("http://news.google.com"); 751 const GURL url3("http://news.google.com");
752 controller().LoadURL( 752 controller().LoadURL(
753 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 753 url3, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
754 EXPECT_FALSE(contents()->cross_navigation_pending()); 754 EXPECT_FALSE(contents()->cross_navigation_pending());
755 contents()->TestDidNavigate( 755 contents()->TestDidNavigate(
756 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED); 756 google_rvh, 2, url3, content::PAGE_TRANSITION_TYPED);
757 NavigationEntry* entry3 = controller().GetLastCommittedEntry(); 757 NavigationEntry* entry3 = controller().GetLastCommittedEntry();
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 // It should have a transient entry. 1888 // It should have a transient entry.
1889 EXPECT_TRUE(other_controller.GetTransientEntry()); 1889 EXPECT_TRUE(other_controller.GetTransientEntry());
1890 1890
1891 // And the interstitial should be showing. 1891 // And the interstitial should be showing.
1892 EXPECT_TRUE(other_contents->ShowingInterstitialPage()); 1892 EXPECT_TRUE(other_contents->ShowingInterstitialPage());
1893 1893
1894 // And the interstitial should do a reload on don't proceed. 1894 // And the interstitial should do a reload on don't proceed.
1895 EXPECT_TRUE(static_cast<InterstitialPageImpl*>( 1895 EXPECT_TRUE(static_cast<InterstitialPageImpl*>(
1896 other_contents->GetInterstitialPage())->reload_on_dont_proceed()); 1896 other_contents->GetInterstitialPage())->reload_on_dont_proceed());
1897 } 1897 }
OLDNEW
« no previous file with comments | « content/browser/tab_contents/tab_contents.cc ('k') | content/browser/tab_contents/tab_contents_view_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698