From d15048d49fee7167c57825bba4d899a7effcad3a Mon Sep 17 00:00:00 2001 From: "mikhail.pozdnyakov" Date: Thu, 23 Apr 2015 06:31:07 -0700 Subject: [PATCH] Set display mode for extensions::AppWindow 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} --- .../extension_fullscreen_apitest.cc | 12 ++++++++ .../fullscreen/mq_display_mode/background.js | 7 +++++ .../fullscreen/mq_display_mode/manifest.json | 12 ++++++++ .../fullscreen/mq_display_mode/window.html | 10 +++++++ .../fullscreen/mq_display_mode/window.js | 30 +++++++++++++++++++ .../data/extensions/fullscreen_app/blank.html | 6 +++- .../fullscreen_app/check_media_feature.js | 13 ++++++++ extensions/browser/app_window/app_window.cc | 6 ++++ extensions/browser/app_window/app_window.h | 2 ++ 9 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/background.js create mode 100644 chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/manifest.json create mode 100644 chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.html create mode 100644 chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.js create mode 100644 chrome/test/data/extensions/fullscreen_app/check_media_feature.js diff --git a/chrome/browser/extensions/extension_fullscreen_apitest.cc b/chrome/browser/extensions/extension_fullscreen_apitest.cc index f05b2ef7393a5e..9abe3c333dec48 100644 --- a/chrome/browser/extensions/extension_fullscreen_apitest.cc +++ b/chrome/browser/extensions/extension_fullscreen_apitest.cc @@ -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_; +} diff --git a/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/background.js b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/background.js new file mode 100644 index 00000000000000..633ebde578bc64 --- /dev/null +++ b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/background.js @@ -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'); +}); diff --git a/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/manifest.json b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/manifest.json new file mode 100644 index 00000000000000..753b1b0028a38c --- /dev/null +++ b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/manifest.json @@ -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": [ ] +} diff --git a/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.html b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.html new file mode 100644 index 00000000000000..ff97be2cfe4474 --- /dev/null +++ b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.html @@ -0,0 +1,10 @@ + + + + + + diff --git a/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.js b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.js new file mode 100644 index 00000000000000..99e5bb544392d2 --- /dev/null +++ b/chrome/test/data/extensions/api_test/fullscreen/mq_display_mode/window.js @@ -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]); +} diff --git a/chrome/test/data/extensions/fullscreen_app/blank.html b/chrome/test/data/extensions/fullscreen_app/blank.html index 170718246acadd..164106944ff811 100644 --- a/chrome/test/data/extensions/fullscreen_app/blank.html +++ b/chrome/test/data/extensions/fullscreen_app/blank.html @@ -1 +1,5 @@ - \ No newline at end of file + + + + + diff --git a/chrome/test/data/extensions/fullscreen_app/check_media_feature.js b/chrome/test/data/extensions/fullscreen_app/check_media_feature.js new file mode 100644 index 00000000000000..7f37900f6b612d --- /dev/null +++ b/chrome/test/data/extensions/fullscreen_app/check_media_feature.js @@ -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"; +} diff --git a/extensions/browser/app_window/app_window.cc b/extensions/browser/app_window/app_window.cc index 5ca80d41fcae23..64fa3c3e7c81e6 100644 --- a/extensions/browser/app_window/app_window.cc +++ b/extensions/browser/app_window/app_window.cc @@ -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) { diff --git a/extensions/browser/app_window/app_window.h b/extensions/browser/app_window/app_window.h index df6b2486320934..10baa0eef81e6f 100644 --- a/extensions/browser/app_window/app_window.h +++ b/extensions/browser/app_window/app_window.h @@ -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,