Skip to content

Commit

Permalink
Set display mode for extensions::AppWindow
Browse files Browse the repository at this point in the history
This CL provides content::WebContentsDelegate::GetDisplayMode() implementation for extensions::AppWindow.

The 'extensions/api_test/fullscreen/' test is modified to verify media query "display-mode" features correctness.

BUG=471703

Review URL: https://codereview.chromium.org/1070423003

Cr-Commit-Position: refs/heads/master@{#326502}
  • Loading branch information
mikhail.pozdnyakov authored and Commit bot committed Apr 23, 2015
1 parent 62215af commit d15048d
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 1 deletion.
12 changes: 12 additions & 0 deletions chrome/browser/extensions/extension_fullscreen_apitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,15 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
ASSERT_TRUE(RunExtensionTest("window_update/sizing")) << message_;
ASSERT_FALSE(browser()->window()->IsFullscreen());
}

#if defined(OS_MACOSX)
// Fails on MAC: http://crbug.com/480370
#define MAYBE_DisplayModeWindowIsInFullscreen DISABLED_DisplayModeWindowIsInFullscreen
#else
#define MAYBE_DisplayModeWindowIsInFullscreen DisplayModeWindowIsInFullscreen
#endif // defined(OS_MACOSX)

IN_PROC_BROWSER_TEST_F(ExtensionApiTest,
MAYBE_DisplayModeWindowIsInFullscreen) {
ASSERT_TRUE(RunPlatformAppTest("fullscreen/mq_display_mode")) << message_;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2013 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.

chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "App window, 'display-mode' media feature test",
"description": "tests the 'display mode' media feature for the fullscreened app window",
"version": "1",
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [ ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
* 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.
-->
<html>
<body>
<script src="window.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2015 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.
function checkWindowRestored() {
var standalone = matchMedia( '(display-mode: standalone)' );
chrome.test.assertTrue(standalone.matches,
"Display mode of the restored window is 'standalone'");

chrome.test.succeed();
}

function checkWindowFullscreened() {
var fullscreen = matchMedia( '(display-mode: fullscreen)' );
chrome.test.assertTrue(fullscreen.matches,
"Display mode of the fullscreened window is 'fullscreen'");

window.onresize = checkWindowRestored;
chrome.app.window.current().restore();
}

window.onload = function() {
function checkDisplayModeMediaFeature() {
var standalone = matchMedia( '(display-mode: standalone)' );
chrome.test.assertTrue(standalone.matches,
"Initially display mode is 'standalone'");
window.onresize = checkWindowFullscreened;
chrome.app.window.current().fullscreen();
};
chrome.test.runTests([checkDisplayModeMediaFeature]);
}
6 changes: 5 additions & 1 deletion chrome/test/data/extensions/fullscreen_app/blank.html
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
<html><head></head><body></body></html>
<html>
<head></head>
<body></body>
<script src="check_media_feature.js" type="text/javascript"></script>
</html>
13 changes: 13 additions & 0 deletions chrome/test/data/extensions/fullscreen_app/check_media_feature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2015 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.
var fullscreen = matchMedia( '(display-mode: fullscreen)' );
var p = document.createElement("p");
document.body.appendChild(p);
if (fullscreen.matches) {
p.innerHTML = "(display-mode: fullscreen) matches.";
p.style.color = "green";
} else {
p.innerHTML = "(display-mode: fullscreen) does not match.";
p.style.color = "red";
}
6 changes: 6 additions & 0 deletions extensions/browser/app_window/app_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,12 @@ bool AppWindow::IsFullscreenForTabOrPending(const content::WebContents* source)
return IsHtmlApiFullscreen();
}

blink::WebDisplayMode AppWindow::GetDisplayMode(
const content::WebContents* source) const {
return IsFullscreen() ? blink::WebDisplayModeFullscreen
: blink::WebDisplayModeStandalone;
}

void AppWindow::OnExtensionUnloaded(BrowserContext* browser_context,
const Extension* extension,
UnloadedExtensionInfo::Reason reason) {
Expand Down
2 changes: 2 additions & 0 deletions extensions/browser/app_window/app_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ class AppWindow : public content::WebContentsDelegate,
void ExitFullscreenModeForTab(content::WebContents* source) override;
bool IsFullscreenForTabOrPending(
const content::WebContents* source) const override;
blink::WebDisplayMode GetDisplayMode(
const content::WebContents* source) const override;
void RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
Expand Down

0 comments on commit d15048d

Please sign in to comment.