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[] =
"frame.inactiveColor must be used with frame.color.";
const char kConflictingBoundsOptions[] =
"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
const char kNoneFrameOption[] = "none";
......@@ -234,10 +236,16 @@ bool AppWindowCreateFunction::RunAsync() {
if (options->resizable.get())
create_params.resizable = *options->resizable.get();
if (options->always_on_top.get() &&
GetExtension()->HasAPIPermission(APIPermission::kAlwaysOnTopWindows))
if (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())
create_params.focused = *options->focused.get();
......
......@@ -3,29 +3,22 @@
// found in the LICENSE file.
var callbackPass = chrome.test.callbackPass;
var callbackFail = chrome.test.callbackFail;
function testAlwaysOnTop(testId, value) {
var options = {
id: testId,
alwaysOnTop: value
};
function setAlwaysOnTop(value) {
chrome.app.window.create('index.html',
options,
{},
callbackPass(function(win) {
// Check that isAlwaysOnTop() returns false because the manifest did not
// specify the "app.window.alwaysOnTop" permission.
chrome.test.assertEq(false, win.isAlwaysOnTop());
chrome.test.assertFalse(win.isAlwaysOnTop());
// Attempt to use setAlwaysOnTop() to change the property. But this should
// also fail.
// Attempt to use setAlwaysOnTop() to change the property.
win.setAlwaysOnTop(value);
// setAlwaysOnTop is synchronous in the browser, so send an async request to
// ensure we get the updated value of isAlwaysOnTop.
chrome.test.waitForRoundTrip("msg", callbackPass(function(platformInfo) {
// Check that isAlwaysOnTop() returns false.
chrome.test.assertEq(false, win.isAlwaysOnTop());
// setAlwaysOnTop() is synchronous in the browser, so send an async request
// to ensure we get the updated value of isAlwaysOnTop().
chrome.test.waitForRoundTrip("", callbackPass(function() {
// Check that isAlwaysOnTop() always returns false.
chrome.test.assertFalse(win.isAlwaysOnTop());
win.contentWindow.close();
}));
......@@ -35,14 +28,43 @@ function testAlwaysOnTop(testId, value) {
chrome.app.runtime.onLaunched.addListener(function() {
chrome.test.runTests([
// Try to enable alwaysOnTop on window creation and after window creation.
function testAlwaysOnTopEnable() {
testAlwaysOnTop('testAlwaysOnTopEnable', true);
// Attempting to create an alwaysOnTop window without the permission should
// fail to create a window.
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.
function testAlwaysOnTopDisable() {
testAlwaysOnTop('testAlwaysOnTopDisable', false);
// Disabling the alwaysOnTop property after window creation without the
// permission should not change the property.
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