Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / exclusive_access / fullscreen_controller_browsertest.cc
blob88e6e5d5658ff30095cc4d8e2c040a9d5a3cbc44
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/browser.h"
6 #include "chrome/browser/ui/browser_commands.h"
7 #include "chrome/browser/ui/browser_tabstrip.h"
8 #include "chrome/browser/ui/browser_window.h"
9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller_test.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "components/content_settings/core/browser/host_content_settings_map.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/url_constants.h"
17 using content::WebContents;
18 using ui::PAGE_TRANSITION_TYPED;
20 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest,
21 PendingMouseLockExitsOnTabSwitch) {
22 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
23 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
24 WebContents* tab1 = browser()->tab_strip_model()->GetActiveWebContents();
26 // Request mouse lock. Bubble is displayed.
27 RequestToLockMouse(true, false);
28 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
30 // Activate current tab. Mouse lock bubble remains.
31 browser()->tab_strip_model()->ActivateTabAt(0, true);
32 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
34 // Activate second tab. Mouse lock bubble clears.
36 MouseLockNotificationObserver mouse_lock_observer;
37 browser()->tab_strip_model()->ActivateTabAt(1, true);
38 mouse_lock_observer.Wait();
40 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
42 // Now, test that closing an unrelated tab does not disturb a request.
44 // Request mouse lock. Bubble is displayed.
45 RequestToLockMouse(true, false);
46 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
48 // Close first tab while second active. Mouse lock bubble remains.
49 chrome::CloseWebContents(browser(), tab1, false);
50 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
53 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest,
54 PendingMouseLockExitsOnTabClose) {
55 // Add more tabs.
56 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
57 AddTabAtIndex(0, GURL(url::kAboutBlankURL), PAGE_TRANSITION_TYPED);
59 // Request mouse lock. Bubble is displayed.
60 RequestToLockMouse(true, false);
61 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
63 // Close tab. Bubble is cleared.
65 MouseLockNotificationObserver mouse_lock_observer;
66 chrome::CloseTab(browser());
67 mouse_lock_observer.Wait();
69 ASSERT_FALSE(IsFullscreenBubbleDisplayed());
72 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, MouseLockOnFileURL) {
73 static const base::FilePath::CharType* kEmptyFile =
74 FILE_PATH_LITERAL("empty.html");
75 GURL file_url(ui_test_utils::GetTestUrl(
76 base::FilePath(base::FilePath::kCurrentDirectory),
77 base::FilePath(kEmptyFile)));
78 AddTabAtIndex(0, file_url, PAGE_TRANSITION_TYPED);
79 RequestToLockMouse(true, false);
80 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
81 ASSERT_TRUE(IsFullscreenBubbleDisplayingButtons());
84 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, FullscreenOnFileURL) {
85 static const base::FilePath::CharType* kEmptyFile =
86 FILE_PATH_LITERAL("empty.html");
87 GURL file_url(ui_test_utils::GetTestUrl(
88 base::FilePath(base::FilePath::kCurrentDirectory),
89 base::FilePath(kEmptyFile)));
90 AddTabAtIndex(0, file_url, PAGE_TRANSITION_TYPED);
91 RequestToLockMouse(true, false);
92 ASSERT_TRUE(IsFullscreenBubbleDisplayed());
93 ASSERT_TRUE(IsFullscreenBubbleDisplayingButtons());
96 IN_PROC_BROWSER_TEST_F(FullscreenControllerTest, PermissionContentSettings) {
97 GURL url = test_server()->GetURL(kFullscreenMouseLockHTML);
98 ASSERT_TRUE(test_server()->Start());
99 ui_test_utils::NavigateToURL(browser(), url);
101 EXPECT_FALSE(browser()->window()->IsFullscreen());
103 // The content's origin is not allowed to go fullscreen.
104 EXPECT_EQ(
105 CONTENT_SETTING_ASK,
106 browser()->profile()->GetHostContentSettingsMap()->GetContentSetting(
107 url.GetOrigin(),
108 url.GetOrigin(),
109 CONTENT_SETTINGS_TYPE_FULLSCREEN,
110 std::string()));
112 GetFullscreenController()->EnterFullscreenModeForTab(
113 browser()->tab_strip_model()->GetActiveWebContents(), url.GetOrigin());
114 EXPECT_TRUE(IsFullscreenBubbleDisplayed());
116 // The content's origin is still not allowed to go fullscreen.
117 EXPECT_EQ(
118 CONTENT_SETTING_ASK,
119 browser()->profile()->GetHostContentSettingsMap()->GetContentSetting(
120 url.GetOrigin(),
121 url.GetOrigin(),
122 CONTENT_SETTINGS_TYPE_FULLSCREEN,
123 std::string()));
125 AcceptCurrentFullscreenOrMouseLockRequest();
127 // The content's origin is allowed to go fullscreen.
128 EXPECT_EQ(
129 CONTENT_SETTING_ALLOW,
130 browser()->profile()->GetHostContentSettingsMap()->GetContentSetting(
131 url.GetOrigin(),
132 url.GetOrigin(),
133 CONTENT_SETTINGS_TYPE_FULLSCREEN,
134 std::string()));
136 // The primary and secondary patterns have been set when setting the
137 // permission, thus setting another secondary pattern shouldn't work.
138 EXPECT_EQ(
139 CONTENT_SETTING_ASK,
140 browser()->profile()->GetHostContentSettingsMap()->GetContentSetting(
141 url.GetOrigin(),
142 GURL("https://test.com"),
143 CONTENT_SETTINGS_TYPE_FULLSCREEN,
144 std::string()));
146 browser()->profile()->GetHostContentSettingsMap()->ClearSettingsForOneType(
147 CONTENT_SETTINGS_TYPE_FULLSCREEN);