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

Side by Side Diff: chrome/browser/ui/fullscreen/fullscreen_controller_state_unittest.cc

Issue 158253002: Tabs being screen-captured will fullscreen within their tab contents area. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed scheib's review comments. Rebased. Created 6 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 | Annotate | Revision Log
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 "build/build_config.h" 6 #include "build/build_config.h"
6 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/browser_tabstrip.h" 8 #include "chrome/browser/ui/browser_tabstrip.h"
8 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" 9 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
9 #include "chrome/browser/ui/fullscreen/fullscreen_controller_state_test.h" 10 #include "chrome/browser/ui/fullscreen/fullscreen_controller_state_test.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_switches.h"
11 #include "chrome/test/base/browser_with_test_window_test.h" 13 #include "chrome/test/base/browser_with_test_window_test.h"
12 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_view.h"
13 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
14 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
15 18
16 // The FullscreenControllerStateUnitTest unit test suite exhastively tests 19 // The FullscreenControllerStateUnitTest unit test suite exhastively tests
17 // the FullscreenController through all permutations of events. The behavior 20 // the FullscreenController through all permutations of events. The behavior
18 // of the BrowserWindow is mocked via FullscreenControllerTestWindow. 21 // of the BrowserWindow is mocked via FullscreenControllerTestWindow.
19 22
20 23
21 // FullscreenControllerTestWindow ---------------------------------------------- 24 // FullscreenControllerTestWindow ----------------------------------------------
22 25
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 ASSERT_TRUE(browser()->window()->IsFullscreen()); 469 ASSERT_TRUE(browser()->window()->IsFullscreen());
467 470
468 content::WebContents* new_web_contents = content::WebContents::Create( 471 content::WebContents* new_web_contents = content::WebContents::Create(
469 content::WebContents::CreateParams(profile())); 472 content::WebContents::CreateParams(profile()));
470 scoped_ptr<content::WebContents> old_web_contents( 473 scoped_ptr<content::WebContents> old_web_contents(
471 browser()->tab_strip_model()->ReplaceWebContentsAt( 474 browser()->tab_strip_model()->ReplaceWebContentsAt(
472 0, new_web_contents)); 475 0, new_web_contents));
473 ChangeWindowFullscreenState(); 476 ChangeWindowFullscreenState();
474 EXPECT_FALSE(browser()->window()->IsFullscreen()); 477 EXPECT_FALSE(browser()->window()->IsFullscreen());
475 } 478 }
479
480 // Tests that, in a browser configured for Fullscreen-Within-Tab mode,
481 // fullscreening a screen-captured tab will NOT cause any fullscreen state
482 // change to the browser window. Furthermore, the test switches between tabs to
483 // confirm a captured tab will be resized by FullscreenController to the capture
484 // video resolution once the widget is detached from the UI.
485 //
486 // See 'FullscreenWithinTab Note' in fullscreen_controller.h.
487 TEST_F(FullscreenControllerStateUnitTest, OneCapturedFullscreenedTab) {
488 CommandLine::ForCurrentProcess()->
489 AppendSwitch(switches::kEmbedFlashFullscreen);
490 content::WebContentsDelegate* const wc_delegate =
491 static_cast<content::WebContentsDelegate*>(browser());
492 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget());
493
494 AddTab(browser(), GURL(content::kAboutBlankURL));
495 AddTab(browser(), GURL(content::kAboutBlankURL));
496 content::WebContents* const first_tab =
497 browser()->tab_strip_model()->GetWebContentsAt(0);
498 content::WebContents* const second_tab =
499 browser()->tab_strip_model()->GetWebContentsAt(1);
500
501 // Activate the first tab and tell its WebContents it is being captured.
502 browser()->tab_strip_model()->ActivateTabAt(0, true);
503 const gfx::Size kCaptureSize(1280, 720);
504 first_tab->IncrementCapturerCount(kCaptureSize);
505 ASSERT_FALSE(browser()->window()->IsFullscreen());
506 ASSERT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
507 ASSERT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
508 ASSERT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
509
510 // Enter tab fullscreen. Since the tab is being captured, the browser window
511 // should not expand to fill the screen.
512 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
513 EXPECT_FALSE(browser()->window()->IsFullscreen());
514 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
515 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
516 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
517
518 // Switch to the other tab. Check that the first tab was resized to the
519 // WebContents' preferred size.
520 browser()->tab_strip_model()->ActivateTabAt(1, true);
521 EXPECT_FALSE(browser()->window()->IsFullscreen());
522 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
523 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
524 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
525 // TODO(miu): Need to make an adjustment to content::WebContentsViewMac for
miu 2014/02/12 08:25:20 Try bots caught this. I'll need to implement WebC
526 // the following to work:
527 #if !defined(OS_MACOSX)
528 EXPECT_EQ(kCaptureSize, first_tab->GetView()->GetViewBounds().size());
529 #endif
530
531 // Switch back to the first tab and exit fullscreen.
532 browser()->tab_strip_model()->ActivateTabAt(0, true);
533 EXPECT_FALSE(browser()->window()->IsFullscreen());
534 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
535 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
536 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
537 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
538 EXPECT_FALSE(browser()->window()->IsFullscreen());
539 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
540 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
541 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
542 }
543
544 // Tests that, in a browser configured for Fullscreen-Within-Tab mode, more than
545 // one tab can be in fullscreen mode at the same time without interfering with
546 // each other. One tab is being screen-captured and is toggled into fullscreen
547 // mode, and then the user switches to another tab not being screen-captured and
548 // fullscreens it. The first tab's fullscreen toggle does not affect the
549 // browser window fullscreen, while the second one's does. Then, the order of
550 // operations is reversed.
551 //
552 // See 'FullscreenWithinTab Note' in fullscreen_controller.h.
553 TEST_F(FullscreenControllerStateUnitTest, TwoFullscreenedTabsOneCaptured) {
554 CommandLine::ForCurrentProcess()->
555 AppendSwitch(switches::kEmbedFlashFullscreen);
556 content::WebContentsDelegate* const wc_delegate =
557 static_cast<content::WebContentsDelegate*>(browser());
558 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget());
559
560 AddTab(browser(), GURL(content::kAboutBlankURL));
561 AddTab(browser(), GURL(content::kAboutBlankURL));
562 content::WebContents* const first_tab =
563 browser()->tab_strip_model()->GetWebContentsAt(0);
564 content::WebContents* const second_tab =
565 browser()->tab_strip_model()->GetWebContentsAt(1);
566
567 // Start capturing the first tab, fullscreen it, then switch to the second tab
568 // and fullscreen that. The second tab will cause the browser window to
569 // expand to fill the screen.
570 browser()->tab_strip_model()->ActivateTabAt(0, true);
571 const gfx::Size kCaptureSize(1280, 720);
572 first_tab->IncrementCapturerCount(kCaptureSize);
573 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
574 EXPECT_FALSE(browser()->window()->IsFullscreen());
575 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
576 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
577 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
578 browser()->tab_strip_model()->ActivateTabAt(1, true);
579 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
580 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
581 EXPECT_TRUE(browser()->window()->IsFullscreen());
582 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
583 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
584 EXPECT_TRUE(GetFullscreenController()->IsFullscreenForTabOrPending());
585
586 // Now exit fullscreen while still in the second tab. The browser window
587 // should no longer be fullscreened.
588 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
589 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
590 EXPECT_FALSE(browser()->window()->IsFullscreen());
591 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
592 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
593 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
594
595 // Finally, exit fullscreen on the captured tab.
596 browser()->tab_strip_model()->ActivateTabAt(0, true);
597 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
598 EXPECT_FALSE(browser()->window()->IsFullscreen());
599 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
600 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
601 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
602 }
603
604 // Tests that, in a browser configured for Fullscreen-Within-Tab mode, more than
605 // one tab can be in fullscreen mode at the same time. This is like the
606 // TwoFullscreenedTabsOneCaptured test above, except that the screen-captured
607 // tab exits fullscreen mode while the second tab is still in the foreground.
608 // When the first tab exits fullscreen, the fullscreen state of the second tab
609 // and the browser window should remain unchanged.
610 //
611 // See 'FullscreenWithinTab Note' in fullscreen_controller.h.
612 TEST_F(FullscreenControllerStateUnitTest,
613 BackgroundCapturedTabExitsFullscreen) {
614 CommandLine::ForCurrentProcess()->
615 AppendSwitch(switches::kEmbedFlashFullscreen);
616 content::WebContentsDelegate* const wc_delegate =
617 static_cast<content::WebContentsDelegate*>(browser());
618 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget());
619
620 AddTab(browser(), GURL(content::kAboutBlankURL));
621 AddTab(browser(), GURL(content::kAboutBlankURL));
622 content::WebContents* const first_tab =
623 browser()->tab_strip_model()->GetWebContentsAt(0);
624 content::WebContents* const second_tab =
625 browser()->tab_strip_model()->GetWebContentsAt(1);
626
627 // Start capturing the first tab, fullscreen it, then switch to the second tab
628 // and fullscreen that. The second tab will cause the browser window to
629 // expand to fill the screen.
630 browser()->tab_strip_model()->ActivateTabAt(0, true);
631 const gfx::Size kCaptureSize(1280, 720);
632 first_tab->IncrementCapturerCount(kCaptureSize);
633 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
634 EXPECT_FALSE(browser()->window()->IsFullscreen());
635 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
636 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
637 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
638 browser()->tab_strip_model()->ActivateTabAt(1, true);
639 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
640 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
641 EXPECT_TRUE(browser()->window()->IsFullscreen());
642 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
643 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
644 EXPECT_TRUE(GetFullscreenController()->IsFullscreenForTabOrPending());
645
646 // Now, the first tab (backgrounded) exits fullscreen. This should not affect
647 // the second tab's fullscreen, nor the state of the browser window.
648 GetFullscreenController()->ToggleFullscreenModeForTab(first_tab, false);
649 EXPECT_TRUE(browser()->window()->IsFullscreen());
650 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
651 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
652 EXPECT_TRUE(GetFullscreenController()->IsFullscreenForTabOrPending());
653
654 // Finally, exit fullscreen on the second tab.
655 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
656 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
657 EXPECT_FALSE(browser()->window()->IsFullscreen());
658 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab));
659 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab));
660 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
661 }
662
663 // Tests that, in a browser configured for Fullscreen-Within-Tab mode,
664 // fullscreening a screen-captured tab will NOT cause any fullscreen state
665 // change to the browser window. Then, toggling Browser Fullscreen mode should
666 // fullscreen the browser window, but this should behave fully independently of
667 // the tab's fullscreen state.
668 //
669 // See 'FullscreenWithinTab Note' in fullscreen_controller.h.
670 TEST_F(FullscreenControllerStateUnitTest,
671 OneCapturedTabFullscreenedBeforeBrowserFullscreen) {
672 CommandLine::ForCurrentProcess()->
673 AppendSwitch(switches::kEmbedFlashFullscreen);
674 content::WebContentsDelegate* const wc_delegate =
675 static_cast<content::WebContentsDelegate*>(browser());
676 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget());
677
678 AddTab(browser(), GURL(content::kAboutBlankURL));
679 content::WebContents* const tab =
680 browser()->tab_strip_model()->GetWebContentsAt(0);
681
682 // Start capturing the tab and fullscreen it. The state of the browser window
683 // should remain unchanged.
684 browser()->tab_strip_model()->ActivateTabAt(0, true);
685 const gfx::Size kCaptureSize(1280, 720);
686 tab->IncrementCapturerCount(kCaptureSize);
687 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE));
688 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
689 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
690 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForBrowser());
691
692 // Now, toggle into Browser Fullscreen mode. The browser window should now be
693 // fullscreened.
694 ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
695 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
696 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
697 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
698 EXPECT_TRUE(GetFullscreenController()->IsFullscreenForBrowser());
699
700 // Now, toggle back out of Browser Fullscreen mode. The browser window exits
701 // fullscreen mode, but the tab stays in fullscreen mode.
702 ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
703 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
704 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(tab));
705 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
706 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForBrowser());
707
708 // Finally, toggle back into Browser Fullscreen mode and then toggle out of
709 // tab fullscreen mode. The browser window should stay fullscreened, while
710 // the tab exits fullscreen mode.
711 ASSERT_TRUE(InvokeEvent(TOGGLE_FULLSCREEN));
712 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE));
713 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE));
714 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(tab));
715 EXPECT_FALSE(GetFullscreenController()->IsFullscreenForTabOrPending());
716 EXPECT_TRUE(GetFullscreenController()->IsFullscreenForBrowser());
717 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698