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

Side by Side Diff: chrome/browser/renderer_host/render_process_host_chrome_browsertest.cc

Issue 18167004: Iterate over listeners when sending process died notification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes. Created 7 years, 5 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
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/process_util.h"
6 #include "chrome/browser/devtools/devtools_window.h" 7 #include "chrome/browser/devtools/devtools_window.h"
7 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h" 9 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/singleton_tabs.h" 10 #include "chrome/browser/ui/singleton_tabs.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/url_constants.h" 14 #include "chrome/common/url_constants.h"
13 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
16 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
17 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents.h" 20 #include "content/public/browser/web_contents.h"
21 #include "content/public/browser/web_contents_observer.h"
19 22
20 using content::RenderViewHost; 23 using content::RenderViewHost;
21 using content::RenderWidgetHost; 24 using content::RenderWidgetHost;
22 using content::WebContents; 25 using content::WebContents;
23 26
24 namespace { 27 namespace {
25 28
26 int RenderProcessHostCount() { 29 int RenderProcessHostCount() {
27 content::RenderProcessHost::iterator hosts = 30 content::RenderProcessHost::iterator hosts =
28 content::RenderProcessHost::AllHostsIterator(); 31 content::RenderProcessHost::AllHostsIterator();
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 RenderViewHost* devtools = FindFirstDevToolsHost(); 348 RenderViewHost* devtools = FindFirstDevToolsHost();
346 DCHECK(devtools); 349 DCHECK(devtools);
347 350
348 // DevTools start in a separate process. 351 // DevTools start in a separate process.
349 DevToolsWindow::ToggleDevToolsWindow( 352 DevToolsWindow::ToggleDevToolsWindow(
350 devtools, true, DEVTOOLS_TOGGLE_ACTION_INSPECT); 353 devtools, true, DEVTOOLS_TOGGLE_ACTION_INSPECT);
351 host_count++; 354 host_count++;
352 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); 355 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count());
353 EXPECT_EQ(host_count, RenderProcessHostCount()); 356 EXPECT_EQ(host_count, RenderProcessHostCount());
354 } 357 }
358
359 // This class's goal is to close the browser window when a renderer process has
360 // crashed. It does so by monitoring WebContents for RenderViewGone event and
361 // closing the passed in TabStripModel. This is used in the following test case.
362 class WindowDestroyer : public content::WebContentsObserver {
363 public:
364 WindowDestroyer(content::WebContents* web_contents, TabStripModel* model)
365 : content::WebContentsObserver(web_contents),
366 tab_strip_model_(model) {
367 }
368
369 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
370 // Wait for the window to be destroyed, which will ensure all other
371 // RenderViewHost objects are deleted before we return and proceed with
372 // the next iteration of notifications.
373 content::WindowedNotificationObserver observer(
374 chrome::NOTIFICATION_BROWSER_CLOSED,
375 content::NotificationService::AllSources());
376 tab_strip_model_->CloseAllTabs();
377 observer.Wait();
378 }
379
380 private:
381 TabStripModel* tab_strip_model_;
382 };
jochen (gone - plz use gerrit) 2013/07/02 07:56:46 nit. DISALLOW_COPY_AND_ASSIGN()
nasko 2013/07/02 14:57:29 Done.
383
384 // Test to ensure that while iterating through all listeners in
385 // RenderProcessHost and invalidating them, we remove them properly and don't
386 // access already freed objects. See http://crbug.com/255524.
387 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest,
388 CloseAllTabsDuringProcessDied) {
389 GURL url(chrome::kChromeUINewTabURL);
390
391 ui_test_utils::NavigateToURL(browser(), url);
392 ui_test_utils::NavigateToURLWithDisposition(
393 browser(), url, NEW_BACKGROUND_TAB,
394 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
395
396 EXPECT_EQ(2, browser()->tab_strip_model()->count());
397
398 WebContents* wc1 = browser()->tab_strip_model()->GetWebContentsAt(0);
399 WebContents* wc2 = browser()->tab_strip_model()->GetWebContentsAt(1);
400 EXPECT_EQ(wc1->GetRenderProcessHost(), wc2->GetRenderProcessHost());
401
402 // Create an object that will close the window on a process crash.
403 WindowDestroyer destroyer(wc1, browser()->tab_strip_model());
404
405 // Use NOTIFICATION_BROWSER_CLOSED instead of NOTIFICATION_WINDOW_CLOSED,
406 // since the latter is not implemented on OSX and the test will timeout,
407 // causing it to fail.
408 content::WindowedNotificationObserver observer(
409 chrome::NOTIFICATION_BROWSER_CLOSED,
410 content::NotificationService::AllSources());
411
412 // Kill the renderer process, simulating a crash. This should the ProcessDied
413 // method to be called. Alternatively, RenderProcessHost::OnChannelError can
414 // be called to directly force a call to ProcessDied.
415 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true);
416
417 observer.Wait();
418 }
OLDNEW
« no previous file with comments | « no previous file | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698