Commit d369e7db authored by Felix Ekblom's avatar Felix Ekblom Committed by Commit Bot

Add callback to cecPrivate actions and an API test

This CL add a callback to sendStandBy() and sendWakeUp() that is run
once requests have been been made on D-Bus to put displays to sleep
or wake them up.

Additionally, an API test is added ensuring that calls to the functions
propagate to the D-Bus client.

BUG=b:78171027

Change-Id: I7c529ce328bcd8ce67d96d357f71dfbc0da229cf
Reviewed-on: https://chromium-review.googlesource.com/1053780Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Commit-Queue: Felix Ekblom <felixe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561451}
parent 8e2725e5
......@@ -15,12 +15,12 @@ FakeCecServiceClient::~FakeCecServiceClient() = default;
void FakeCecServiceClient::SendStandBy() {
stand_by_call_count_++;
last_set_state_ = kStandBy;
SetDisplayPowerState(PowerState::kStandBy);
}
void FakeCecServiceClient::SendWakeUp() {
wake_up_call_count_++;
last_set_state_ = kAwake;
SetDisplayPowerState(PowerState::kOn);
}
void FakeCecServiceClient::QueryDisplayCecPowerState(
......@@ -31,4 +31,10 @@ void FakeCecServiceClient::QueryDisplayCecPowerState(
void FakeCecServiceClient::Init(dbus::Bus* bus) {}
void FakeCecServiceClient::SetDisplayPowerState(PowerState new_state) {
for (size_t i = 0; i < tv_power_states_.size(); i++) {
tv_power_states_[i] = new_state;
}
}
} // namespace chromeos
......@@ -17,8 +17,6 @@ class CHROMEOS_EXPORT FakeCecServiceClient : public CecServiceClient {
FakeCecServiceClient();
~FakeCecServiceClient() override;
enum CurrentState { kUndefined, kStandBy, kAwake };
// CecServiceClient
void SendStandBy() override;
void SendWakeUp() override;
......@@ -28,8 +26,6 @@ class CHROMEOS_EXPORT FakeCecServiceClient : public CecServiceClient {
int stand_by_call_count() const { return stand_by_call_count_; }
int wake_up_call_count() const { return wake_up_call_count_; }
CurrentState last_set_state() const { return last_set_state_; }
void set_tv_power_states(const std::vector<PowerState>& power_states) {
tv_power_states_ = power_states;
}
......@@ -41,9 +37,10 @@ class CHROMEOS_EXPORT FakeCecServiceClient : public CecServiceClient {
void Init(dbus::Bus* bus) override;
private:
void SetDisplayPowerState(PowerState new_state);
int stand_by_call_count_ = 0;
int wake_up_call_count_ = 0;
CurrentState last_set_state_ = kUndefined;
std::vector<PowerState> tv_power_states_;
......
......@@ -480,6 +480,7 @@ source_set("browser_tests") {
}
if (is_chromeos) {
sources += [
"api/cec_private/cec_private_apitest.cc",
"api/media_perception_private/media_perception_private_apitest.cc",
"api/virtual_keyboard/virtual_keyboard_apitest.cc",
]
......
// Copyright 2018 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 "base/macros.h"
#include "chromeos/dbus/cec_service_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_cec_service_client.h"
#include "extensions/common/features/feature_session_type.h"
#include "extensions/common/switches.h"
#include "extensions/shell/test/shell_apitest.h"
#include "extensions/test/extension_test_message_listener.h"
#include "extensions/test/result_catcher.h"
namespace extensions {
namespace {
constexpr char kTestAppId[] = "jabiebdnficieldhmegebckfhpfidfla";
class CecPrivateKioskApiTest : public ShellApiTest {
public:
CecPrivateKioskApiTest()
: session_type_(
ScopedCurrentFeatureSessionType(FeatureSessionType::KIOSK)) {}
~CecPrivateKioskApiTest() override = default;
void SetUpOnMainThread() override {
cec_ = static_cast<chromeos::FakeCecServiceClient*>(
chromeos::DBusThreadManager::Get()->GetCecServiceClient());
}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(
extensions::switches::kWhitelistedExtensionID, kTestAppId);
ShellApiTest::SetUpCommandLine(command_line);
}
protected:
chromeos::FakeCecServiceClient* cec_ = nullptr;
private:
std::unique_ptr<base::AutoReset<FeatureSessionType>> session_type_;
DISALLOW_COPY_AND_ASSIGN(CecPrivateKioskApiTest);
};
using CecPrivateNonKioskApiTest = ShellApiTest;
} // namespace
IN_PROC_BROWSER_TEST_F(CecPrivateKioskApiTest, TestAllApiFunctions) {
cec_->set_tv_power_states({chromeos::CecServiceClient::PowerState::kOn,
chromeos::CecServiceClient::PowerState::kOn});
extensions::ResultCatcher catcher;
ExtensionTestMessageListener standby_call_count("standby_call_count", true);
ExtensionTestMessageListener wakeup_call_count("wakeup_call_count", true);
ASSERT_TRUE(LoadApp("api_test/cec_private/api"));
ASSERT_TRUE(standby_call_count.WaitUntilSatisfied())
<< standby_call_count.message();
standby_call_count.Reply(cec_->stand_by_call_count());
ASSERT_TRUE(wakeup_call_count.WaitUntilSatisfied())
<< wakeup_call_count.message();
wakeup_call_count.Reply(cec_->wake_up_call_count());
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
IN_PROC_BROWSER_TEST_F(CecPrivateNonKioskApiTest, TestCecPrivateNotAvailable) {
ASSERT_TRUE(RunAppTest("api_test/cec_private/non_kiosk_api_not_available"))
<< message_;
}
} // namespace extensions
......@@ -161,7 +161,9 @@
},
"cecPrivate": {
"channel": "stable",
"extension_types": ["extension", "platform_app"],
"extension_types": ["platform_app"],
"platforms": ["chromeos"],
"session_types": ["kiosk"],
"whitelist": [
"1C93BD3CF875F4A73C0B2A163BB8FBDA8B8B3D80", // http://crbug.com/824667#c15
"A3BC37E2148AC4E99BE4B16AF9D42DD1E592BBBE", // http://crbug.com/824667#c15
......
......@@ -36,17 +36,25 @@ namespace cecPrivate {
callback DisplayCecPowerStateCallback =
void(DisplayCecPowerState[] powerStates);
callback ChangePowerStateCallback = void();
interface Functions {
// Attempt to put all HDMI CEC compatible devices in standby.
//
// This is not guaranteed to have any effect on the connected displays.
// Displays that do not support HDMI CEC will not be affected.
static void sendStandBy();
//
// |callback| will be run as soon as all displays have been requested to
// change their power state.
static void sendStandBy(optional ChangePowerStateCallback callback);
// Attempt to announce this device as the active input source towards all
// HDMI CEC enabled displays connected, waking them from standby if
// necessary.
static void sendWakeUp();
//
// |callback| will be run as soon as all displays have been requested to
// change their power state.
static void sendWakeUp(optional ChangePowerStateCallback callback);
// Queries all HDMI CEC capable displays for their current power state.
static void queryDisplayCecPowerState(
......
// Copyright 2018 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.test.runTests([
function getInitialState() {
chrome.cecPrivate.queryDisplayCecPowerState(
chrome.test.callbackPass(state => {
chrome.test.assertEq(['on', 'on'], state);
}));
},
function sendStandBy() {
chrome.cecPrivate.sendStandBy(chrome.test.callbackPass(
() => chrome.test.sendMessage(
'standby_call_count',
chrome.test.callbackPass(
count => chrome.test.assertEq(1, parseInt(count, 10))))));
},
function getStandByStateState() {
chrome.cecPrivate.queryDisplayCecPowerState(chrome.test.callbackPass(
state => chrome.test.assertEq(['standby', 'standby'], state)));
},
function sendWakeup() {
chrome.cecPrivate.sendWakeUp(chrome.test.callbackPass(
() => chrome.test.sendMessage(
'wakeup_call_count',
chrome.test.callbackPass(
count => chrome.test.assertEq(1, parseInt(count, 10))))));
},
function getWokeUpState() {
chrome.cecPrivate.queryDisplayCecPowerState(chrome.test.callbackPass(
state => chrome.test.assertEq(['on', 'on'], state)));
}
]);
{
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Vj3NOQEKvLt7z6PjCTXBcazmfpMw7464q3DVljy24r6sOaF5zGqu+ZJqDDqRcqkVwCCHVda420Dka73cq6wg0M+6oEtLFvP4XVsnSVAywZI6L1jJ106/ndo3VoUiMcNCFv8NWra+CpsKugCw1jUNb05tuKNJvNR4nI7hDj6iQx4U8PNuo6fJUZWl+jcxf/fFmcH54ZdyL5KuZSHAPzZPEUBVG15KLlqpaSprTdbYLqUpzF9KIEX/rgxncUXVq0yaRIlSa7I++IaxSmujBjdsiArFaAq+yCZBBQiEKNuTMveQhFBeTAq5oBJ9nOH9VYmVbg3WjUMdeszjwE9B87kowIDAQAB",
"name": "chrome.cecPrivate",
"manifest_version": 2,
"version": "0.1",
"description": "end-to-end browser tests for chrome.cecPrivate API",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [
"cecPrivate"
],
"kiosk_enabled": true
}
// Copyright 2018 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.test.runTests([
function ensureCecPrivateNotDefined() {
chrome.test.assertTrue(typeof chrome.cecPrivate === 'undefined');
chrome.test.succeed();
},
]);
{
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0Vj3NOQEKvLt7z6PjCTXBcazmfpMw7464q3DVljy24r6sOaF5zGqu+ZJqDDqRcqkVwCCHVda420Dka73cq6wg0M+6oEtLFvP4XVsnSVAywZI6L1jJ106/ndo3VoUiMcNCFv8NWra+CpsKugCw1jUNb05tuKNJvNR4nI7hDj6iQx4U8PNuo6fJUZWl+jcxf/fFmcH54ZdyL5KuZSHAPzZPEUBVG15KLlqpaSprTdbYLqUpzF9KIEX/rgxncUXVq0yaRIlSa7I++IaxSmujBjdsiArFaAq+yCZBBQiEKNuTMveQhFBeTAq5oBJ9nOH9VYmVbg3WjUMdeszjwE9B87kowIDAQAB",
"name": "chrome.cecPrivate",
"manifest_version": 2,
"version": "0.1",
"description": "Verify that cecPrivate is not available outside kiosk mode",
"app": {
"background": {
"scripts": ["background.js"]
}
},
"permissions": [
"cecPrivate"
]
}
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