Commit 72508a5f authored by Tim Zheng's avatar Tim Zheng Committed by Commit Bot

Add autotest API for setting a Crostini app scaled.

To set a Crostini app scaled is to set the property in the Crostini app
registry so that when the app launches it'll use low display density.

BUG=chromium:839242
TEST=unit test included in this CL

Change-Id: I1428a49cce918930f8b5d4083fbc9ba208e8b101
Reviewed-on: https://chromium-review.googlesource.com/c/1393547
Commit-Queue: Tim Zheng <timzheng@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarDan Erat <derat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619728}
parent 0748bf4e
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include "chrome/browser/chromeos/arc/arc_util.h" #include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/crostini/crostini_manager.h" #include "chrome/browser/chromeos/crostini/crostini_manager.h"
#include "chrome/browser/chromeos/crostini/crostini_pref_names.h" #include "chrome/browser/chromeos/crostini/crostini_pref_names.h"
#include "chrome/browser/chromeos/crostini/crostini_registry_service.h"
#include "chrome/browser/chromeos/crostini/crostini_registry_service_factory.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h" #include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/login/lock/screen_locker.h" #include "chrome/browser/chromeos/login/lock/screen_locker.h"
#include "chrome/browser/chromeos/printing/cups_printers_manager.h" #include "chrome/browser/chromeos/printing/cups_printers_manager.h"
...@@ -1280,6 +1282,36 @@ void AutotestPrivateSendAssistantTextQueryFunction::Timeout() { ...@@ -1280,6 +1282,36 @@ void AutotestPrivateSendAssistantTextQueryFunction::Timeout() {
Respond(Error("Assistant response timeout.")); Respond(Error("Assistant response timeout."));
} }
///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateSetCrostiniAppScaledFunction
///////////////////////////////////////////////////////////////////////////////
AutotestPrivateSetCrostiniAppScaledFunction::
~AutotestPrivateSetCrostiniAppScaledFunction() = default;
ExtensionFunction::ResponseAction
AutotestPrivateSetCrostiniAppScaledFunction::Run() {
std::unique_ptr<api::autotest_private::SetCrostiniAppScaled::Params> params(
api::autotest_private::SetCrostiniAppScaled::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
DVLOG(1) << "AutotestPrivateSetCrostiniAppScaledFunction " << params->app_id
<< " " << params->scaled;
ChromeLauncherController* const controller =
ChromeLauncherController::instance();
if (!controller)
return RespondNow(Error("Controller not available"));
crostini::CrostiniRegistryService* registry_service =
crostini::CrostiniRegistryServiceFactory::GetForProfile(
controller->profile());
if (!registry_service)
return RespondNow(Error("Crostini registry not available"));
registry_service->SetAppScaled(params->app_id, params->scaled);
return RespondNow(NoArguments());
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateAPI // AutotestPrivateAPI
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
......
...@@ -492,6 +492,18 @@ class AutotestPrivateSendAssistantTextQueryFunction ...@@ -492,6 +492,18 @@ class AutotestPrivateSendAssistantTextQueryFunction
std::unique_ptr<base::DictionaryValue> result_; std::unique_ptr<base::DictionaryValue> result_;
}; };
// Enable/disable a Crostini app's "scaled" property.
// When an app is "scaled", it will use low display density.
class AutotestPrivateSetCrostiniAppScaledFunction
: public UIThreadExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("autotestPrivate.setCrostiniAppScaled",
AUTOTESTPRIVATE_SETCROSTINIAPPSCALED)
private:
~AutotestPrivateSetCrostiniAppScaledFunction() override;
ResponseAction Run() override;
};
// The profile-keyed service that manages the autotestPrivate extension API. // The profile-keyed service that manages the autotestPrivate extension API.
class AutotestPrivateAPI : public BrowserContextKeyedAPI { class AutotestPrivateAPI : public BrowserContextKeyedAPI {
public: public:
......
...@@ -284,5 +284,11 @@ namespace autotestPrivate { ...@@ -284,5 +284,11 @@ namespace autotestPrivate {
// |callback|: Called when response has been received. // |callback|: Called when response has been received.
static void sendAssistantTextQuery(DOMString query, long timeout_ms, static void sendAssistantTextQuery(DOMString query, long timeout_ms,
AssistantQueryResponseCallback callback); AssistantQueryResponseCallback callback);
// Enable/disable a Crostini app's "scaled" property.
// |appId|: The Crostini application ID.
// |scaled|: The app is "scaled" when shown, which means it uses low display density.
// |callback|: Called when the operation has completed.
static void setCrostiniAppScaled(DOMString appId, boolean scaled, VoidCallback callback);
}; };
}; };
...@@ -190,6 +190,17 @@ var defaultTests = [ ...@@ -190,6 +190,17 @@ var defaultTests = [
chrome.autotestPrivate.runCrostiniInstaller(chrome.test.callbackFail( chrome.autotestPrivate.runCrostiniInstaller(chrome.test.callbackFail(
'Crostini is not available for the current user')); 'Crostini is not available for the current user'));
}, },
// This sets a Crostini app's "scaled" property in the app registry.
// When the property is set to true, the app will be launched in low display
// density.
function setCrostiniAppScaled() {
chrome.autotestPrivate.setCrostiniAppScaled(
'nodabfiipdopnjihbfpiengllkohmfkl', true,
function() {
chrome.test.assertNoLastError();
chrome.test.succeed();
});
},
function bootstrapMachineLearningService() { function bootstrapMachineLearningService() {
chrome.autotestPrivate.bootstrapMachineLearningService( chrome.autotestPrivate.bootstrapMachineLearningService(
chrome.test.callbackFail('ML Service connection error')); chrome.test.callbackFail('ML Service connection error'));
......
...@@ -1366,6 +1366,7 @@ enum HistogramValue { ...@@ -1366,6 +1366,7 @@ enum HistogramValue {
AUTOTESTPRIVATE_CLOSEAPP = 1303, AUTOTESTPRIVATE_CLOSEAPP = 1303,
ACCESSIBILITY_PRIVATE_SETSWITCHACCESSMENUSTATE = 1304, ACCESSIBILITY_PRIVATE_SETSWITCHACCESSMENUSTATE = 1304,
AUTOTESTPRIVATE_SENDASSISTANTTEXTQUERY = 1305, AUTOTESTPRIVATE_SENDASSISTANTTEXTQUERY = 1305,
AUTOTESTPRIVATE_SETCROSTINIAPPSCALED = 1306,
// Last entry: Add new entries above, then run: // Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py // python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY ENUM_BOUNDARY
......
...@@ -17585,6 +17585,7 @@ Called by update_net_error_codes.py.--> ...@@ -17585,6 +17585,7 @@ Called by update_net_error_codes.py.-->
<int value="1303" label="AUTOTESTPRIVATE_CLOSEAPP"/> <int value="1303" label="AUTOTESTPRIVATE_CLOSEAPP"/>
<int value="1304" label="ACCESSIBILITY_PRIVATE_SETSWITCHACCESSMENUSTATE"/> <int value="1304" label="ACCESSIBILITY_PRIVATE_SETSWITCHACCESSMENUSTATE"/>
<int value="1305" label="AUTOTESTPRIVATE_SENDASSISTANTTEXTQUERY"/> <int value="1305" label="AUTOTESTPRIVATE_SENDASSISTANTTEXTQUERY"/>
<int value="1306" label="AUTOTESTPRIVATE_SETCROSTINIAPPSCALED"/>
</enum> </enum>
<enum name="ExtensionIconState"> <enum name="ExtensionIconState">
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