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