Skip to content

Commit

Permalink
Support for autotestPrivate.refreshEnterprisePolicies
Browse files Browse the repository at this point in the history
Adding an API that will refresh (refetch) Enterprise Policies when called.
This will remove the need for automated testing to go to the
chrome://policy page, and "click" the refresh button via a js call.

Bug=chromium:1012712
Test=Locally deployed and tested and basic unittest.

Change-Id: Iedc3c2e349cceb7f8b076259877d548b9f4babda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1683103
Commit-Queue: Derek Beckett <dbeckett@chromium.org>
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Reviewed-by: Pavol Marko <pmarko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707382}
  • Loading branch information
Derek Beckett authored and Commit Bot committed Oct 18, 2019
1 parent bf60349 commit 382a1ef
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/statistics_recorder.h"
#include "base/run_loop.h"
#include "base/scoped_observer.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
Expand Down Expand Up @@ -88,6 +89,7 @@
#include "chromeos/services/machine_learning/public/cpp/service_connection.h"
#include "components/arc/arc_prefs.h"
#include "components/arc/metrics/arc_metrics_constants.h"
#include "components/policy/core/common/policy_service.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/histogram_fetcher.h"
#include "extensions/browser/event_router.h"
Expand Down Expand Up @@ -667,6 +669,26 @@ AutotestPrivateGetAllEnterprisePoliciesFunction::Run() {
base::Value::ToUniquePtrValue(std::move(all_policies_array))));
}

///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateRefreshEnterprisePoliciesFunction
///////////////////////////////////////////////////////////////////////////////

AutotestPrivateRefreshEnterprisePoliciesFunction::
~AutotestPrivateRefreshEnterprisePoliciesFunction() = default;

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

g_browser_process->policy_service()->RefreshPolicies(base::Bind(
&AutotestPrivateRefreshEnterprisePoliciesFunction::RefreshDone, this));
return RespondLater();
}

void AutotestPrivateRefreshEnterprisePoliciesFunction::RefreshDone() {
Respond(NoArguments());
}

///////////////////////////////////////////////////////////////////////////////
// AutotestPrivateGetExtensionsInfoFunction
///////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,20 @@ class AutotestPrivateGetAllEnterprisePoliciesFunction
ResponseAction Run() override;
};

class AutotestPrivateRefreshEnterprisePoliciesFunction
: public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("autotestPrivate.refreshEnterprisePolicies",
AUTOTESTPRIVATE_REFRESHENTERPRISEPOLICIES)

private:
~AutotestPrivateRefreshEnterprisePoliciesFunction() override;
ResponseAction Run() override;

// Called once all the policies have been refreshed.
void RefreshDone();
};

class AutotestPrivateBootstrapMachineLearningServiceFunction
: public ExtensionFunction {
public:
Expand Down
3 changes: 3 additions & 0 deletions chrome/common/extensions/api/autotest_private.idl
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,9 @@ namespace autotestPrivate {
static void getAllEnterprisePolicies(
AllEnterprisePoliciesCallback callback);

// Refreshes the Enterprise Policies.
static void refreshEnterprisePolicies(VoidCallback callback);

// Simulates a memory access bug for asan testing.
static void simulateAsanMemoryBug();

Expand Down
8 changes: 8 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 @@ -666,6 +666,14 @@ var policyTests = [
chrome.test.succeed();
}));
},
function refreshEnterprisePolicies() {
chrome.autotestPrivate.refreshEnterprisePolicies(
chrome.test.callbackPass(function() {
chrome.test.succeed();
})
);
},

];

var arcPerformanceTracingTests = [
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 @@ -1457,6 +1457,7 @@ enum HistogramValue {
AUTOTESTPRIVATE_GETAPPWINDOWLIST = 1394,
AUTOTESTPRIVATE_SETAPPWINDOWSTATE = 1395,
AUTOTESTPRIVATE_CLOSEAPPWINDOW = 1396,
AUTOTESTPRIVATE_REFRESHENTERPRISEPOLICIES = 1397,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
Expand Down
1 change: 1 addition & 0 deletions tools/metrics/histograms/enums.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20970,6 +20970,7 @@ Called by update_net_error_codes.py.-->
<int value="1394" label="AUTOTESTPRIVATE_GETAPPWINDOWLIST"/>
<int value="1395" label="AUTOTESTPRIVATE_SETAPPWINDOWSTATE"/>
<int value="1396" label="AUTOTESTPRIVATE_CLOSEAPPWINDOW"/>
<int value="1397" label="AUTOTESTPRIVATE_REFRESHENTERPRISEPOLICIES"/>
</enum>

<enum name="ExtensionIconState">
Expand Down

0 comments on commit 382a1ef

Please sign in to comment.