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 "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 Loading... | |
| 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 TEST_F(FullscreenControllerStateUnitTest, OneCapturedFullscreenedTab) { | |
|
scheib
2014/02/12 01:41:16
Please comment the intent of each test and referen
miu
2014/02/12 08:25:19
Done.
| |
| 481 CommandLine::ForCurrentProcess()-> | |
| 482 AppendSwitch(switches::kEmbedFlashFullscreen); | |
| 483 content::WebContentsDelegate* const wc_delegate = | |
| 484 static_cast<content::WebContentsDelegate*>(browser()); | |
| 485 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget()); | |
| 486 | |
| 487 AddTab(browser(), GURL(content::kAboutBlankURL)); | |
| 488 AddTab(browser(), GURL(content::kAboutBlankURL)); | |
| 489 content::WebContents* const first_tab = | |
| 490 browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 491 content::WebContents* const second_tab = | |
| 492 browser()->tab_strip_model()->GetWebContentsAt(1); | |
| 493 | |
| 494 // Activate the first tab and tell its WebContents it is being captured. | |
| 495 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
| 496 const gfx::Size kCaptureSize(1280, 720); | |
| 497 first_tab->IncrementCapturerCount(kCaptureSize); | |
| 498 ASSERT_FALSE(browser()->window()->IsFullscreen()); | |
| 499 ASSERT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 500 ASSERT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
|
scheib
2014/02/12 01:41:16
Add assert for "IsFullscreenForTabOrPending()"?
miu
2014/02/12 08:25:19
Done, and throughout all these new tests.
| |
| 501 | |
| 502 // Enter tab fullscreen. Since the tab is being captured, the browser window | |
| 503 // should not expand to fill the screen. | |
| 504 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE)); | |
| 505 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 506 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 507 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 508 | |
| 509 // Switch to the other tab. Check that the first tab was resized to the | |
| 510 // WebContents' preferred size. | |
| 511 browser()->tab_strip_model()->ActivateTabAt(1, true); | |
| 512 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 513 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 514 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 515 EXPECT_EQ(kCaptureSize, first_tab->GetView()->GetViewBounds().size()); | |
| 516 | |
| 517 // Switch back to the first tab and exit fullscreen. | |
|
scheib
2014/02/12 01:41:16
What size should it be now?
miu
2014/02/12 08:25:19
It can't be determined in these tests since we've
| |
| 518 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
| 519 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 520 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 521 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 522 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)); | |
| 523 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 524 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 525 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 526 } | |
| 527 | |
| 528 TEST_F(FullscreenControllerStateUnitTest, TwoFullscreenedTabsOneCaptured) { | |
| 529 CommandLine::ForCurrentProcess()-> | |
| 530 AppendSwitch(switches::kEmbedFlashFullscreen); | |
| 531 content::WebContentsDelegate* const wc_delegate = | |
| 532 static_cast<content::WebContentsDelegate*>(browser()); | |
| 533 ASSERT_TRUE(wc_delegate->EmbedsFullscreenWidget()); | |
| 534 | |
| 535 AddTab(browser(), GURL(content::kAboutBlankURL)); | |
| 536 AddTab(browser(), GURL(content::kAboutBlankURL)); | |
| 537 content::WebContents* const first_tab = | |
| 538 browser()->tab_strip_model()->GetWebContentsAt(0); | |
| 539 content::WebContents* const second_tab = | |
| 540 browser()->tab_strip_model()->GetWebContentsAt(1); | |
| 541 | |
| 542 // Start capturing the first tab, fullscreen it, then switch to the second tab | |
| 543 // and fullscreen that. The second tab will cause the browser window to | |
| 544 // expand to fill the screen. | |
| 545 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
| 546 const gfx::Size kCaptureSize(1280, 720); | |
| 547 first_tab->IncrementCapturerCount(kCaptureSize); | |
| 548 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE)); | |
| 549 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 550 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 551 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 552 browser()->tab_strip_model()->ActivateTabAt(1, true); | |
| 553 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_TRUE)); | |
| 554 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE)); | |
| 555 EXPECT_TRUE(browser()->window()->IsFullscreen()); | |
| 556 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 557 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 558 | |
| 559 // Now exit fullscreen while still in the second tab. The browser window | |
| 560 // should no longer be fullscreened. | |
| 561 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)); | |
| 562 ASSERT_TRUE(InvokeEvent(WINDOW_CHANGE)); | |
| 563 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 564 EXPECT_TRUE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 565 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 566 | |
| 567 // Finally, exit fullscreen on the captured tab. | |
| 568 browser()->tab_strip_model()->ActivateTabAt(0, true); | |
| 569 ASSERT_TRUE(InvokeEvent(TAB_FULLSCREEN_FALSE)); | |
| 570 EXPECT_FALSE(browser()->window()->IsFullscreen()); | |
| 571 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(first_tab)); | |
| 572 EXPECT_FALSE(wc_delegate->IsFullscreenForTabOrPending(second_tab)); | |
| 573 } | |
|
scheib
2014/02/12 01:41:16
Some other test scenarios:
- Tab already fullscree
miu
2014/02/12 08:25:19
Done, except for the first scenario because there'
| |
| OLD | NEW |