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

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: 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
Charlie Reis 2013/07/01 17:16:42 nit: Remove extra blank line.
nasko 2013/07/01 23:08:42 Done.
359
360 // This class's goal is to close the browser window when a renderer process has
361 // crashed. It does so by monitoring WebContents for RenderViewGone event and
362 // closing the passed in TabStripModel. This is used in the following test case.
363 class WindowDestroyer : public content::WebContentsObserver {
364 public:
365 WindowDestroyer(content::WebContents* web_contents, TabStripModel* model)
366 : content::WebContentsObserver(web_contents),
367 tab_strip_model_(model) {
368 }
369
370 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
371 LOG(ERROR) << "WD::RenderViewGone";
Charlie Reis 2013/07/01 17:16:42 Remove log statements?
nasko 2013/07/01 23:08:42 Done.
372 content::WindowedNotificationObserver observer(
373 chrome::NOTIFICATION_WINDOW_CLOSED,
374 content::NotificationService::AllSources());
375 LOG(ERROR) << "WD::RenderViewGone: observer created.";
376 tab_strip_model_->CloseAllTabs();
377 LOG(ERROR) << "WD::RenderViewGone: Closed all tabs, waiting for window.";
378 observer.Wait();
379 LOG(ERROR) << "WD::RenderViewGone: Closed window.";
380 }
381
382 private:
383 TabStripModel* tab_strip_model_;
384 };
385
386 // Test to ensure that while iterating through all listeners in
387 // RenderProcessHost and they are invalidated, we remove them properly and don't
Charlie Reis 2013/07/01 17:16:42 nit: and they are invalidated -> and invalidating
nasko 2013/07/01 23:08:42 Done.
388 // access already freed objects. See http://crbug.com/255524
Charlie Reis 2013/07/01 17:16:42 nit: End with a period.
nasko 2013/07/01 23:08:42 Done.
389 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest,
390 CloseAllTabsDuringProcessDied) {
391 GURL url(chrome::kChromeUINewTabURL);
392
393 ui_test_utils::NavigateToURL(browser(), url);
394 ui_test_utils::NavigateToURLWithDisposition(
395 browser(), url, NEW_BACKGROUND_TAB,
396 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
397
398 EXPECT_EQ(2, browser()->tab_strip_model()->count());
399
400 WebContents* wc1 = browser()->tab_strip_model()->GetWebContentsAt(0);
401 WebContents* wc2 = browser()->tab_strip_model()->GetWebContentsAt(1);
402 EXPECT_EQ(wc1->GetRenderProcessHost(), wc2->GetRenderProcessHost());
403
404 // Create an object that will close the window on a process crash.
405 WindowDestroyer destroyer(wc1, browser()->tab_strip_model());
406
407 content::WindowedNotificationObserver observer(
408 chrome::NOTIFICATION_WINDOW_CLOSED,
409 content::NotificationService::AllSources());
410
411 // Kill the renderer process, simulating a crash. This should the ProcessDied
412 // method to be called. Alternatively, RenderProcessHost::OnChannelError can
413 // be called to directly force a call to ProcessDied.
414 base::KillProcess(wc1->GetRenderProcessHost()->GetHandle(), -1, true);
415
416 observer.Wait();
417 }
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