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

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

Issue 2828403002: Revert of Revert "Revert of Reland: Switch WindowedNotificationObserver to use base::RunLoop.... (Closed)
Patch Set: Created 3 years, 8 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
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/macros.h" 6 #include "base/macros.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/process/process.h" 8 #include "base/process/process.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 chrome::ToggleDevToolsWindow(browser(), DevToolsToggleAction::Toggle()); 518 chrome::ToggleDevToolsWindow(browser(), DevToolsToggleAction::Toggle());
519 close_observer.Wait(); 519 close_observer.Wait();
520 } 520 }
521 521
522 // This class's goal is to close the browser window when a renderer process has 522 // This class's goal is to close the browser window when a renderer process has
523 // crashed. It does so by monitoring WebContents for RenderProcessGone event and 523 // crashed. It does so by monitoring WebContents for RenderProcessGone event and
524 // closing the passed in TabStripModel. This is used in the following test case. 524 // closing the passed in TabStripModel. This is used in the following test case.
525 class WindowDestroyer : public content::WebContentsObserver { 525 class WindowDestroyer : public content::WebContentsObserver {
526 public: 526 public:
527 WindowDestroyer(content::WebContents* web_contents, TabStripModel* model) 527 WindowDestroyer(content::WebContents* web_contents, TabStripModel* model)
528 : content::WebContentsObserver(web_contents), 528 : content::WebContentsObserver(web_contents), tab_strip_model_(model) {}
529 tab_strip_model_(model),
530 browser_closed_observer_(chrome::NOTIFICATION_BROWSER_CLOSED,
531 content::NotificationService::AllSources()) {}
532
533 // Wait for the browser window to be destroyed.
534 void Wait() { browser_closed_observer_.Wait(); }
535 529
536 void RenderProcessGone(base::TerminationStatus status) override { 530 void RenderProcessGone(base::TerminationStatus status) override {
531 // Wait for the window to be destroyed, which will ensure all other
532 // RenderViewHost objects are deleted before we return and proceed with
533 // the next iteration of notifications.
534 content::WindowedNotificationObserver observer(
535 chrome::NOTIFICATION_BROWSER_CLOSED,
536 content::NotificationService::AllSources());
537 tab_strip_model_->CloseAllTabs(); 537 tab_strip_model_->CloseAllTabs();
538 observer.Wait();
538 } 539 }
539 540
540 private: 541 private:
541 TabStripModel* tab_strip_model_; 542 TabStripModel* tab_strip_model_;
542 content::WindowedNotificationObserver browser_closed_observer_;
543 543
544 DISALLOW_COPY_AND_ASSIGN(WindowDestroyer); 544 DISALLOW_COPY_AND_ASSIGN(WindowDestroyer);
545 }; 545 };
546 546
547 // Test to ensure that while iterating through all listeners in 547 // Test to ensure that while iterating through all listeners in
548 // RenderProcessHost and invalidating them, we remove them properly and don't 548 // RenderProcessHost and invalidating them, we remove them properly and don't
549 // access already freed objects. See http://crbug.com/255524. 549 // access already freed objects. See http://crbug.com/255524.
550 // Crashes on Win/Linux only. http://crbug.com/606485. 550 // Crashes on Win/Linux only. http://crbug.com/606485.
551 #if defined(OS_WIN) || defined(OS_LINUX) 551 #if defined(OS_WIN) || defined(OS_LINUX)
552 #define MAYBE_CloseAllTabsDuringProcessDied \ 552 #define MAYBE_CloseAllTabsDuringProcessDied \
(...skipping 12 matching lines...) Expand all
565 565
566 EXPECT_EQ(2, browser()->tab_strip_model()->count()); 566 EXPECT_EQ(2, browser()->tab_strip_model()->count());
567 567
568 WebContents* wc1 = browser()->tab_strip_model()->GetWebContentsAt(0); 568 WebContents* wc1 = browser()->tab_strip_model()->GetWebContentsAt(0);
569 WebContents* wc2 = browser()->tab_strip_model()->GetWebContentsAt(1); 569 WebContents* wc2 = browser()->tab_strip_model()->GetWebContentsAt(1);
570 EXPECT_EQ(wc1->GetRenderProcessHost(), wc2->GetRenderProcessHost()); 570 EXPECT_EQ(wc1->GetRenderProcessHost(), wc2->GetRenderProcessHost());
571 571
572 // Create an object that will close the window on a process crash. 572 // Create an object that will close the window on a process crash.
573 WindowDestroyer destroyer(wc1, browser()->tab_strip_model()); 573 WindowDestroyer destroyer(wc1, browser()->tab_strip_model());
574 574
575 content::WindowedNotificationObserver observer(
576 chrome::NOTIFICATION_BROWSER_CLOSED,
577 content::NotificationService::AllSources());
578
575 // Kill the renderer process, simulating a crash. This should the ProcessDied 579 // Kill the renderer process, simulating a crash. This should the ProcessDied
576 // method to be called. Alternatively, RenderProcessHost::OnChannelError can 580 // method to be called. Alternatively, RenderProcessHost::OnChannelError can
577 // be called to directly force a call to ProcessDied. 581 // be called to directly force a call to ProcessDied.
578 wc1->GetRenderProcessHost()->Shutdown(-1, true); 582 wc1->GetRenderProcessHost()->Shutdown(-1, true);
579 583
580 destroyer.Wait(); 584 observer.Wait();
581 } 585 }
582 586
583 // Sets up the browser in order to start the tests with two tabs open: one 587 // Sets up the browser in order to start the tests with two tabs open: one
584 // called "no audio" in foreground and another called "audio" in background with 588 // called "no audio" in foreground and another called "audio" in background with
585 // audio in playing state. Also sets up the variables containing the process 589 // audio in playing state. Also sets up the variables containing the process
586 // associated with each tab, the urls of the two pages and the WebContents of 590 // associated with each tab, the urls of the two pages and the WebContents of
587 // the "audio" page. 591 // the "audio" page.
588 class ChromeRenderProcessHostBackgroundingTest 592 class ChromeRenderProcessHostBackgroundingTest
589 : public ChromeRenderProcessHostTest { 593 : public ChromeRenderProcessHostTest {
590 public: 594 public:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, true); 726 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, true);
723 727
724 // Start the audio from the backgrounded tab. 728 // Start the audio from the backgrounded tab.
725 ASSERT_TRUE( 729 ASSERT_TRUE(
726 content::ExecuteScript(audio_tab_web_contents_, 730 content::ExecuteScript(audio_tab_web_contents_,
727 "document.getElementById('audioPlayer').play();")); 731 "document.getElementById('audioPlayer').play();"));
728 732
729 // Wait until the two pages are not backgrounded. 733 // Wait until the two pages are not backgrounded.
730 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, false); 734 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, false);
731 } 735 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698