OLD | NEW |
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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "content/browser/browser_thread_impl.h" | 6 #include "content/browser/browser_thread_impl.h" |
7 #include "content/browser/browser_url_handler.h" | 7 #include "content/browser/browser_url_handler.h" |
8 #include "content/browser/mock_content_browser_client.h" | 8 #include "content/browser/mock_content_browser_client.h" |
| 9 #include "content/browser/renderer_host/mock_render_process_host.h" |
9 #include "content/browser/renderer_host/test_render_view_host.h" | 10 #include "content/browser/renderer_host/test_render_view_host.h" |
10 #include "content/browser/site_instance_impl.h" | 11 #include "content/browser/site_instance_impl.h" |
11 #include "content/browser/tab_contents/navigation_controller_impl.h" | 12 #include "content/browser/tab_contents/navigation_controller_impl.h" |
12 #include "content/browser/tab_contents/navigation_entry_impl.h" | 13 #include "content/browser/tab_contents/navigation_entry_impl.h" |
13 #include "content/browser/tab_contents/render_view_host_manager.h" | 14 #include "content/browser/tab_contents/render_view_host_manager.h" |
14 #include "content/browser/tab_contents/test_tab_contents.h" | 15 #include "content/browser/tab_contents/test_tab_contents.h" |
15 #include "content/common/test_url_constants.h" | 16 #include "content/common/test_url_constants.h" |
16 #include "content/common/view_messages.h" | 17 #include "content/common/view_messages.h" |
17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
(...skipping 10 matching lines...) Expand all Loading... |
29 #include "webkit/glue/webkit_glue.h" | 30 #include "webkit/glue/webkit_glue.h" |
30 | 31 |
31 using content::BrowserContext; | 32 using content::BrowserContext; |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 using content::BrowserThreadImpl; | 34 using content::BrowserThreadImpl; |
34 using content::NavigationController; | 35 using content::NavigationController; |
35 using content::NavigationEntry; | 36 using content::NavigationEntry; |
36 using content::NavigationEntryImpl; | 37 using content::NavigationEntryImpl; |
37 using content::RenderViewHost; | 38 using content::RenderViewHost; |
38 using content::RenderViewHostImpl; | 39 using content::RenderViewHostImpl; |
| 40 using content::RenderViewHostImplTestHarness; |
39 using content::SiteInstance; | 41 using content::SiteInstance; |
40 using content::TestRenderViewHost; | 42 using content::TestRenderViewHost; |
41 using content::WebContents; | 43 using content::WebContents; |
42 using content::WebUI; | 44 using content::WebUI; |
43 using content::WebUIController; | 45 using content::WebUIController; |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 const char kChromeUISchemeButNotWebUIURL[] = "chrome://not-webui"; | 49 const char kChromeUISchemeButNotWebUIURL[] = "chrome://not-webui"; |
48 | 50 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 116 } |
115 | 117 |
116 private: | 118 private: |
117 RenderViewHostManagerTestWebUIControllerFactory factory_; | 119 RenderViewHostManagerTestWebUIControllerFactory factory_; |
118 | 120 |
119 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestBrowserClient); | 121 DISALLOW_COPY_AND_ASSIGN(RenderViewHostManagerTestBrowserClient); |
120 }; | 122 }; |
121 | 123 |
122 } // namespace | 124 } // namespace |
123 | 125 |
124 class RenderViewHostManagerTest : public RenderViewHostTestHarness { | 126 class RenderViewHostManagerTest |
| 127 : public RenderViewHostImplTestHarness { |
125 public: | 128 public: |
126 virtual void SetUp() OVERRIDE { | 129 virtual void SetUp() OVERRIDE { |
127 RenderViewHostTestHarness::SetUp(); | 130 RenderViewHostTestHarness::SetUp(); |
128 old_browser_client_ = content::GetContentClient()->browser(); | 131 old_browser_client_ = content::GetContentClient()->browser(); |
129 content::GetContentClient()->set_browser(&browser_client_); | 132 content::GetContentClient()->set_browser(&browser_client_); |
130 url_util::AddStandardScheme(chrome::kChromeUIScheme); | 133 url_util::AddStandardScheme(chrome::kChromeUIScheme); |
131 } | 134 } |
132 | 135 |
133 virtual void TearDown() OVERRIDE { | 136 virtual void TearDown() OVERRIDE { |
134 RenderViewHostTestHarness::TearDown(); | 137 RenderViewHostTestHarness::TearDown(); |
135 content::GetContentClient()->set_browser(old_browser_client_); | 138 content::GetContentClient()->set_browser(old_browser_client_); |
136 } | 139 } |
137 | 140 |
138 void set_should_create_webui(bool should_create_webui) { | 141 void set_should_create_webui(bool should_create_webui) { |
139 browser_client_.set_should_create_webui(should_create_webui); | 142 browser_client_.set_should_create_webui(should_create_webui); |
140 } | 143 } |
141 | 144 |
142 void NavigateActiveAndCommit(const GURL& url) { | 145 void NavigateActiveAndCommit(const GURL& url) { |
143 // Note: we navigate the active RenderViewHost because previous navigations | 146 // Note: we navigate the active RenderViewHost because previous navigations |
144 // won't have committed yet, so NavigateAndCommit does the wrong thing | 147 // won't have committed yet, so NavigateAndCommit does the wrong thing |
145 // for us. | 148 // for us. |
146 controller().LoadURL( | 149 controller().LoadURL( |
147 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); | 150 url, content::Referrer(), content::PAGE_TRANSITION_LINK, std::string()); |
148 TestRenderViewHost* old_rvh = rvh(); | 151 TestRenderViewHost* old_rvh = test_rvh(); |
149 | 152 |
150 // Simulate the ShouldClose_ACK that is received from the current renderer | 153 // Simulate the ShouldClose_ACK that is received from the current renderer |
151 // for a cross-site navigation. | 154 // for a cross-site navigation. |
152 if (old_rvh != active_rvh()) | 155 if (old_rvh != active_rvh()) |
153 old_rvh->SendShouldCloseACK(true); | 156 old_rvh->SendShouldCloseACK(true); |
154 | 157 |
155 // Commit the navigation with a new page ID. | 158 // Commit the navigation with a new page ID. |
156 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( | 159 int32 max_page_id = contents()->GetMaxPageIDForSiteInstance( |
157 active_rvh()->GetSiteInstance()); | 160 active_rvh()->GetSiteInstance()); |
158 active_rvh()->SendNavigate(max_page_id + 1, url); | 161 active_test_rvh()->SendNavigate(max_page_id + 1, url); |
159 | 162 |
160 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation | 163 // Simulate the SwapOut_ACK that fires if you commit a cross-site navigation |
161 // without making any network requests. | 164 // without making any network requests. |
162 if (old_rvh != active_rvh()) | 165 if (old_rvh != active_rvh()) |
163 old_rvh->OnSwapOutACK(); | 166 old_rvh->OnSwapOutACK(); |
164 } | 167 } |
165 | 168 |
166 bool ShouldSwapProcesses(RenderViewHostManager* manager, | 169 bool ShouldSwapProcesses(RenderViewHostManager* manager, |
167 const NavigationEntryImpl* cur_entry, | 170 const NavigationEntryImpl* cur_entry, |
168 const NavigationEntryImpl* new_entry) const { | 171 const NavigationEntryImpl* new_entry) const { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // one will create a new SiteInstance. Because current_instance and | 334 // one will create a new SiteInstance. Because current_instance and |
332 // new_instance will be different, a new RenderViewHost will be created for | 335 // new_instance will be different, a new RenderViewHost will be created for |
333 // the second navigation. We have to avoid this in order to exercise the | 336 // the second navigation. We have to avoid this in order to exercise the |
334 // target code patch. | 337 // target code patch. |
335 NavigateActiveAndCommit(kNtpUrl); | 338 NavigateActiveAndCommit(kNtpUrl); |
336 | 339 |
337 // Navigate. | 340 // Navigate. |
338 controller().LoadURL( | 341 controller().LoadURL( |
339 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 342 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
340 // Simulate response from RenderView for FirePageBeforeUnload. | 343 // Simulate response from RenderView for FirePageBeforeUnload. |
341 rvh()->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( | 344 test_rvh()->TestOnMessageReceived(ViewHostMsg_ShouldClose_ACK( |
342 rvh()->GetRoutingID(), true, base::TimeTicks(), base::TimeTicks())); | 345 rvh()->GetRoutingID(), true, base::TimeTicks(), base::TimeTicks())); |
343 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. | 346 ASSERT_TRUE(pending_rvh()); // New pending RenderViewHost will be created. |
344 RenderViewHost* last_rvh = pending_rvh(); | 347 RenderViewHost* last_rvh = pending_rvh(); |
345 int32 new_id = contents()->GetMaxPageIDForSiteInstance( | 348 int32 new_id = contents()->GetMaxPageIDForSiteInstance( |
346 active_rvh()->GetSiteInstance()) + 1; | 349 active_rvh()->GetSiteInstance()) + 1; |
347 pending_rvh()->SendNavigate(new_id, kUrl); | 350 pending_test_rvh()->SendNavigate(new_id, kUrl); |
348 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 351 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
349 ASSERT_TRUE(controller().GetLastCommittedEntry()); | 352 ASSERT_TRUE(controller().GetLastCommittedEntry()); |
350 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); | 353 EXPECT_TRUE(kUrl == controller().GetLastCommittedEntry()->GetURL()); |
351 EXPECT_FALSE(controller().GetPendingEntry()); | 354 EXPECT_FALSE(controller().GetPendingEntry()); |
352 // Because we're using TestTabContents and TestRenderViewHost in this | 355 // Because we're using TestTabContents and TestRenderViewHost in this |
353 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no | 356 // unittest, no one calls TabContents::RenderViewCreated(). So, we see no |
354 // EnableViewSourceMode message, here. | 357 // EnableViewSourceMode message, here. |
355 | 358 |
356 // Clear queued messages before load. | 359 // Clear queued messages before load. |
357 process()->sink().ClearMessages(); | 360 process()->sink().ClearMessages(); |
358 // Navigate, again. | 361 // Navigate, again. |
359 controller().LoadURL( | 362 controller().LoadURL( |
360 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); | 363 kUrl, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); |
361 // The same RenderViewHost should be reused. | 364 // The same RenderViewHost should be reused. |
362 EXPECT_FALSE(pending_rvh()); | 365 EXPECT_FALSE(pending_rvh()); |
363 EXPECT_TRUE(last_rvh == rvh()); | 366 EXPECT_TRUE(last_rvh == rvh()); |
364 rvh()->SendNavigate(new_id, kUrl); // The same page_id returned. | 367 test_rvh()->SendNavigate(new_id, kUrl); // The same page_id returned. |
365 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); | 368 EXPECT_EQ(controller().GetLastCommittedEntryIndex(), 1); |
366 EXPECT_FALSE(controller().GetPendingEntry()); | 369 EXPECT_FALSE(controller().GetPendingEntry()); |
367 // New message should be sent out to make sure to enter view-source mode. | 370 // New message should be sent out to make sure to enter view-source mode. |
368 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( | 371 EXPECT_TRUE(process()->sink().GetUniqueMessageMatching( |
369 ViewMsg_EnableViewSourceMode::ID)); | 372 ViewMsg_EnableViewSourceMode::ID)); |
370 } | 373 } |
371 | 374 |
372 // Tests the Init function by checking the initial RenderViewHost. | 375 // Tests the Init function by checking the initial RenderViewHost. |
373 TEST_F(RenderViewHostManagerTest, Init) { | 376 TEST_F(RenderViewHostManagerTest, Init) { |
374 // Using TestBrowserContext. | 377 // Using TestBrowserContext. |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 } | 750 } |
748 | 751 |
749 // Ensure that we can go back and forward even if a SwapOut ACK isn't received. | 752 // Ensure that we can go back and forward even if a SwapOut ACK isn't received. |
750 // See http://crbug.com/93427. | 753 // See http://crbug.com/93427. |
751 TEST_F(RenderViewHostManagerTest, NavigateAfterMissingSwapOutACK) { | 754 TEST_F(RenderViewHostManagerTest, NavigateAfterMissingSwapOutACK) { |
752 const GURL kUrl1("http://www.google.com/"); | 755 const GURL kUrl1("http://www.google.com/"); |
753 const GURL kUrl2("http://www.chromium.org/"); | 756 const GURL kUrl2("http://www.chromium.org/"); |
754 | 757 |
755 // Navigate to two pages. | 758 // Navigate to two pages. |
756 contents()->NavigateAndCommit(kUrl1); | 759 contents()->NavigateAndCommit(kUrl1); |
757 TestRenderViewHost* rvh1 = rvh(); | 760 TestRenderViewHost* rvh1 = test_rvh(); |
758 contents()->NavigateAndCommit(kUrl2); | 761 contents()->NavigateAndCommit(kUrl2); |
759 TestRenderViewHost* rvh2 = rvh(); | 762 TestRenderViewHost* rvh2 = test_rvh(); |
760 | 763 |
761 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't | 764 // Now go back, but suppose the SwapOut_ACK isn't received. This shouldn't |
762 // happen, but we have seen it when going back quickly across many entries | 765 // happen, but we have seen it when going back quickly across many entries |
763 // (http://crbug.com/93427). | 766 // (http://crbug.com/93427). |
764 contents()->GetController().GoBack(); | 767 contents()->GetController().GoBack(); |
765 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack()); | 768 EXPECT_TRUE(rvh2->is_waiting_for_beforeunload_ack()); |
766 contents()->ProceedWithCrossSiteNavigation(); | 769 contents()->ProceedWithCrossSiteNavigation(); |
767 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack()); | 770 EXPECT_FALSE(rvh2->is_waiting_for_beforeunload_ack()); |
768 rvh2->SwapOut(1, 1); | 771 rvh2->SwapOut(1, 1); |
769 EXPECT_TRUE(rvh2->is_waiting_for_unload_ack()); | 772 EXPECT_TRUE(rvh2->is_waiting_for_unload_ack()); |
770 | 773 |
771 // The back navigation commits. We should proactively clear the | 774 // The back navigation commits. We should proactively clear the |
772 // is_waiting_for_unload_ack state to be safe. | 775 // is_waiting_for_unload_ack state to be safe. |
773 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); | 776 const NavigationEntry* entry1 = contents()->GetController().GetPendingEntry(); |
774 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); | 777 rvh1->SendNavigate(entry1->GetPageID(), entry1->GetURL()); |
775 EXPECT_TRUE(rvh2->is_swapped_out()); | 778 EXPECT_TRUE(rvh2->is_swapped_out()); |
776 EXPECT_FALSE(rvh2->is_waiting_for_unload_ack()); | 779 EXPECT_FALSE(rvh2->is_waiting_for_unload_ack()); |
777 | 780 |
778 // We should be able to navigate forward. | 781 // We should be able to navigate forward. |
779 contents()->GetController().GoForward(); | 782 contents()->GetController().GoForward(); |
780 contents()->ProceedWithCrossSiteNavigation(); | 783 contents()->ProceedWithCrossSiteNavigation(); |
781 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); | 784 const NavigationEntry* entry2 = contents()->GetController().GetPendingEntry(); |
782 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); | 785 rvh2->SendNavigate(entry2->GetPageID(), entry2->GetURL()); |
783 EXPECT_EQ(rvh2, rvh()); | 786 EXPECT_EQ(rvh2, rvh()); |
784 EXPECT_FALSE(rvh2->is_swapped_out()); | 787 EXPECT_FALSE(rvh2->is_swapped_out()); |
785 EXPECT_TRUE(rvh1->is_swapped_out()); | 788 EXPECT_TRUE(rvh1->is_swapped_out()); |
786 } | 789 } |
OLD | NEW |