Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 14 matching lines...) Expand all Loading... | |
| 25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/render_widget_host.h" | 26 #include "content/public/browser/render_widget_host.h" |
| 27 #include "content/public/browser/render_widget_host_iterator.h" | 27 #include "content/public/browser/render_widget_host_iterator.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/browser/web_contents_observer.h" | 29 #include "content/public/browser/web_contents_observer.h" |
| 30 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 31 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
| 32 #include "net/base/filename_util.h" | 32 #include "net/base/filename_util.h" |
| 33 #include "net/test/embedded_test_server/embedded_test_server.h" | 33 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 34 | 34 |
| 35 #if defined(OS_MACOSX) | |
| 36 #include "content/public/browser/browser_child_process_host.h" | |
| 37 #endif // defined(OS_MACOSX) | |
| 38 | |
| 35 using content::RenderViewHost; | 39 using content::RenderViewHost; |
| 36 using content::RenderWidgetHost; | 40 using content::RenderWidgetHost; |
| 37 using content::WebContents; | 41 using content::WebContents; |
| 38 | 42 |
| 39 namespace { | 43 namespace { |
| 40 | 44 |
| 41 int RenderProcessHostCount() { | 45 int RenderProcessHostCount() { |
| 42 content::RenderProcessHost::iterator hosts = | 46 content::RenderProcessHost::iterator hosts = |
| 43 content::RenderProcessHost::AllHostsIterator(); | 47 content::RenderProcessHost::AllHostsIterator(); |
| 44 int count = 0; | 48 int count = 0; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 // Create another omnibox tab. It should share the process with the other | 293 // Create another omnibox tab. It should share the process with the other |
| 290 // WebUI. | 294 // WebUI. |
| 291 ui_test_utils::NavigateToURLWithDisposition( | 295 ui_test_utils::NavigateToURLWithDisposition( |
| 292 browser(), omnibox, WindowOpenDisposition::NEW_FOREGROUND_TAB, | 296 browser(), omnibox, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 293 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 297 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 294 tab_count++; | 298 tab_count++; |
| 295 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); | 299 EXPECT_EQ(tab_count, browser()->tab_strip_model()->count()); |
| 296 EXPECT_EQ(host_count, RenderProcessHostCount()); | 300 EXPECT_EQ(host_count, RenderProcessHostCount()); |
| 297 } | 301 } |
| 298 | 302 |
| 299 // We don't change process priorities on Mac or Posix because the user lacks the | 303 // We don't change process priorities on Posix because the user lacks the |
| 300 // permission to raise a process' priority even after lowering it. | 304 // permission to raise a process' priority even after lowering it. |
| 301 #if defined(OS_WIN) || defined(OS_LINUX) | 305 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) |
| 302 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) { | 306 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostTest, Backgrounding) { |
| 303 if (!base::Process::CanBackgroundProcesses()) { | 307 if (!base::Process::CanBackgroundProcesses()) { |
| 304 LOG(ERROR) << "Can't background processes"; | 308 LOG(ERROR) << "Can't background processes"; |
| 305 return; | 309 return; |
| 306 } | 310 } |
| 311 #if defined(OS_MACOSX) | |
| 312 base::PortProvider* port_provider = | |
| 313 content::BrowserChildProcessHost::GetPortProvider(); | |
| 314 #endif // defined(OS_MACOSX) | |
| 315 | |
| 307 base::CommandLine& parsed_command_line = | 316 base::CommandLine& parsed_command_line = |
| 308 *base::CommandLine::ForCurrentProcess(); | 317 *base::CommandLine::ForCurrentProcess(); |
| 309 parsed_command_line.AppendSwitch(switches::kProcessPerTab); | 318 parsed_command_line.AppendSwitch(switches::kProcessPerTab); |
| 310 | 319 |
| 311 // Change the first tab to be the omnibox page (TYPE_WEBUI). | 320 // Change the first tab to be the omnibox page (TYPE_WEBUI). |
| 312 GURL omnibox(chrome::kChromeUIOmniboxURL); | 321 GURL omnibox(chrome::kChromeUIOmniboxURL); |
| 313 ui_test_utils::NavigateToURL(browser(), omnibox); | 322 ui_test_utils::NavigateToURL(browser(), omnibox); |
| 314 | 323 |
| 315 // Create a new tab. It should be foreground. | 324 // Create a new tab. It should be foreground. |
| 316 GURL page1("data:text/html,hello world1"); | 325 GURL page1("data:text/html,hello world1"); |
| 317 base::Process process1 = ShowSingletonTab(page1); | 326 base::Process process1 = ShowSingletonTab(page1); |
| 318 ASSERT_TRUE(process1.IsValid()); | 327 ASSERT_TRUE(process1.IsValid()); |
| 328 #if defined(OS_MACOSX) | |
| 329 EXPECT_FALSE(process1.IsProcessBackgrounded(port_provider)); | |
| 330 #else | |
| 319 EXPECT_FALSE(process1.IsProcessBackgrounded()); | 331 EXPECT_FALSE(process1.IsProcessBackgrounded()); |
| 332 #endif | |
| 320 | 333 |
| 321 // Create another tab. It should be foreground, and the first tab should | 334 // Create another tab. It should be foreground, and the first tab should |
| 322 // now be background. | 335 // now be background. |
| 323 GURL page2("data:text/html,hello world2"); | 336 GURL page2("data:text/html,hello world2"); |
| 324 base::Process process2 = ShowSingletonTab(page2); | 337 base::Process process2 = ShowSingletonTab(page2); |
| 325 ASSERT_TRUE(process2.IsValid()); | 338 ASSERT_TRUE(process2.IsValid()); |
| 326 EXPECT_NE(process1.Pid(), process2.Pid()); | 339 EXPECT_NE(process1.Pid(), process2.Pid()); |
| 340 #if defined(OS_MACOSX) | |
| 341 EXPECT_TRUE(process1.IsProcessBackgrounded(port_provider)); | |
| 342 EXPECT_FALSE(process2.IsProcessBackgrounded(port_provider)); | |
| 343 #else | |
| 327 EXPECT_TRUE(process1.IsProcessBackgrounded()); | 344 EXPECT_TRUE(process1.IsProcessBackgrounded()); |
| 328 EXPECT_FALSE(process2.IsProcessBackgrounded()); | 345 EXPECT_FALSE(process2.IsProcessBackgrounded()); |
| 346 #endif // defined(OS_MACOSX) | |
| 329 | 347 |
| 330 // Load another tab in background. The renderer of the new tab should be | 348 // Load another tab in background. The renderer of the new tab should be |
| 331 // backgrounded, while visibility of the other renderers should not change. | 349 // backgrounded, while visibility of the other renderers should not change. |
| 332 GURL page3("data:text/html,hello world3"); | 350 GURL page3("data:text/html,hello world3"); |
| 333 base::Process process3 = OpenBackgroundTab(page3); | 351 base::Process process3 = OpenBackgroundTab(page3); |
| 334 ASSERT_TRUE(process3.IsValid()); | 352 ASSERT_TRUE(process3.IsValid()); |
| 335 EXPECT_NE(process3.Pid(), process1.Pid()); | 353 EXPECT_NE(process3.Pid(), process1.Pid()); |
| 336 EXPECT_NE(process3.Pid(), process2.Pid()); | 354 EXPECT_NE(process3.Pid(), process2.Pid()); |
| 355 #if defined(OS_MACOSX) | |
| 356 EXPECT_TRUE(process1.IsProcessBackgrounded(port_provider)); | |
| 357 EXPECT_FALSE(process2.IsProcessBackgrounded(port_provider)); | |
| 358 // TODO(gab): The new background tab should be backgrounded but it currently | |
| 359 // intentionally isn't per a workaround to https://crbug.com/560446 in | |
| 360 // RenderProcessHostImpl::OnProcessLaunched(). | |
| 361 EXPECT_FALSE(process3.IsProcessBackgrounded(port_provider)); | |
| 362 | |
| 363 // Navigate back to the first page. Its renderer should be in foreground | |
| 364 // again while the other renderers should be backgrounded. | |
| 365 | |
| 366 EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid()); | |
| 367 EXPECT_FALSE(process1.IsProcessBackgrounded(port_provider)); | |
| 368 EXPECT_TRUE(process2.IsProcessBackgrounded(port_provider)); | |
| 369 // TODO(gab): Same as above. | |
| 370 EXPECT_FALSE(process3.IsProcessBackgrounded(port_provider)); | |
| 371 | |
| 372 // TODO(gab): Remove this when https://crbug.com/560446 is fixed, but for now | |
| 373 // confirm that the correct state is at least achieved when tab #3 is | |
| 374 // explicitly foregrounded and re-backgrounded. | |
| 375 EXPECT_EQ(process3.Pid(), ShowSingletonTab(page3).Pid()); | |
| 376 EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid()); | |
| 377 EXPECT_FALSE(process1.IsProcessBackgrounded(port_provider)); | |
| 378 EXPECT_TRUE(process2.IsProcessBackgrounded(port_provider)); | |
| 379 EXPECT_TRUE(process3.IsProcessBackgrounded(port_provider)); | |
| 380 #else | |
| 337 EXPECT_TRUE(process1.IsProcessBackgrounded()); | 381 EXPECT_TRUE(process1.IsProcessBackgrounded()); |
| 338 EXPECT_FALSE(process2.IsProcessBackgrounded()); | 382 EXPECT_FALSE(process2.IsProcessBackgrounded()); |
| 339 // TODO(gab): The new background tab should be backgrounded but it currently | 383 // TODO(gab): The new background tab should be backgrounded but it currently |
| 340 // intentionally isn't per a workaround to https://crbug.com/560446 in | 384 // intentionally isn't per a workaround to https://crbug.com/560446 in |
| 341 // RenderProcessHostImpl::OnProcessLaunched(). | 385 // RenderProcessHostImpl::OnProcessLaunched(). |
| 342 EXPECT_FALSE(process3.IsProcessBackgrounded()); | 386 EXPECT_FALSE(process3.IsProcessBackgrounded()); |
| 343 | 387 |
| 344 // Navigate back to the first page. Its renderer should be in foreground | 388 // Navigate back to the first page. Its renderer should be in foreground |
| 345 // again while the other renderers should be backgrounded. | 389 // again while the other renderers should be backgrounded. |
| 390 | |
| 346 EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid()); | 391 EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid()); |
| 347 EXPECT_FALSE(process1.IsProcessBackgrounded()); | 392 EXPECT_FALSE(process1.IsProcessBackgrounded()); |
| 348 EXPECT_TRUE(process2.IsProcessBackgrounded()); | 393 EXPECT_TRUE(process2.IsProcessBackgrounded()); |
| 349 // TODO(gab): Same as above. | 394 // TODO(gab): Same as above. |
| 350 EXPECT_FALSE(process3.IsProcessBackgrounded()); | 395 EXPECT_FALSE(process3.IsProcessBackgrounded()); |
| 351 | 396 |
| 352 // TODO(gab): Remove this when https://crbug.com/560446 is fixed, but for now | 397 // TODO(gab): Remove this when https://crbug.com/560446 is fixed, but for now |
| 353 // confirm that the correct state is at least achieved when tab #3 is | 398 // confirm that the correct state is at least achieved when tab #3 is |
| 354 // explicitly foregrounded and re-backgrounded. | 399 // explicitly foregrounded and re-backgrounded. |
| 355 EXPECT_EQ(process3.Pid(), ShowSingletonTab(page3).Pid()); | 400 EXPECT_EQ(process3.Pid(), ShowSingletonTab(page3).Pid()); |
| 356 EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid()); | 401 EXPECT_EQ(process1.Pid(), ShowSingletonTab(page1).Pid()); |
| 357 EXPECT_FALSE(process1.IsProcessBackgrounded()); | 402 EXPECT_FALSE(process1.IsProcessBackgrounded()); |
| 358 EXPECT_TRUE(process2.IsProcessBackgrounded()); | 403 EXPECT_TRUE(process2.IsProcessBackgrounded()); |
| 359 EXPECT_TRUE(process3.IsProcessBackgrounded()); | 404 EXPECT_TRUE(process3.IsProcessBackgrounded()); |
| 405 #endif | |
| 360 } | 406 } |
| 361 #endif | 407 #endif |
| 362 | 408 |
| 363 // TODO(nasko): crbug.com/173137 | 409 // TODO(nasko): crbug.com/173137 |
| 364 // Disable on Windows and Mac due to ongoing flakiness. (crbug.com/442785) | 410 // Disable on Windows and Mac due to ongoing flakiness. (crbug.com/442785) |
| 365 #if defined(OS_WIN) || defined(OS_MACOSX) | 411 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 366 #define MAYBE_ProcessOverflow DISABLED_ProcessOverflow | 412 #define MAYBE_ProcessOverflow DISABLED_ProcessOverflow |
| 367 #else | 413 #else |
| 368 #define MAYBE_ProcessOverflow ProcessOverflow | 414 #define MAYBE_ProcessOverflow ProcessOverflow |
| 369 #endif | 415 #endif |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest, | 642 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest, |
| 597 ProcessPriorityAfterStoppedAudio) { | 643 ProcessPriorityAfterStoppedAudio) { |
| 598 // This test is invalid on platforms that can't background. | 644 // This test is invalid on platforms that can't background. |
| 599 if (!base::Process::CanBackgroundProcesses()) | 645 if (!base::Process::CanBackgroundProcesses()) |
| 600 return; | 646 return; |
| 601 | 647 |
| 602 ShowSingletonTab(audio_url_); | 648 ShowSingletonTab(audio_url_); |
| 603 | 649 |
| 604 // Wait until the no audio page is backgrounded and the audio page is not | 650 // Wait until the no audio page is backgrounded and the audio page is not |
| 605 // backgrounded. | 651 // backgrounded. |
| 652 #if defined(OS_MACOSX) | |
| 653 base::PortProvider* port_provider = | |
| 654 content::BrowserChildProcessHost::GetPortProvider(); | |
| 655 while (!no_audio_process_.IsProcessBackgrounded(port_provider) || | |
| 656 audio_process_.IsProcessBackgrounded(port_provider)) { | |
| 657 base::RunLoop().RunUntilIdle(); | |
| 658 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
| 659 } | |
| 660 #else | |
| 606 while (!no_audio_process_.IsProcessBackgrounded() || | 661 while (!no_audio_process_.IsProcessBackgrounded() || |
| 607 audio_process_.IsProcessBackgrounded()) { | 662 audio_process_.IsProcessBackgrounded()) { |
| 608 base::RunLoop().RunUntilIdle(); | 663 base::RunLoop().RunUntilIdle(); |
| 609 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 664 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 610 } | 665 } |
| 611 | 666 #endif // defined(OS_MACOSX) |
| 612 // Pause the audio and immediately switch to the no audio tab. | 667 // Pause the audio and immediately switch to the no audio tab. |
| 613 ASSERT_TRUE(content::ExecuteScript( | 668 ASSERT_TRUE(content::ExecuteScript( |
| 614 audio_tab_web_contents_, | 669 audio_tab_web_contents_, |
| 615 "document.getElementById('audioPlayer').pause();")); | 670 "document.getElementById('audioPlayer').pause();")); |
| 616 ShowSingletonTab(no_audio_url_); | 671 ShowSingletonTab(no_audio_url_); |
| 617 | 672 |
| 618 // Wait until the no audio page is not backgrounded and the audio page is | 673 // Wait until the no audio page is not backgrounded and the audio page is |
| 619 // backgrounded. | 674 // backgrounded. |
| 675 #if defined(OS_MACOSX) | |
| 676 while (no_audio_process_.IsProcessBackgrounded(port_provider) || | |
| 677 !audio_process_.IsProcessBackgrounded(port_provider)) { | |
| 678 base::RunLoop().RunUntilIdle(); | |
| 679 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
| 680 } | |
| 681 #else | |
| 620 while (no_audio_process_.IsProcessBackgrounded() || | 682 while (no_audio_process_.IsProcessBackgrounded() || |
| 621 !audio_process_.IsProcessBackgrounded()) { | 683 !audio_process_.IsProcessBackgrounded()) { |
| 622 base::RunLoop().RunUntilIdle(); | 684 base::RunLoop().RunUntilIdle(); |
| 623 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 685 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 624 } | 686 } |
| 687 #endif // defined(OS_MACOSX) | |
| 625 } | 688 } |
| 626 | 689 |
| 627 // Test to make sure that a process is backgrounded automatically when audio | 690 // Test to make sure that a process is backgrounded automatically when audio |
| 628 // stops playing from a hidden tab. | 691 // stops playing from a hidden tab. |
| 629 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest, | 692 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest, |
| 630 ProcessPriorityAfterAudioStopsOnNotVisibleTab) { | 693 ProcessPriorityAfterAudioStopsOnNotVisibleTab) { |
| 631 // This test is invalid on platforms that can't background. | 694 // This test is invalid on platforms that can't background. |
| 632 if (!base::Process::CanBackgroundProcesses()) | 695 if (!base::Process::CanBackgroundProcesses()) |
| 633 return; | 696 return; |
| 634 | 697 |
| 635 // Wait until the two pages are not backgrounded. | 698 // Wait until the two pages are not backgrounded. |
| 699 #if defined(OS_MACOSX) | |
| 700 base::PortProvider* port_provider = | |
| 701 content::BrowserChildProcessHost::GetPortProvider(); | |
| 702 while (no_audio_process_.IsProcessBackgrounded(port_provider) || | |
| 703 audio_process_.IsProcessBackgrounded(port_provider)) { | |
| 704 base::RunLoop().RunUntilIdle(); | |
| 705 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
| 706 } | |
| 707 #else | |
| 636 while (no_audio_process_.IsProcessBackgrounded() || | 708 while (no_audio_process_.IsProcessBackgrounded() || |
| 637 audio_process_.IsProcessBackgrounded()) { | 709 audio_process_.IsProcessBackgrounded()) { |
| 638 base::RunLoop().RunUntilIdle(); | 710 base::RunLoop().RunUntilIdle(); |
| 639 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 711 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 640 } | 712 } |
| 713 #endif // defined(OS_MACOSX) | |
| 641 | 714 |
| 642 // Stop the audio. | 715 // Stop the audio. |
| 643 ASSERT_TRUE(content::ExecuteScript( | 716 ASSERT_TRUE(content::ExecuteScript( |
| 644 audio_tab_web_contents_, | 717 audio_tab_web_contents_, |
| 645 "document.getElementById('audioPlayer').pause();")); | 718 "document.getElementById('audioPlayer').pause();")); |
| 646 | 719 |
| 647 // Wait until the no audio page is not backgrounded and the audio page is | 720 // Wait until the no audio page is not backgrounded and the audio page is |
| 648 // backgrounded. | 721 // backgrounded. |
| 722 #if defined(OS_MACOSX) | |
| 723 while (no_audio_process_.IsProcessBackgrounded(port_provider) || | |
| 724 !audio_process_.IsProcessBackgrounded(port_provider)) { | |
| 725 base::RunLoop().RunUntilIdle(); | |
| 726 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
| 727 } | |
| 728 #else | |
| 649 while (no_audio_process_.IsProcessBackgrounded() || | 729 while (no_audio_process_.IsProcessBackgrounded() || |
| 650 !audio_process_.IsProcessBackgrounded()) { | 730 !audio_process_.IsProcessBackgrounded()) { |
| 651 base::RunLoop().RunUntilIdle(); | 731 base::RunLoop().RunUntilIdle(); |
| 652 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 732 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 653 } | 733 } |
| 734 #endif // defined(OS_MACOSX) | |
| 654 } | 735 } |
| 655 | 736 |
| 656 // Test to make sure that a process is un-backgrounded automatically when audio | 737 // Test to make sure that a process is un-backgrounded automatically when |
| 738 // audio | |
| 657 // starts playing from a backgrounded tab. | 739 // starts playing from a backgrounded tab. |
| 658 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest, | 740 IN_PROC_BROWSER_TEST_F(ChromeRenderProcessHostBackgroundingTest, |
| 659 ProcessPriorityAfterAudioStartsFromBackgroundTab) { | 741 ProcessPriorityAfterAudioStartsFromBackgroundTab) { |
| 660 // This test is invalid on platforms that can't background. | 742 // This test is invalid on platforms that can't background. |
| 661 if (!base::Process::CanBackgroundProcesses()) | 743 if (!base::Process::CanBackgroundProcesses()) |
| 662 return; | 744 return; |
| 663 | 745 |
| 664 // Stop the audio. | 746 // Stop the audio. |
| 665 ASSERT_TRUE(content::ExecuteScript( | 747 ASSERT_TRUE(content::ExecuteScript( |
| 666 audio_tab_web_contents_, | 748 audio_tab_web_contents_, |
| 667 "document.getElementById('audioPlayer').pause();")); | 749 "document.getElementById('audioPlayer').pause();")); |
| 668 | 750 |
| 669 // Wait until the no audio page is not backgrounded and the audio page is | 751 // Wait until the no audio page is not backgrounded and the audio page is |
| 670 // backgrounded. | 752 // backgrounded. |
| 753 #if defined(OS_MACOSX) | |
|
Robert Sesek
2016/11/03 20:18:42
You could refactor this whole block into a protect
lgrey
2016/11/04 16:09:40
Done.
| |
| 754 base::PortProvider* port_provider = | |
| 755 content::BrowserChildProcessHost::GetPortProvider(); | |
| 756 while (no_audio_process_.IsProcessBackgrounded(port_provider) || | |
| 757 !audio_process_.IsProcessBackgrounded(port_provider)) { | |
| 758 base::RunLoop().RunUntilIdle(); | |
| 759 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
| 760 } | |
| 761 #else | |
| 671 while (no_audio_process_.IsProcessBackgrounded() || | 762 while (no_audio_process_.IsProcessBackgrounded() || |
| 672 !audio_process_.IsProcessBackgrounded()) { | 763 !audio_process_.IsProcessBackgrounded()) { |
| 673 base::RunLoop().RunUntilIdle(); | 764 base::RunLoop().RunUntilIdle(); |
| 674 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 765 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 675 } | 766 } |
| 767 #endif // defined(OS_MACOSX) | |
| 676 | 768 |
| 677 // Start the audio from the backgrounded tab. | 769 // Start the audio from the backgrounded tab. |
| 678 ASSERT_TRUE( | 770 ASSERT_TRUE( |
| 679 content::ExecuteScript(audio_tab_web_contents_, | 771 content::ExecuteScript(audio_tab_web_contents_, |
| 680 "document.getElementById('audioPlayer').play();")); | 772 "document.getElementById('audioPlayer').play();")); |
| 681 | 773 |
| 682 // Wait until the two pages are not backgrounded. | 774 // Wait until the two pages are not backgrounded. |
| 775 #if defined(OS_MACOSX) | |
| 776 while (no_audio_process_.IsProcessBackgrounded(port_provider) || | |
| 777 audio_process_.IsProcessBackgrounded(port_provider)) { | |
| 778 base::RunLoop().RunUntilIdle(); | |
| 779 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | |
| 780 } | |
| 781 #else | |
| 683 while (no_audio_process_.IsProcessBackgrounded() || | 782 while (no_audio_process_.IsProcessBackgrounded() || |
| 684 audio_process_.IsProcessBackgrounded()) { | 783 audio_process_.IsProcessBackgrounded()) { |
| 685 base::RunLoop().RunUntilIdle(); | 784 base::RunLoop().RunUntilIdle(); |
| 686 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 785 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 687 } | 786 } |
| 787 #endif // defined(OS_MACOSX) | |
| 688 } | 788 } |
| OLD | NEW |