forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split full screen allowed policy browsertests
The browsertests of full screen allowed policy are moved from policy_browsertests to a separate file. Bug: 1128323 Change-Id: I6a470347be838d58b1b2d24b37f8f0bd852bc35e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410064 Commit-Queue: Swapnil Gupta <swapnilgupta@google.com> Reviewed-by: Sergey Poromov <poromov@chromium.org> Cr-Commit-Position: refs/heads/master@{#807856}
- Loading branch information
1 parent
7aaf3a3
commit 59cb2fb
Showing
3 changed files
with
132 additions
and
116 deletions.
There are no files selected for viewing
130 changes: 130 additions & 0 deletions
130
chrome/browser/policy/full_screen_allowed_policy_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// Copyright 2020 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 "base/values.h" | ||
#include "build/build_config.h" | ||
#include "chrome/browser/apps/app_service/app_service_proxy.h" | ||
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h" | ||
#include "chrome/browser/policy/policy_test_utils.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_commands.h" | ||
#include "chrome/browser/ui/browser_window.h" | ||
#include "components/policy/core/common/policy_map.h" | ||
#include "components/policy/core/common/policy_types.h" | ||
#include "components/policy/policy_constants.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "content/public/test/browser_test_utils.h" | ||
#include "extensions/browser/app_window/app_window.h" | ||
#include "extensions/browser/app_window/app_window_registry.h" | ||
#include "extensions/browser/app_window/native_app_window.h" | ||
#include "extensions/common/extension.h" | ||
#include "ui/base/window_open_disposition.h" | ||
|
||
namespace policy { | ||
|
||
namespace { | ||
|
||
const base::FilePath::CharType kUnpackedFullscreenAppName[] = | ||
FILE_PATH_LITERAL("fullscreen_app"); | ||
|
||
// Observer used to wait for the creation of a new app window. | ||
class TestAddAppWindowObserver | ||
: public extensions::AppWindowRegistry::Observer { | ||
public: | ||
explicit TestAddAppWindowObserver(extensions::AppWindowRegistry* registry); | ||
~TestAddAppWindowObserver() override; | ||
|
||
// extensions::AppWindowRegistry::Observer: | ||
void OnAppWindowAdded(extensions::AppWindow* app_window) override; | ||
|
||
extensions::AppWindow* WaitForAppWindow(); | ||
|
||
private: | ||
extensions::AppWindowRegistry* registry_; // Not owned. | ||
extensions::AppWindow* window_; // Not owned. | ||
base::RunLoop run_loop_; | ||
}; | ||
|
||
TestAddAppWindowObserver::TestAddAppWindowObserver( | ||
extensions::AppWindowRegistry* registry) | ||
: registry_(registry), window_(nullptr) { | ||
registry_->AddObserver(this); | ||
} | ||
|
||
TestAddAppWindowObserver::~TestAddAppWindowObserver() { | ||
registry_->RemoveObserver(this); | ||
} | ||
|
||
void TestAddAppWindowObserver::OnAppWindowAdded( | ||
extensions::AppWindow* app_window) { | ||
window_ = app_window; | ||
run_loop_.Quit(); | ||
} | ||
|
||
extensions::AppWindow* TestAddAppWindowObserver::WaitForAppWindow() { | ||
run_loop_.Run(); | ||
return window_; | ||
} | ||
|
||
} // namespace | ||
|
||
IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedBrowser) { | ||
PolicyMap policies; | ||
policies.Set(key::kFullscreenAllowed, POLICY_LEVEL_MANDATORY, | ||
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false), | ||
nullptr); | ||
UpdateProviderPolicy(policies); | ||
|
||
BrowserWindow* browser_window = browser()->window(); | ||
ASSERT_TRUE(browser_window); | ||
|
||
EXPECT_FALSE(browser_window->IsFullscreen()); | ||
chrome::ToggleFullscreenMode(browser()); | ||
EXPECT_FALSE(browser_window->IsFullscreen()); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(PolicyTest, FullscreenAllowedApp) { | ||
PolicyMap policies; | ||
policies.Set(key::kFullscreenAllowed, POLICY_LEVEL_MANDATORY, | ||
POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, base::Value(false), | ||
nullptr); | ||
UpdateProviderPolicy(policies); | ||
|
||
scoped_refptr<const extensions::Extension> extension = | ||
LoadUnpackedExtension(kUnpackedFullscreenAppName); | ||
ASSERT_TRUE(extension); | ||
|
||
// Launch an app that tries to open a fullscreen window. | ||
TestAddAppWindowObserver add_window_observer( | ||
extensions::AppWindowRegistry::Get(browser()->profile())); | ||
apps::AppServiceProxyFactory::GetForProfile(browser()->profile()) | ||
->BrowserAppLauncher() | ||
->LaunchAppWithParams(apps::AppLaunchParams( | ||
extension->id(), apps::mojom::LaunchContainer::kLaunchContainerNone, | ||
WindowOpenDisposition::NEW_WINDOW, | ||
apps::mojom::AppLaunchSource::kSourceTest)); | ||
extensions::AppWindow* window = add_window_observer.WaitForAppWindow(); | ||
ASSERT_TRUE(window); | ||
|
||
// Verify that the window is not in fullscreen mode. | ||
EXPECT_FALSE(window->GetBaseWindow()->IsFullscreen()); | ||
|
||
// We have to wait for the navigation to commit since the JS object | ||
// registration is delayed (see AppWindowCreateFunction::RunAsync). | ||
EXPECT_TRUE(content::WaitForLoadStop(window->web_contents())); | ||
|
||
// Verify that the window cannot be toggled into fullscreen mode via apps | ||
// APIs. | ||
EXPECT_TRUE(content::ExecuteScript( | ||
window->web_contents(), "chrome.app.window.current().fullscreen();")); | ||
EXPECT_FALSE(window->GetBaseWindow()->IsFullscreen()); | ||
|
||
// Verify that the window cannot be toggled into fullscreen mode from within | ||
// Chrome (e.g., using keyboard accelerators). | ||
window->Fullscreen(); | ||
EXPECT_FALSE(window->GetBaseWindow()->IsFullscreen()); | ||
} | ||
|
||
} // namespace policy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters