Commit fbd998cf authored by Alexander Hendrich's avatar Alexander Hendrich Committed by Commit Bot

[Extensions] Add API test for chrome.loginScreenUi

This CL adds an api test for the new chrome.loginScreenUi API. It checks
availability (only available to whitelisted extension on unknown, trunk
and dev browser channel). It also checks that the API can only be called
from the login/lock screen, that windows are automatically closed when
login in or unlocking and that appropiate error messages are emitted
when opening two windows or closing non-existent windows.

Bug: 957573
Change-Id: I95c72e2462da0b316f87bcbf3d8ed601e33cc4e7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1598824
Commit-Queue: Alexander Hendrich <hendrich@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664616}
parent 8cef6682
// Copyright 2019 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 "chrome/browser/chromeos/extensions/login_screen_ui/login_screen_extension_ui_handler.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "components/session_manager/core/session_manager.h"
#include "components/version_info/version_info.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/api/test/test_api.h"
#include "extensions/common/features/feature_channel.h"
namespace extensions {
// Class for testing the loginScreenUi API using different browser channels.
class LoginScreenUiApiPerChannelTest
: public ExtensionApiTest,
public testing::WithParamInterface<version_info::Channel> {
public:
LoginScreenUiApiPerChannelTest()
: channel_(GetParam()), scoped_current_channel_(GetParam()) {}
protected:
const version_info::Channel channel_;
const extensions::ScopedCurrentChannel scoped_current_channel_;
DISALLOW_COPY_AND_ASSIGN(LoginScreenUiApiPerChannelTest);
};
// Api not available on all browser channels for non-whitelisted extension.
IN_PROC_BROWSER_TEST_P(LoginScreenUiApiPerChannelTest,
NotAvailableForNotWhitelistedExtension) {
EXPECT_TRUE(RunExtensionSubtest(
"login_screen_ui/not_whitelisted_extension.crx", "test.html",
kFlagLoadForLoginScreen | kFlagIgnoreManifestWarnings))
<< message_;
}
// API available to whitelisted extension on unknown, canary and dev browser
// channels, but not on beta and stable channels.
IN_PROC_BROWSER_TEST_P(LoginScreenUiApiPerChannelTest,
AvailableForWhitelistedExtension) {
const std::string whitelisted_extension =
"login_screen_ui/whitelisted_extension.crx";
switch (channel_) {
case version_info::Channel::UNKNOWN:
case version_info::Channel::CANARY:
case version_info::Channel::DEV:
EXPECT_TRUE(RunExtensionSubtest(whitelisted_extension,
"test.html?apiAvailable",
kFlagLoadForLoginScreen))
<< message_;
break;
case version_info::Channel::BETA:
case version_info::Channel::STABLE:
EXPECT_TRUE(RunExtensionSubtest(
whitelisted_extension, "test.html?apiNotAvailable",
kFlagLoadForLoginScreen | kFlagIgnoreManifestWarnings))
<< message_;
break;
}
}
INSTANTIATE_TEST_SUITE_P(,
LoginScreenUiApiPerChannelTest,
testing::Values(version_info::Channel::UNKNOWN,
version_info::Channel::CANARY,
version_info::Channel::DEV,
version_info::Channel::BETA,
version_info::Channel::STABLE));
} // namespace extensions
...@@ -1829,6 +1829,7 @@ if (!is_android) { ...@@ -1829,6 +1829,7 @@ if (!is_android) {
"../browser/chromeos/extensions/incoming_native_messaging_apitest.cc", "../browser/chromeos/extensions/incoming_native_messaging_apitest.cc",
"../browser/chromeos/extensions/info_private_apitest.cc", "../browser/chromeos/extensions/info_private_apitest.cc",
"../browser/chromeos/extensions/input_method_apitest_chromeos.cc", "../browser/chromeos/extensions/input_method_apitest_chromeos.cc",
"../browser/chromeos/extensions/login_screen_ui/login_screen_ui_apitest.cc",
"../browser/chromeos/extensions/users_private/users_private_apitest.cc", "../browser/chromeos/extensions/users_private/users_private_apitest.cc",
"../browser/chromeos/extensions/wallpaper_apitest.cc", "../browser/chromeos/extensions/wallpaper_apitest.cc",
"../browser/chromeos/extensions/wallpaper_manager_browsertest.cc", "../browser/chromeos/extensions/wallpaper_manager_browsertest.cc",
......
The whitelisted_extension.crx package must be signed by WebStore, in order for
the extension to have the expected ID which is whitelisted in Chrome:
"oclffehlkdgibkainkilopaalpdobkan".
The not_whitelisted_extension.crx can be packed using the private key
./not_whitelisted_extension.pem. For the instructions, refer to:
<https://developer.chrome.com/extensions/packaging#creating>.
These extensions are intended to be used for the manual testing of the
chrome.loginScreenUi API.
In case a new version of the test extension has to be published on WebStore,
please reach out to the managed-devices@ mailing list.
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCx73TkYXs82V8P
asE7rbSaoIuY4RG0FzKNzntXN0t6oW3vCWPtm4CPeLZK4aTt2X/bggeaTTZHXSkS
SBVYev3Gk/93bEw4PDt1R0EnYb4cuwNfuuy8Eer43FKTuD5UfM8mhIsOCio5LigC
MHR/EJzkoAxVBqYETTRXTyLP4UZivzMc462MILD7tZAnC/s3WLoXgLVxqXpnALYh
95Prj/EosBHX/rk9JOsBUQP6k4cwxAyjaZ/8Ufr8BZvA77wWyK9tDDRjbpBhhcD1
VU2aq9yCB9gp+b0jhV2RX7k7LunLz3ZK6FC0xXV8piyRKAXtwe7PnR0Suc0Nyn8V
dxmxtWCzAgMBAAECggEATZjcdMaQTIKNYrdPKrv/sZlHF7Y7lrqxGMeN4YSjPYkN
3LtPIW15vNfLQ8+wsetyx2Mm9qMqgye9BBR8fpgwePvM4qNPgAzAb05SOx70ninu
eD6YBBKaUsoelv437Hd7jVQrIkXLkSEwYHgKLemsSkYD6saZ+vFCXLsNtvOK0v/M
rFuJ3rZ4xf5QoVLbt5nnD9L6CWbVqmUx0YsM1TCw9bMtRjaW3LI65Hi4ekLx/fMo
sELs8DE2SjOEDkp1PpmU1zyNHypeLjEV++CIW4hw/+yW5aGs0suknXExfdmUH4D3
s2ZBmgmK97qZFyeBiGAV19QL86h0s2h+lTjgvaDEFQKBgQDvCveTWoCaHvxX+Onf
HPdzQvXg0jilMOlop1QfNzysNeZl2fbzExG3wvFgPIrBxwragy5ByqSjeEJ0bzdn
Xy33EiWTJigrenwy5+brgjUYOVbCswcj7O7pHDLeY2rUIFSDkdBAuSlqhxxw1xm6
DEdha7s2GfPAiyjacmPD4i8dDQKBgQC+jsYwag+zN/giJz/w88qezi6whad9I1O4
osf606KB6WmzXE0aDxqrbdBskiUXZhXg9PV4D67w3KsWf9lp8xqVhbeR+XOUdJt1
/m6pyb3FEslpv98nJOSlr3vJMT9QHnivQ22/H7yn4Iq3OmANGePMA9A9nfLqoYy9
3gy/XuSEvwKBgQCSce+W0L00roL+CjqNO5vFe2JTJ7cYTMzSFqEMtrRu9F6AS3Zl
GGukXsOtp6mCacSWdgNivxj6JPThjDkvFTp9wRpP+fJmIJXyQexQn+aTPp2Ojktz
kPYUzffEErgh2OSt7ijdXhKndrrPzpeuSVN5tZxt2pxge2C945KHMQyYCQKBgAc+
MARJE72xI+pQaZrD+XCdz6KAAgS8ogMDlOxQvP2JHK5nlLqn1lCrxN9LksNX6v74
8JeWqQSYrpwVUfM3/UuvoHGY9K6w2/PZLuWfOGpUM3mkhFvdiB9QEzlreMeX0OiA
fJxmHWqYG02pl1sIH+NyRakB5ujKKSpSVVO0zKTLAoGADOkc3VDDpNihH0ppUYQw
1zGwH/vq6WaidkO9TOWgZ+lPoXaspr7K8Z3Ssq5n1zKXlcbDWWdAqHsDAPYrdkcy
pcIXjxC910A09wmON/QNWGRWtb775gXZCzRbaX1GwmXEg6iAvMp4vwvoSO29cU06
HmSqRl1Dh42+y+EhSgmuIso=
-----END PRIVATE KEY-----
{
"name": "loginScreenUi API test extension",
"version": "0.1",
"manifest_version": 2,
"description": "Test of chrome.loginScreenUi interface",
"permissions": [
"loginScreenUi"
]
}
<!--
* Copyright 2019 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.
-->
<script src="test.js"></script>
<html>
<head><title>loginScreenUi component API interface test</title></head>
<body><h2>chrome.loginScreenUi.* tests</h2></body>
</html>
// Copyright 2019 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.
if (chrome.loginScreenUi)
chrome.test.fail('API available');
else
chrome.test.succeed();
{
"name": "chrome.loginScreenUi extension tests",
"version": "1.3",
"manifest_version": 2,
"description": "Test of chrome.loginScreenUi interface",
"permissions": [
"loginScreenUi"
]
}
<!--
* Copyright 2019 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.
-->
<script src="test.js"></script>
<html>
<head><title>loginScreenUi component API interface test</title></head>
<body><h2>chrome.loginScreenUi.* tests</h2></body>
</html>
// Copyright 2019 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 isApiAvailable() {
return chrome && chrome.hasOwnProperty('loginScreenUi') &&
chrome.loginScreenUi.hasOwnProperty('show') &&
chrome.loginScreenUi.hasOwnProperty('close') &&
typeof chrome.loginScreenUi.show === 'function' &&
typeof chrome.loginScreenUi.close === 'function';
}
var availableTests = [
function apiAvailable() {
chrome.test.assertTrue(isApiAvailable());
chrome.test.succeed();
},
function apiNotAvailable() {
chrome.test.assertFalse(isApiAvailable());
chrome.test.succeed();
},
];
var testToRun = window.location.search.substring(1);
chrome.test.runTests(availableTests.filter(function(op) {
return op.name == testToRun;
}));
<!--
* Copyright 2019 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>
<head><title>loginScreenUi component API interface test</title></head>
<body><h2>chrome.loginScreenUi.* tests</h2></body>
</html>
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