Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Unified Diff: chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc

Issue 2529083002: Make extensions developer mode adhere to policy (Closed)
Patch Set: Reviewers' comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc b/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
index 5961e214069fe66d844bb892aca1895c613b8d08..22f4fe8c662960aae228efbe2680a2b651a24e2d 100644
--- a/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
+++ b/chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc
@@ -25,6 +25,13 @@
#include "chrome/common/pref_names.h"
#include "chrome/test/base/test_browser_window.h"
#include "components/crx_file/id_util.h"
+#include "components/policy/core/browser/browser_policy_connector.h"
+#include "components/policy/core/common/mock_configuration_policy_provider.h"
+#include "components/policy/core/common/policy_map.h"
+#include "components/policy/core/common/policy_service_impl.h"
+#include "components/policy/core/common/policy_types.h"
+#include "components/policy/policy_constants.h"
+#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/web_contents_tester.h"
#include "extensions/browser/event_router_factory.h"
#include "extensions/browser/extension_error_test_util.h"
@@ -40,6 +47,9 @@
#include "extensions/common/test_util.h"
#include "extensions/common/value_builder.h"
+using testing::Return;
+using testing::_;
+
namespace extensions {
namespace {
@@ -95,6 +105,16 @@ class DeveloperPrivateApiUnitTest : public ExtensionServiceTestBase {
api::developer_private::PackStatus expected_status,
int expected_flags);
+ // Execute the updateProfileConfiguration API call with a specified
+ // dev_mode. This is done from the webui when the user checks the
+ // "Developer Mode" checkbox.
+ void UpdateProfileConfigurationDevMode(bool dev_mode);
+
+ // Execute the getProfileConfiguration API and parse its result into a
+ // ProfileInfo structure for further verification in the calling test.
+ std::unique_ptr<api::developer_private::ProfileInfo>
+ GetProfileConfiguration();
+
Browser* browser() { return browser_.get(); }
private:
@@ -107,6 +127,7 @@ class DeveloperPrivateApiUnitTest : public ExtensionServiceTestBase {
std::unique_ptr<Browser> browser_;
std::vector<std::unique_ptr<TestExtensionDir>> test_extension_dirs_;
+ policy::MockConfigurationPolicyProvider mock_policy_provider_;
DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateApiUnitTest);
};
@@ -242,9 +263,44 @@ testing::AssertionResult DeveloperPrivateApiUnitTest::TestPackExtensionFunction(
return testing::AssertionSuccess();
}
+void DeveloperPrivateApiUnitTest::UpdateProfileConfigurationDevMode(
+ bool dev_mode) {
+ scoped_refptr<UIThreadExtensionFunction> function(
+ new api::DeveloperPrivateUpdateProfileConfigurationFunction());
+ std::unique_ptr<base::ListValue> args =
+ ListBuilder()
+ .Append(DictionaryBuilder()
+ .SetBoolean("inDeveloperMode", dev_mode)
+ .Build())
+ .Build();
+ EXPECT_TRUE(RunFunction(function, *args)) << function->GetError();
+}
+
+std::unique_ptr<api::developer_private::ProfileInfo>
+ DeveloperPrivateApiUnitTest::GetProfileConfiguration() {
+ scoped_refptr<UIThreadExtensionFunction> function(
+ new api::DeveloperPrivateGetProfileConfigurationFunction());
+ base::ListValue args;
+ EXPECT_TRUE(RunFunction(function, args)) << function->GetError();
+
+ EXPECT_TRUE(function->GetResultList());
Andrew T Wilson (Slow) 2016/12/04 14:54:54 ASSERT_TRUE() because your test will crash on the
pmarko 2016/12/07 16:12:11 Good point - had have to change the method type to
+ EXPECT_EQ(1u, function->GetResultList()->GetSize());
Andrew T Wilson (Slow) 2016/12/04 14:54:54 I'd probably also ASSERT_EQ or ASSERT_GE here beca
Andrew T Wilson (Slow) 2016/12/04 14:54:54 I'd probably also ASSERT_EQ or ASSERT_GE here beca
pmarko 2016/12/07 16:12:11 Done - taking ASSERT_EQ because the API is suppose
+ const base::Value* response_value = nullptr;
+ function->GetResultList()->Get(0u, &response_value);
+ std::unique_ptr<api::developer_private::ProfileInfo> response =
+ api::developer_private::ProfileInfo::FromValue(*response_value);
+ return response;
+}
+
void DeveloperPrivateApiUnitTest::SetUp() {
ExtensionServiceTestBase::SetUp();
- InitializeEmptyExtensionService();
+
+ // By not specifying a pref_file filepath, we get a
+ // sync_preferences::TestingPrefServiceSyncable
+ // - see BuildTestingProfile in extension_service_test_base.cc.
+ ExtensionServiceInitParams init_params = CreateDefaultInitParams();
+ init_params.pref_file.clear();
+ InitializeExtensionService(init_params);
browser_window_.reset(new TestBrowserWindow());
Browser::CreateParams params(profile());
@@ -576,4 +632,39 @@ TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateDeleteExtensionErrors) {
EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty());
}
+// Test developerPrivate.updateProfileConfiguration
+// trying to turn on devMode when DeveloperToolsDisabled policy is active
+TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateDevModeDisabledPolicy) {
+ testing_pref_service()->SetManagedPref(
+ prefs::kExtensionsUIDeveloperMode,
+ new base::FundamentalValue(false));
+
+ UpdateProfileConfigurationDevMode(true);
+
+ EXPECT_FALSE(
+ profile()->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode));
+
+ std::unique_ptr<api::developer_private::ProfileInfo> profile_info =
+ GetProfileConfiguration();
+ EXPECT_FALSE(profile_info->in_developer_mode);
+ EXPECT_TRUE(profile_info->is_developer_mode_controlled_by_policy);
+}
+
+// Test developerPrivate.updateProfileConfiguration
+// trying to turn on devMode
+TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateDevMode) {
+ EXPECT_FALSE(
+ profile()->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode));
+
+ UpdateProfileConfigurationDevMode(true);
+
+ EXPECT_TRUE(
+ profile()->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode));
+
+ std::unique_ptr<api::developer_private::ProfileInfo> profile_info =
+ GetProfileConfiguration();
+ EXPECT_TRUE(profile_info->in_developer_mode);
+ EXPECT_FALSE(profile_info->is_developer_mode_controlled_by_policy);
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698