Commit 4c900827 authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

Enabling alwaysOnTop should fail to create app windows if the permission is lacking

If the alwaysOnTop property is enabled, but the app.window.alwaysOnTop
permission is not specified in the manifest, app window creation will
now fail with an error.

BUG=371213
TEST=browser_tests 
(PlatformAppBrowserTest.WindowsApiAlwaysOnTopNoPermissions)

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@270045 0039d316-1c4b-4281-b951-d872f2087c98
parent d22f9d4a
...@@ -48,6 +48,8 @@ const char kInactiveColorWithoutColor[] = ...@@ -48,6 +48,8 @@ const char kInactiveColorWithoutColor[] =
"frame.inactiveColor must be used with frame.color."; "frame.inactiveColor must be used with frame.color.";
const char kConflictingBoundsOptions[] = const char kConflictingBoundsOptions[] =
"The $1 property cannot be specified for both inner and outer bounds."; "The $1 property cannot be specified for both inner and outer bounds.";
const char kAlwaysOnTopPermission[] =
"The \"app.window.alwaysOnTop\" permission is required.";
} // namespace app_window_constants } // namespace app_window_constants
const char kNoneFrameOption[] = "none"; const char kNoneFrameOption[] = "none";
...@@ -234,10 +236,16 @@ bool AppWindowCreateFunction::RunAsync() { ...@@ -234,10 +236,16 @@ bool AppWindowCreateFunction::RunAsync() {
if (options->resizable.get()) if (options->resizable.get())
create_params.resizable = *options->resizable.get(); create_params.resizable = *options->resizable.get();
if (options->always_on_top.get() && if (options->always_on_top.get()) {
GetExtension()->HasAPIPermission(APIPermission::kAlwaysOnTopWindows))
create_params.always_on_top = *options->always_on_top.get(); create_params.always_on_top = *options->always_on_top.get();
if (create_params.always_on_top && !GetExtension()->HasAPIPermission(
APIPermission::kAlwaysOnTopWindows)) {
error_ = app_window_constants::kAlwaysOnTopPermission;
return false;
}
}
if (options->focused.get()) if (options->focused.get())
create_params.focused = *options->focused.get(); create_params.focused = *options->focused.get();
......
...@@ -3,29 +3,22 @@ ...@@ -3,29 +3,22 @@
// found in the LICENSE file. // found in the LICENSE file.
var callbackPass = chrome.test.callbackPass; var callbackPass = chrome.test.callbackPass;
var callbackFail = chrome.test.callbackFail;
function testAlwaysOnTop(testId, value) { function setAlwaysOnTop(value) {
var options = {
id: testId,
alwaysOnTop: value
};
chrome.app.window.create('index.html', chrome.app.window.create('index.html',
options, {},
callbackPass(function(win) { callbackPass(function(win) {
// Check that isAlwaysOnTop() returns false because the manifest did not chrome.test.assertFalse(win.isAlwaysOnTop());
// specify the "app.window.alwaysOnTop" permission.
chrome.test.assertEq(false, win.isAlwaysOnTop());
// Attempt to use setAlwaysOnTop() to change the property. But this should // Attempt to use setAlwaysOnTop() to change the property.
// also fail.
win.setAlwaysOnTop(value); win.setAlwaysOnTop(value);
// setAlwaysOnTop is synchronous in the browser, so send an async request to // setAlwaysOnTop() is synchronous in the browser, so send an async request
// ensure we get the updated value of isAlwaysOnTop. // to ensure we get the updated value of isAlwaysOnTop().
chrome.test.waitForRoundTrip("msg", callbackPass(function(platformInfo) { chrome.test.waitForRoundTrip("", callbackPass(function() {
// Check that isAlwaysOnTop() returns false. // Check that isAlwaysOnTop() always returns false.
chrome.test.assertEq(false, win.isAlwaysOnTop()); chrome.test.assertFalse(win.isAlwaysOnTop());
win.contentWindow.close(); win.contentWindow.close();
})); }));
...@@ -35,14 +28,43 @@ function testAlwaysOnTop(testId, value) { ...@@ -35,14 +28,43 @@ function testAlwaysOnTop(testId, value) {
chrome.app.runtime.onLaunched.addListener(function() { chrome.app.runtime.onLaunched.addListener(function() {
chrome.test.runTests([ chrome.test.runTests([
// Try to enable alwaysOnTop on window creation and after window creation. // Attempting to create an alwaysOnTop window without the permission should
function testAlwaysOnTopEnable() { // fail to create a window.
testAlwaysOnTop('testAlwaysOnTopEnable', true); function testCreateAlwaysOnTopEnabled() {
var options = {
alwaysOnTop: true
};
chrome.app.window.create(
'index.html', options,
callbackFail('The "app.window.alwaysOnTop" permission is required.'));
},
// Setting the alwaysOnTop property to false without the permission should
// still result in a window being created.
function testCreateAlwaysOnTopDisabled() {
var options = {
alwaysOnTop: false
};
chrome.app.window.create('index.html',
options,
callbackPass(function(win) {
chrome.test.assertFalse(win.isAlwaysOnTop());
win.contentWindow.close();
}));
},
// Enabling the alwaysOnTop property after window creation without the
// permission should fail.
function testSetAlwaysOnTopEnabled() {
setAlwaysOnTop(true);
}, },
// Try to disable alwaysOnTop on window creation and after window creation. // Disabling the alwaysOnTop property after window creation without the
function testAlwaysOnTopDisable() { // permission should not change the property.
testAlwaysOnTop('testAlwaysOnTopDisable', false); function testSetAlwaysOnTopDisabled() {
setAlwaysOnTop(false);
} }
]); ]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment