Skip to content

Commit

Permalink
Add ability to get all installed apps to autotestPrivate
Browse files Browse the repository at this point in the history
Added AutotestPrivateGetAllInstalledAppsFunction to autotestPrivate api.
Created enums for AppType and AppReadiness in autotest_private_api.idl
Added test case to confirm that all default apps are available. Updated
HistogramValue enum for extension functions with new item.

Test: locally on eve and browser_tests --gtest_filter="AutotestPrivateApiTest.AutotestPrivate"
Bug: 989231
Change-Id: Id8a83335d7ad0922480652bb871e200e470d923a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1742394
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Reviewed-by: Toni Baržić <tbarzic@chromium.org>
Commit-Queue: Brendan Hansknecht <bhansknecht@chromium.org>
Cr-Commit-Position: refs/heads/master@{#687305}
  • Loading branch information
Brendan Hansknecht authored and Commit Bot committed Aug 15, 2019
1 parent 97af437 commit fa7c3b0
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/assistant/assistant_util.h"
Expand Down Expand Up @@ -69,6 +71,7 @@
#include "chrome/common/extensions/api/autotest_private.h"
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/pref_names.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/session_manager/session_manager_client.h"
#include "chromeos/printing/printer_configuration.h"
Expand Down Expand Up @@ -228,6 +231,64 @@ api::autotest_private::ShelfItemStatus GetShelfItemStatus(
return api::autotest_private::ShelfItemStatus::SHELF_ITEM_STATUS_NONE;
}

api::autotest_private::AppType GetAppType(apps::mojom::AppType type) {
switch (type) {
case apps::mojom::AppType::kArc:
return api::autotest_private::AppType::APP_TYPE_ARC;
case apps::mojom::AppType::kBuiltIn:
return api::autotest_private::AppType::APP_TYPE_BUILTIN;
case apps::mojom::AppType::kCrostini:
return api::autotest_private::AppType::APP_TYPE_CROSTINI;
case apps::mojom::AppType::kExtension:
return api::autotest_private::AppType::APP_TYPE_EXTENSION;
case apps::mojom::AppType::kWeb:
return api::autotest_private::AppType::APP_TYPE_WEB;
case apps::mojom::AppType::kUnknown:
return api::autotest_private::AppType::APP_TYPE_NONE;
}
NOTREACHED();
return api::autotest_private::AppType::APP_TYPE_NONE;
}

api::autotest_private::AppReadiness GetAppReadiness(
apps::mojom::Readiness readiness) {
switch (readiness) {
case apps::mojom::Readiness::kReady:
return api::autotest_private::AppReadiness::APP_READINESS_READY;
case apps::mojom::Readiness::kDisabledByBlacklist:
return api::autotest_private::AppReadiness::
APP_READINESS_DISABLEDBYBLACKLIST;
case apps::mojom::Readiness::kDisabledByPolicy:
return api::autotest_private::AppReadiness::
APP_READINESS_DISABLEDBYPOLICY;
case apps::mojom::Readiness::kDisabledByUser:
return api::autotest_private::AppReadiness::APP_READINESS_DISABLEDBYUSER;
case apps::mojom::Readiness::kTerminated:
return api::autotest_private::AppReadiness::APP_READINESS_TERMINATED;
case apps::mojom::Readiness::kUninstalledByUser:
return api::autotest_private::AppReadiness::
APP_READINESS_UNINSTALLEDBYUSER;
case apps::mojom::Readiness::kUnknown:
return api::autotest_private::AppReadiness::APP_READINESS_NONE;
}
NOTREACHED();
return api::autotest_private::AppReadiness::APP_READINESS_NONE;
}

std::unique_ptr<bool> ConvertMojomOptionalBool(
apps::mojom::OptionalBool optional) {
switch (optional) {
case apps::mojom::OptionalBool::kTrue:
return std::make_unique<bool>(true);
case apps::mojom::OptionalBool::kFalse:
return std::make_unique<bool>(false);
case apps::mojom::OptionalBool::kUnknown:
return nullptr;
}
NOTREACHED();
return nullptr;
}

// Helper function to set whitelisted user pref based on |pref_name| with any
// specific pref validations. Returns error messages if any.
std::string SetWhitelistedPref(Profile* profile,
Expand Down Expand Up @@ -1758,6 +1819,46 @@ AutotestPrivateSetTabletModeEnabledFunction::Run() {
std::make_unique<base::Value>(ash::TabletMode::Get()->InTabletMode())));
}

///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateGetAllInstalledAppsFunction
///////////////////////////////////////////////////////////////////////////////
AutotestPrivateGetAllInstalledAppsFunction::
AutotestPrivateGetAllInstalledAppsFunction() = default;

AutotestPrivateGetAllInstalledAppsFunction::
~AutotestPrivateGetAllInstalledAppsFunction() = default;

ExtensionFunction::ResponseAction
AutotestPrivateGetAllInstalledAppsFunction::Run() {
DVLOG(1) << "AutotestPrivateGetAllInstalledAppsFunction";

Profile* const profile = Profile::FromBrowserContext(browser_context());
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(profile);

if (!proxy)
return RespondNow(Error("App Service not available"));

std::vector<api::autotest_private::App> installed_apps;
proxy->AppRegistryCache().ForEachApp([&installed_apps](
const apps::AppUpdate& update) {
api::autotest_private::App app;
app.app_id = update.AppId();
app.name = update.Name();
app.short_name = update.ShortName();
app.additional_search_terms = update.AdditionalSearchTerms();
app.type = GetAppType(update.AppType());
app.readiness = GetAppReadiness(update.Readiness());
app.show_in_launcher = ConvertMojomOptionalBool(update.ShowInLauncher());
app.show_in_search = ConvertMojomOptionalBool(update.ShowInSearch());
installed_apps.emplace_back(std::move(app));
});

return RespondNow(
ArgumentList(api::autotest_private::GetAllInstalledApps::Results::Create(
installed_apps)));
}

///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateGetShelfItemsFunction
///////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,18 @@ class AutotestPrivateSetTabletModeEnabledFunction : public ExtensionFunction {
ResponseAction Run() override;
};

// Returns a list of all installed applications
class AutotestPrivateGetAllInstalledAppsFunction : public ExtensionFunction {
public:
AutotestPrivateGetAllInstalledAppsFunction();
DECLARE_EXTENSION_FUNCTION("autotestPrivate.getAllInstalledApps",
AUTOTESTPRIVATE_GETALLINSTALLEDAPPS)

private:
~AutotestPrivateGetAllInstalledAppsFunction() override;
ResponseAction Run() override;
};

// Returns a list of all shelf items
class AutotestPrivateGetShelfItemsFunction : public ExtensionFunction {
public:
Expand Down
35 changes: 35 additions & 0 deletions chrome/common/extensions/api/autotest_private.idl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ namespace autotestPrivate {
Attention
};

// A mapping of apps::mojom::Type
enum AppType {
Arc,
BuiltIn,
Crostini,
Extension,
Web
};

// A mapping of apps::mojom::Readiness
enum AppReadiness {
Ready,
DisabledByBlacklist,
DisabledByPolicy,
DisabledByUser,
Terminated,
UninstalledByUser
};

// A subset of Window State types in ash::WindowStateType. We may add more
// into the set in the future.
enum WindowStateType {
Expand Down Expand Up @@ -231,6 +250,19 @@ namespace autotestPrivate {

callback SetTabletModeEnabledCallback = void(boolean enabled);

dictionary App {
DOMString appId;
DOMString name;
DOMString shortName;
AppType? type;
AppReadiness? readiness;
DOMString[] additionalSearchTerms;
boolean? showInLauncher;
boolean? showInSearch;
};

callback GetAllInstalledAppsCallback = void (App[] apps);

dictionary ShelfItem {
DOMString appId;
DOMString launchId;
Expand Down Expand Up @@ -445,6 +477,9 @@ namespace autotestPrivate {
static void setTabletModeEnabled(boolean enabled,
SetTabletModeEnabledCallback callback);

// Get the list of all installed applications
static void getAllInstalledApps(GetAllInstalledAppsCallback callback);

// Get the list of all shelf items
static void getShelfItems(GetShelfItemsCallback callback);

Expand Down
19 changes: 19 additions & 0 deletions chrome/test/data/extensions/api_test/autotest_private/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,25 @@ var defaultTests = [
chrome.test.succeed();
});
},
// This test verifies that autotetPrivate can correctly query installed apps.
function getAllInstalledApps() {
chrome.autotestPrivate.getAllInstalledApps(chrome.test.callbackPass(
apps => {
// Limit apps to chromium to filter out default apps.
const chromium = apps.find(
app => app.appId == 'mgndgikekgjfcpckkfioiadnlibdjbkf');
chrome.test.assertTrue(!!chromium);
// Only check that name and shortName are set for Chromium because
// their values change if chrome_branded is true.
chrome.test.assertTrue(!!chromium.name);
chrome.test.assertTrue(!!chromium.shortName);
chrome.test.assertEq(chromium.additionalSearchTerms, []);
chrome.test.assertEq(chromium.readiness, 'Ready');
chrome.test.assertEq(chromium.showInLauncher, true);
chrome.test.assertEq(chromium.showInSearch, true);
chrome.test.assertEq(chromium.type, 'Extension');
}));
},
// This test verifies that only Chromium is available by default.
function getShelfItems() {
chrome.autotestPrivate.getShelfItems(chrome.test.callbackPass(items => {
Expand Down
1 change: 1 addition & 0 deletions extensions/browser/extension_function_histogram_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1436,6 +1436,7 @@ enum HistogramValue {
LOGINSCREENSTORAGE_RETRIEVECREDENTIALS = 1373,
AUTOTESTPRIVATE_GETARCAPPWINDOWSTATE = 1374,
AUTOTESTPRIVATE_GETARCAPPWINDOWINFO = 1375,
AUTOTESTPRIVATE_GETALLINSTALLEDAPPS = 1376,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
Expand Down
9 changes: 5 additions & 4 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18744,7 +18744,7 @@ Called by update_net_error_codes.py.-->
<int value="343"
label="DELETED_TYPES_PRIVATE_CHROME_DIRECT_SETTING_ON_CHANGE"/>
<int value="344" label="WEB_VIEW_INTERNAL_ON_MESSAGE"/>
<int value="345" label="EXTENSION_VIEW_INTERNAL_ON_LOAD_COMMIT"/>
<int value="345" label="DELETED_EXTENSION_VIEW_INTERNAL_ON_LOAD_COMMIT"/>
<int value="346" label="RUNTIME_ON_REQUEST"/>
<int value="347" label="RUNTIME_ON_REQUEST_EXTERNAL"/>
<int value="348" label="CHROME_WEB_VIEW_INTERNAL_ON_CONTEXT_MENU_SHOW"/>
Expand Down Expand Up @@ -19848,7 +19848,7 @@ Called by update_net_error_codes.py.-->
<int value="951" label="FILESYSTEMPROVIDER_GET"/>
<int value="952" label="FILEMANAGERPRIVATE_SEARCHFILESBYHASHES"/>
<int value="953" label="DELETED_EASYUNLOCKPRIVATE_SHOWERRORBUBBLE"/>
<int value="954" label="EXTENSIONVIEWINTERNAL_NAVIGATE"/>
<int value="954" label="DELETED_EXTENSIONVIEWINTERNAL_NAVIGATE"/>
<int value="955" label="NETWORKING_CONFIG_SETNETWORKFILTER"/>
<int value="956" label="NETWORKING_CONFIG_FINISHAUTHENTICATION"/>
<int value="957" label="PLATFORMKEYSINTERNAL_SELECTCLIENTCERTIFICATES"/>
Expand Down Expand Up @@ -19953,8 +19953,8 @@ Called by update_net_error_codes.py.-->
<int value="1052" label="WEBCAMPRIVATE_CLOSEWEBCAM"/>
<int value="1053" label="SERIAL_SETBREAK"/>
<int value="1054" label="SERIAL_CLEARBREAK"/>
<int value="1055" label="EXTENSIONVIEWINTERNAL_LOADSRC"/>
<int value="1056" label="EXTENSIONVIEWINTERNAL_PARSESRC"/>
<int value="1055" label="DELETED_EXTENSIONVIEWINTERNAL_LOADSRC"/>
<int value="1056" label="DELETED_EXTENSIONVIEWINTERNAL_PARSESRC"/>
<int value="1057" label="HID_GETUSERSELECTEDDEVICES"/>
<int value="1058"
label="FILESYSTEMPROVIDERINTERNAL_GETACTIONSREQUESTEDSUCCESS"/>
Expand Down Expand Up @@ -20291,6 +20291,7 @@ Called by update_net_error_codes.py.-->
<int value="1373" label="LOGINSCREENSTORAGE_RETRIEVECREDENTIALS"/>
<int value="1374" label="AUTOTESTPRIVATE_GETARCAPPWINDOWSTATE"/>
<int value="1375" label="AUTOTESTPRIVATE_GETARCAPPWINDOWINFO"/>
<int value="1376" label="AUTOTESTPRIVATE_GETALLINSTALLEDAPPS"/>
</enum>

<enum name="ExtensionIconState">
Expand Down

0 comments on commit fa7c3b0

Please sign in to comment.