15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller_test.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/fullscreen/fullscreen_controller.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/test_navigation_observer.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::WebContents;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char FullscreenControllerTest::kFullscreenMouseLockHTML[] =
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    "files/fullscreen_mouselock/fullscreen_mouselock.html";
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerTest::RequestToLockMouse(
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool user_gesture,
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool last_unlocked_by_target) {
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser()->RequestToLockMouse(tab, user_gesture,
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      last_unlocked_by_target);
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerTest::LostMouseLock() {
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  browser()->LostMouseLock();
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerTest::SendEscapeToFullscreenController() {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return browser()->fullscreen_controller()->HandleUserPressedEscape();
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerTest::IsFullscreenForBrowser() {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return browser()->fullscreen_controller()->IsFullscreenForBrowser();
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)bool FullscreenControllerTest::IsWindowFullscreenForTabOrPending() {
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  return browser()->fullscreen_controller()->
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      IsWindowFullscreenForTabOrPending();
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerTest::IsMouseLockPermissionRequested() {
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FullscreenExitBubbleType type =
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      browser()->fullscreen_controller()->GetFullscreenExitBubbleType();
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool mouse_lock = false;
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  fullscreen_bubble::PermissionRequestedByType(type, NULL, &mouse_lock);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return mouse_lock;
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerTest::IsFullscreenPermissionRequested() {
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FullscreenExitBubbleType type =
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      browser()->fullscreen_controller()->GetFullscreenExitBubbleType();
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool fullscreen = false;
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  fullscreen_bubble::PermissionRequestedByType(type, &fullscreen, NULL);
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return fullscreen;
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)FullscreenExitBubbleType
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    FullscreenControllerTest::GetFullscreenExitBubbleType() {
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return browser()->fullscreen_controller()->GetFullscreenExitBubbleType();
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerTest::IsFullscreenBubbleDisplayed() {
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FullscreenExitBubbleType type =
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      browser()->fullscreen_controller()->GetFullscreenExitBubbleType();
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return type != FEB_TYPE_NONE;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)bool FullscreenControllerTest::IsFullscreenBubbleDisplayingButtons() {
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  FullscreenExitBubbleType type =
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      browser()->fullscreen_controller()->GetFullscreenExitBubbleType();
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return fullscreen_bubble::ShowButtonsForType(type);
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerTest::AcceptCurrentFullscreenOrMouseLockRequest() {
812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser()->fullscreen_controller()->OnAcceptFullscreenPermission();
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerTest::DenyCurrentFullscreenOrMouseLockRequest() {
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  browser()->fullscreen_controller()->OnDenyFullscreenPermission();
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerTest::GoBack() {
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestNavigationObserver observer(
90868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      browser()->tab_strip_model()->GetActiveWebContents(), 1);
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::GoBack(browser(), CURRENT_TAB);
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer.Wait();
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void FullscreenControllerTest::Reload() {
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::TestNavigationObserver observer(
97868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      browser()->tab_strip_model()->GetActiveWebContents(), 1);
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  chrome::Reload(browser(), CURRENT_TAB);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  observer.Wait();
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
102d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)void FullscreenControllerTest::SetPrivilegedFullscreen(bool is_privileged) {
103d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  browser()->fullscreen_controller()->
104d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)      SetPrivilegedFullscreenForTesting(is_privileged);
105d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)}
106