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

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

Issue 9271054: Send replies to sync IPCs from swapped out renderers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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/utf_string_conversions.h"
5 #include "content/browser/browser_thread_impl.h" 6 #include "content/browser/browser_thread_impl.h"
6 #include "content/browser/browser_url_handler.h" 7 #include "content/browser/browser_url_handler.h"
7 #include "content/browser/mock_content_browser_client.h" 8 #include "content/browser/mock_content_browser_client.h"
8 #include "content/browser/renderer_host/test_render_view_host.h" 9 #include "content/browser/renderer_host/test_render_view_host.h"
9 #include "content/browser/site_instance.h" 10 #include "content/browser/site_instance.h"
10 #include "content/browser/tab_contents/navigation_controller_impl.h" 11 #include "content/browser/tab_contents/navigation_controller_impl.h"
11 #include "content/browser/tab_contents/navigation_entry_impl.h" 12 #include "content/browser/tab_contents/navigation_entry_impl.h"
12 #include "content/browser/tab_contents/render_view_host_manager.h" 13 #include "content/browser/tab_contents/render_view_host_manager.h"
13 #include "content/browser/tab_contents/test_tab_contents.h" 14 #include "content/browser/tab_contents/test_tab_contents.h"
14 #include "content/browser/webui/empty_web_ui_factory.h" 15 #include "content/browser/webui/empty_web_ui_factory.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"
19 #include "content/public/browser/notification_types.h" 20 #include "content/public/browser/notification_types.h"
20 #include "content/public/browser/web_ui_controller.h" 21 #include "content/public/browser/web_ui_controller.h"
21 #include "content/public/common/page_transition_types.h" 22 #include "content/public/common/page_transition_types.h"
22 #include "content/public/common/url_constants.h" 23 #include "content/public/common/url_constants.h"
23 #include "content/test/test_browser_context.h" 24 #include "content/test/test_browser_context.h"
24 #include "content/test/test_notification_tracker.h" 25 #include "content/test/test_notification_tracker.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "googleurl/src/url_util.h" 27 #include "googleurl/src/url_util.h"
28 #include "ui/base/javascript_message_type.h"
27 #include "webkit/glue/webkit_glue.h" 29 #include "webkit/glue/webkit_glue.h"
28 30
29 using content::BrowserThread; 31 using content::BrowserThread;
30 using content::BrowserThreadImpl; 32 using content::BrowserThreadImpl;
31 using content::NavigationController; 33 using content::NavigationController;
32 using content::NavigationEntry; 34 using content::NavigationEntry;
33 using content::NavigationEntryImpl; 35 using content::NavigationEntryImpl;
34 using content::WebContents; 36 using content::WebContents;
35 using content::WebUIController; 37 using content::WebUIController;
36 38
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 std::string()); 212 std::string());
211 dest_rvh2->SendShouldCloseACK(true); 213 dest_rvh2->SendShouldCloseACK(true);
212 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()-> 214 static_cast<TestRenderViewHost*>(contents2.GetRenderManagerForTesting()->
213 pending_render_view_host())->SendNavigate(102, kNtpUrl); 215 pending_render_view_host())->SendNavigate(102, kNtpUrl);
214 dest_rvh2->OnSwapOutACK(); 216 dest_rvh2->OnSwapOutACK();
215 217
216 EXPECT_EQ(active_rvh()->site_instance(), 218 EXPECT_EQ(active_rvh()->site_instance(),
217 contents2.GetRenderViewHost()->site_instance()); 219 contents2.GetRenderViewHost()->site_instance());
218 } 220 }
219 221
222 // Ensure that the browser ignores most IPC messages that arrive from a
223 // RenderViewHost that has been swapped out. We do not want to take
224 // action on requests from a non-active renderer. The main exception is
225 // for synchronous messages, which cannot be ignored without leaving the
226 // renderer in a stuck state. See http://crbug.com/93427.
227 TEST_F(RenderViewHostManagerTest, FilterMessagesWhileSwappedOut) {
228 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
229 const GURL kNtpUrl(chrome::kTestNewTabURL);
230 const GURL kDestUrl("http://www.google.com/");
231
232 // Navigate our first tab to the new tab page and then to the destination.
233 NavigateActiveAndCommit(kNtpUrl);
234 TestRenderViewHost* ntp_rvh = static_cast<TestRenderViewHost*>(
235 contents()->GetRenderManagerForTesting()->current_host());
236
237 // Send an update title message and make sure it works.
238 const string16 ntp_title = ASCIIToUTF16("NTP Title");
239 WebKit::WebTextDirection direction = WebKit::WebTextDirectionLeftToRight;
240 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(
241 ViewHostMsg_UpdateTitle(rvh()->routing_id(), 0, ntp_title, direction)));
242 EXPECT_EQ(ntp_title, contents()->GetTitle());
243
244 // Navigate to a cross-site URL.
245 contents()->GetController().LoadURL(
246 kDestUrl, content::Referrer(), content::PAGE_TRANSITION_LINK,
247 std::string());
248 EXPECT_TRUE(contents()->cross_navigation_pending());
249 TestRenderViewHost* dest_rvh = static_cast<TestRenderViewHost*>(
250 contents()->GetRenderManagerForTesting()->pending_render_view_host());
251 ASSERT_TRUE(dest_rvh);
252 EXPECT_NE(ntp_rvh, dest_rvh);
253
254 // BeforeUnload finishes.
255 ntp_rvh->SendShouldCloseACK(true);
256
257 // Assume SwapOutACK times out, so the dest_rvh proceeds and commits.
258 dest_rvh->SendNavigate(101, kDestUrl);
259
260 // The new RVH should be able to update its title.
261 const string16 dest_title = ASCIIToUTF16("Google");
262 EXPECT_TRUE(dest_rvh->TestOnMessageReceived(
263 ViewHostMsg_UpdateTitle(rvh()->routing_id(), 101, dest_title,
264 direction)));
265 EXPECT_EQ(dest_title, contents()->GetTitle());
266
267 // The old renderer, being slow, now updates the title. It should be filtered
268 // out and not take effect.
269 EXPECT_TRUE(ntp_rvh->is_swapped_out());
270 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(
271 ViewHostMsg_UpdateTitle(rvh()->routing_id(), 0, ntp_title, direction)));
272 EXPECT_EQ(dest_title, contents()->GetTitle());
273
274 // We cannot filter out synchronous IPC messages, because the renderer would
275 // be left waiting for a reply. We pick RunBeforeUnloadConfirm as an example
276 // that can run easily within a unit test, and that needs to be suppressed
277 // but still receive a reply.
278 MockRenderProcessHost* ntp_process_host =
279 static_cast<MockRenderProcessHost*>(ntp_rvh->process());
280 ntp_process_host->sink().ClearMessages();
281 const string16 msg = ASCIIToUTF16("Message");
282 bool result = false;
283 string16 unused;
284 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(
285 ViewHostMsg_RunBeforeUnloadConfirm(rvh()->routing_id(), kNtpUrl, msg,
286 &result, &unused)));
287 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
288
289 // Also test RunJavaScriptMessage.
290 ntp_process_host->sink().ClearMessages();
291 EXPECT_TRUE(ntp_rvh->TestOnMessageReceived(
292 ViewHostMsg_RunJavaScriptMessage(rvh()->routing_id(), msg, msg, kNtpUrl,
293 ui::JAVASCRIPT_MESSAGE_TYPE_CONFIRM,
294 &result, &unused)));
295 EXPECT_TRUE(ntp_process_host->sink().GetUniqueMessageMatching(IPC_REPLY_ID));
296 }
297
220 // When there is an error with the specified page, renderer exits view-source 298 // When there is an error with the specified page, renderer exits view-source
221 // mode. See WebFrameImpl::DidFail(). We check by this test that 299 // mode. See WebFrameImpl::DidFail(). We check by this test that
222 // EnableViewSourceMode message is sent on every navigation regardless 300 // EnableViewSourceMode message is sent on every navigation regardless
223 // RenderView is being newly created or reused. 301 // RenderView is being newly created or reused.
224 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) { 302 TEST_F(RenderViewHostManagerTest, AlwaysSendEnableViewSourceMode) {
225 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current()); 303 BrowserThreadImpl ui_thread(BrowserThread::UI, MessageLoop::current());
226 const GURL kNtpUrl(chrome::kTestNewTabURL); 304 const GURL kNtpUrl(chrome::kTestNewTabURL);
227 const GURL kUrl("view-source:http://foo"); 305 const GURL kUrl("view-source:http://foo");
228 306
229 // We have to navigate to some page at first since without this, the first 307 // We have to navigate to some page at first since without this, the first
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 // current one. 693 // current one.
616 EXPECT_TRUE(contents()->GetRenderManagerForTesting()-> 694 EXPECT_TRUE(contents()->GetRenderManagerForTesting()->
617 pending_render_view_host() == NULL); 695 pending_render_view_host() == NULL);
618 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host()); 696 EXPECT_EQ(evil_rvh, contents()->GetRenderManagerForTesting()->current_host());
619 697
620 // Also we should not have a pending navigation entry. 698 // Also we should not have a pending navigation entry.
621 NavigationEntry* entry = contents()->GetController().GetActiveEntry(); 699 NavigationEntry* entry = contents()->GetController().GetActiveEntry();
622 ASSERT_TRUE(entry != NULL); 700 ASSERT_TRUE(entry != NULL);
623 EXPECT_EQ(kUrl2, entry->GetURL()); 701 EXPECT_EQ(kUrl2, entry->GetURL());
624 } 702 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698