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

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

Issue 2701473007: Switch WindowedNotificationObserver to use base::RunLoop. (Closed)
Patch Set: Mention the bug; remove deferred quit in WaitForCondition. Created 3 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
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), tab_strip_model_(model) {} 528 : content::WebContentsObserver(web_contents),
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(); }
529 535
530 void RenderProcessGone(base::TerminationStatus status) override { 536 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();
539 } 538 }
540 539
541 private: 540 private:
542 TabStripModel* tab_strip_model_; 541 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
579 // Kill the renderer process, simulating a crash. This should the ProcessDied 575 // Kill the renderer process, simulating a crash. This should the ProcessDied
580 // method to be called. Alternatively, RenderProcessHost::OnChannelError can 576 // method to be called. Alternatively, RenderProcessHost::OnChannelError can
581 // be called to directly force a call to ProcessDied. 577 // be called to directly force a call to ProcessDied.
582 wc1->GetRenderProcessHost()->Shutdown(-1, true); 578 wc1->GetRenderProcessHost()->Shutdown(-1, true);
583 579
584 observer.Wait(); 580 destroyer.Wait();
585 } 581 }
586 582
587 // Sets up the browser in order to start the tests with two tabs open: one 583 // Sets up the browser in order to start the tests with two tabs open: one
588 // called "no audio" in foreground and another called "audio" in background with 584 // called "no audio" in foreground and another called "audio" in background with
589 // audio in playing state. Also sets up the variables containing the process 585 // audio in playing state. Also sets up the variables containing the process
590 // associated with each tab, the urls of the two pages and the WebContents of 586 // associated with each tab, the urls of the two pages and the WebContents of
591 // the "audio" page. 587 // the "audio" page.
592 class ChromeRenderProcessHostBackgroundingTest 588 class ChromeRenderProcessHostBackgroundingTest
593 : public ChromeRenderProcessHostTest { 589 : public ChromeRenderProcessHostTest {
594 public: 590 public:
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, true); 722 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, true);
727 723
728 // Start the audio from the backgrounded tab. 724 // Start the audio from the backgrounded tab.
729 ASSERT_TRUE( 725 ASSERT_TRUE(
730 content::ExecuteScript(audio_tab_web_contents_, 726 content::ExecuteScript(audio_tab_web_contents_,
731 "document.getElementById('audioPlayer').play();")); 727 "document.getElementById('audioPlayer').play();"));
732 728
733 // Wait until the two pages are not backgrounded. 729 // Wait until the two pages are not backgrounded.
734 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, false); 730 WaitUntilBackgrounded(no_audio_process_, false, audio_process_, false);
735 } 731 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_manager_test.cc ('k') | chrome/browser/ui/login/login_handler_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698