summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/exclusive_access/fullscreen_controller_browsertest.cc
blob: 8248e5086c973f00da2a8ab2b6b8e00db46da70e (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// 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/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#include "net/test/embedded_test_server/embedded_test_server.h"

using content::WebContents;
using ui::PAGE_TRANSITION_TYPED;

IN_PROC_BROWSER_TEST_F(FullscreenControllerTest,
                       PendingMouseLockExitsOnTabSwitch) {
  // This test doesn't make sense in simplified mode, since we never prompt for
  // mouse lock.
  if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled())
    return;

  AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
  AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
  WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();

  // Request mouse lock. Bubble is displayed.
  RequestToLockMouse(true, false);
  ASSERT_TRUE(IsFullscreenBubbleDisplayed());

  // Activate current tab. Mouse lock bubble remains.
  browser()->tab_strip_model()->ActivateTabAt(0, true);
  ASSERT_TRUE(IsFullscreenBubbleDisplayed());

  // Activate second tab. Mouse lock bubble clears.
  {
    MouseLockNotificationObserver mouse_lock_observer;
    browser()->tab_strip_model()->ActivateTabAt(1, true);
    mouse_lock_observer.Wait();
  }
  ASSERT_FALSE(IsFullscreenBubbleDisplayed());

  // Now, test that closing an unrelated tab does not disturb a request.

  // Request mouse lock. Bubble is displayed.
  RequestToLockMouse(true, false);
  ASSERT_TRUE(IsFullscreenBubbleDisplayed());

  // Close first tab while second active. Mouse lock bubble remains.
  chrome::CloseWebContents(browser(), tab1, false);
  ASSERT_TRUE(IsFullscreenBubbleDisplayed());
}

IN_PROC_BROWSER_TEST_F(FullscreenControllerTest,
                       PendingMouseLockExitsOnTabClose) {
  // This test doesn't make sense in simplified mode, since we never prompt for
  // mouse lock.
  if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled())
    return;

  // Add more tabs.
  AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
  AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);

  // Request mouse lock. Bubble is displayed.
  RequestToLockMouse(true, false);
  ASSERT_TRUE(IsFullscreenBubbleDisplayed());

  // Close tab. Bubble is cleared.
  {
    MouseLockNotificationObserver mouse_lock_observer;
    chrome::CloseTab(browser());
    mouse_lock_observer.Wait();
  }
  ASSERT_FALSE(IsFullscreenBubbleDisplayed());
}

IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, MouseLockOnFileURL) {
  static const base::FilePath::CharType* kEmptyFile =
      FILE_PATH_LITERAL("empty.html");
  GURL file_url(ui_test_utils::GetTestUrl(
      base::FilePath(base::FilePath::kCurrentDirectory),
      base::FilePath(kEmptyFile)));
  AddTabAtIndex(0, file_url, PAGE_TRANSITION_TYPED);
  RequestToLockMouse(true, false);
  ASSERT_TRUE(IsFullscreenBubbleDisplayed());
  if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled())
    ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
  else
    ASSERT_TRUE(IsFullscreenBubbleDisplayingButtons());
}

IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, FullscreenOnFileURL) {
  static const base::FilePath::CharType* kEmptyFile =
      FILE_PATH_LITERAL("empty.html");
  GURL file_url(ui_test_utils::GetTestUrl(
      base::FilePath(base::FilePath::kCurrentDirectory),
      base::FilePath(kEmptyFile)));
  AddTabAtIndex(0, file_url, PAGE_TRANSITION_TYPED);
  GetFullscreenController()->EnterFullscreenModeForTab(
      browser()->tab_strip_model()->GetActiveWebContents(),
      file_url.GetOrigin());
  ASSERT_TRUE(IsFullscreenBubbleDisplayed());
  if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled())
    ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
  else
    ASSERT_TRUE(IsFullscreenBubbleDisplayingButtons());
}

IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, PermissionContentSettings) {
  ASSERT_TRUE(embedded_test_server()->Start());
  GURL url = embedded_test_server()->GetURL(kFullscreenMouseLockHTML);
  ui_test_utils::NavigateToURL(browser(), url);

  EXPECT_FALSE(browser()->window()->IsFullscreen());

  // The content's origin is not allowed to go fullscreen.
  EXPECT_EQ(
      CONTENT_SETTING_ASK,
      HostContentSettingsMapFactory::GetForProfile(browser()->profile())
          ->GetContentSetting(url.GetOrigin(),
                              url.GetOrigin(),
                              CONTENT_SETTINGS_TYPE_FULLSCREEN,
                              std::string()));

  GetFullscreenController()->EnterFullscreenModeForTab(
      browser()->tab_strip_model()->GetActiveWebContents(), url.GetOrigin());
  EXPECT_TRUE(IsFullscreenBubbleDisplayed());

  // The content's origin is still not allowed to go fullscreen.
  EXPECT_EQ(
      CONTENT_SETTING_ASK,
      HostContentSettingsMapFactory::GetForProfile(browser()->profile())
          ->GetContentSetting(url.GetOrigin(),
                              url.GetOrigin(),
                              CONTENT_SETTINGS_TYPE_FULLSCREEN,
                              std::string()));

  if (ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled()) {
    ASSERT_FALSE(IsFullscreenBubbleDisplayingButtons());
  } else {
    ASSERT_TRUE(IsFullscreenBubbleDisplayingButtons());
    // It only makes sense to test this on the non-simplified mode. In the
    // simplified mode, you cannot accept the request (as it is auto-accepted)
    // so you can't set ALLOW.
    AcceptCurrentFullscreenOrMouseLockRequest();

    // The content's origin is allowed to go fullscreen.
    EXPECT_EQ(CONTENT_SETTING_ALLOW,
              HostContentSettingsMapFactory::GetForProfile(browser()->profile())
                  ->GetContentSetting(url.GetOrigin(), url.GetOrigin(),
                                      CONTENT_SETTINGS_TYPE_FULLSCREEN,
                                      std::string()));
  }

  // The primary and secondary patterns have been set when setting the
  // permission, thus setting another secondary pattern shouldn't work.
  EXPECT_EQ(
      CONTENT_SETTING_ASK,
      HostContentSettingsMapFactory::GetForProfile(browser()->profile())
          ->GetContentSetting(url.GetOrigin(),
                              GURL("https://test.com"),
                              CONTENT_SETTINGS_TYPE_FULLSCREEN,
                              std::string()));

  HostContentSettingsMapFactory::GetForProfile(browser()->profile())
      ->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_FULLSCREEN);
}