summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/fullscreen_controller_test.cc
blob: c4dee4b38e5cd29ceeb96b28487bf5f938387dda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/fullscreen_controller_test.h"

#include "base/command_line.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/fullscreen_controller.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_navigation_observer.h"

using content::WebContents;

const char FullscreenControllerTest::kFullscreenMouseLockHTML[] =
    "files/fullscreen_mouselock/fullscreen_mouselock.html";

void FullscreenControllerTest::SetUpCommandLine(CommandLine* command_line) {
  InProcessBrowserTest::SetUpCommandLine(command_line);
  command_line->AppendSwitch(switches::kEnablePointerLock);
}

void FullscreenControllerTest::ToggleTabFullscreen(WebContents* tab,
                                                   bool enter_fullscreen) {
  if (IsFullscreenForBrowser()) {
    // Changing tab fullscreen state will not actually change the window
    // when browser fullscreen is in effect.
    browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen);
  } else {  // Not in browser fullscreen, expect window to actually change.
    FullscreenNotificationObserver fullscreen_observer;
    browser()->ToggleFullscreenModeForTab(tab, enter_fullscreen);
    fullscreen_observer.Wait();
    ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen);
  }
}

void FullscreenControllerTest::ToggleBrowserFullscreen(bool enter_fullscreen) {
  ASSERT_EQ(browser()->window()->IsFullscreen(), !enter_fullscreen);
  FullscreenNotificationObserver fullscreen_observer;

  browser()->ToggleFullscreenMode();

  fullscreen_observer.Wait();
  ASSERT_EQ(browser()->window()->IsFullscreen(), enter_fullscreen);
  ASSERT_EQ(IsFullscreenForBrowser(), enter_fullscreen);
}

void FullscreenControllerTest::RequestToLockMouse(WebContents* tab,
    bool user_gesture,
    bool last_unlocked_by_target) {
  browser()->RequestToLockMouse(tab, user_gesture,
      last_unlocked_by_target);
}

void FullscreenControllerTest::LostMouseLock() {
  browser()->LostMouseLock();
}

bool FullscreenControllerTest::SendEscapeToFullscreenController() {
  return browser()->fullscreen_controller_->HandleUserPressedEscape();
}

bool FullscreenControllerTest::IsFullscreenForBrowser() {
  return browser()->fullscreen_controller_->IsFullscreenForBrowser();
}

bool FullscreenControllerTest::IsFullscreenForTabOrPending() {
  return browser()->IsFullscreenForTabOrPending();
}

bool FullscreenControllerTest::IsMouseLockPermissionRequested() {
  FullscreenExitBubbleType type =
      browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
  bool mouse_lock = false;
  fullscreen_bubble::PermissionRequestedByType(type, NULL, &mouse_lock);
  return mouse_lock;
}

bool FullscreenControllerTest::IsFullscreenPermissionRequested() {
  FullscreenExitBubbleType type =
      browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
  bool fullscreen = false;
  fullscreen_bubble::PermissionRequestedByType(type, &fullscreen, NULL);
  return fullscreen;
}

FullscreenExitBubbleType
    FullscreenControllerTest::GetFullscreenExitBubbleType() {
  return browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
}

bool FullscreenControllerTest::IsFullscreenBubbleDisplayed() {
  FullscreenExitBubbleType type =
      browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
  return type != FEB_TYPE_NONE;
}

bool FullscreenControllerTest::IsFullscreenBubbleDisplayingButtons() {
  FullscreenExitBubbleType type =
      browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
  return fullscreen_bubble::ShowButtonsForType(type);
}

void FullscreenControllerTest::AcceptCurrentFullscreenOrMouseLockRequest() {
  WebContents* fullscreen_tab = browser()->GetActiveWebContents();
  FullscreenExitBubbleType type =
      browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
  browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type);
}

void FullscreenControllerTest::DenyCurrentFullscreenOrMouseLockRequest() {
  FullscreenExitBubbleType type =
      browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
  browser()->OnDenyFullscreenPermission(type);
}

void FullscreenControllerTest::AddTabAtIndexAndWait(int index, const GURL& url,
    content::PageTransition transition) {
  content::TestNavigationObserver observer(
      content::NotificationService::AllSources(), NULL, 1);

  AddTabAtIndex(index, url, transition);

  observer.Wait();
}

void FullscreenControllerTest::GoBack() {
  content::TestNavigationObserver observer(
      content::NotificationService::AllSources(), NULL, 1);

  browser()->GoBack(CURRENT_TAB);

  observer.Wait();
}