| Index: chrome/browser/extensions/extension_management_policy_unittest.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_management_policy_unittest.cc (revision 0)
|
| +++ chrome/browser/extensions/extension_management_policy_unittest.cc (revision 0)
|
| @@ -0,0 +1,181 @@
|
| +// Copyright (c) 2012 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/utf_string_conversions.h"
|
| +#include "chrome/browser/extensions/extension_management_policy.h"
|
| +#include "chrome/browser/extensions/test_extension_management_policy.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +typedef TestExtensionManagementPolicyDelegate TestDelegate;
|
| +
|
| +class ExtensionManagementPolicyTest : public testing::Test {
|
| + public:
|
| + void SetUp() {
|
| + allow_all_.SetAllowedActions(TestDelegate::ALLOW_ALL);
|
| + no_modify_status_.SetAllowedActions(TestDelegate::PROHIBIT_MODIFY_STATUS);
|
| + no_modify_usage_.SetAllowedActions(TestDelegate::PROHIBIT_MODIFY_USAGE);
|
| + no_install_.SetAllowedActions(TestDelegate::PROHIBIT_INSTALL);
|
| + must_remain_enabled_.SetAllowedActions(TestDelegate::MUST_REMAIN_ENABLED);
|
| + }
|
| +
|
| + protected:
|
| + ExtensionManagementPolicy policy_;
|
| +
|
| + TestDelegate allow_all_;
|
| + TestDelegate no_modify_status_;
|
| + TestDelegate no_modify_usage_;
|
| + TestDelegate no_install_;
|
| + TestDelegate must_remain_enabled_;
|
| +};
|
| +
|
| +TEST_F(ExtensionManagementPolicyTest, RegisterAndUnregister) {
|
| + EXPECT_EQ(0u, policy_.CountDelegates());
|
| + policy_.RegisterDelegate(&allow_all_);
|
| + EXPECT_EQ(1u, policy_.CountDelegates());
|
| + policy_.RegisterDelegate(&allow_all_);
|
| + EXPECT_EQ(1u, policy_.CountDelegates());
|
| +
|
| + policy_.RegisterDelegate(&no_modify_status_);
|
| + EXPECT_EQ(2u, policy_.CountDelegates());
|
| + policy_.UnregisterDelegate(&allow_all_);
|
| + EXPECT_EQ(1u, policy_.CountDelegates());
|
| + policy_.UnregisterDelegate(&allow_all_);
|
| + EXPECT_EQ(1u, policy_.CountDelegates());
|
| + policy_.UnregisterDelegate(&no_modify_status_);
|
| + EXPECT_EQ(0u, policy_.CountDelegates());
|
| +
|
| + policy_.RegisterDelegate(&allow_all_);
|
| + policy_.RegisterDelegate(&no_modify_status_);
|
| + EXPECT_EQ(2u, policy_.CountDelegates());
|
| + policy_.UnregisterAllDelegates();
|
| + EXPECT_EQ(0u, policy_.CountDelegates());
|
| +}
|
| +
|
| +TEST_F(ExtensionManagementPolicyTest, UserMayInstall) {
|
| + // No delegates registered.
|
| + string16 error;
|
| + EXPECT_TRUE(policy_.UserMayInstall("", Extension::INVALID, "", &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // One delegate, no relevant restriction.
|
| + policy_.RegisterDelegate(&no_modify_status_);
|
| + EXPECT_TRUE(policy_.UserMayInstall("", Extension::INVALID, "", &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Two delegates, no relevant restrictions.
|
| + policy_.RegisterDelegate(&no_modify_usage_);
|
| + EXPECT_TRUE(policy_.UserMayInstall("", Extension::INVALID, "", &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Three delegates, one with a relevant restriction.
|
| + policy_.RegisterDelegate(&no_install_);
|
| + EXPECT_FALSE(policy_.UserMayInstall("", Extension::INVALID, "", &error));
|
| + EXPECT_FALSE(error.empty());
|
| +
|
| + // Remove the restriction.
|
| + policy_.UnregisterDelegate(&no_install_);
|
| + error.clear();
|
| + EXPECT_TRUE(policy_.UserMayInstall("", Extension::INVALID, "", &error));
|
| + EXPECT_TRUE(error.empty());
|
| +}
|
| +TEST_F(ExtensionManagementPolicyTest, UserMayModifyStatus) {
|
| + // No delegates registered.
|
| + string16 error;
|
| + EXPECT_TRUE(policy_.UserMayModifyStatus(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // One delegate, no relevant restriction.
|
| + policy_.RegisterDelegate(&allow_all_);
|
| + EXPECT_TRUE(policy_.UserMayModifyStatus(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Two delegates, no relevant restrictions.
|
| + policy_.RegisterDelegate(&no_modify_usage_);
|
| + EXPECT_TRUE(policy_.UserMayModifyStatus(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Three delegates, one with a relevant restriction.
|
| + policy_.RegisterDelegate(&no_modify_status_);
|
| + EXPECT_FALSE(policy_.UserMayModifyStatus(NULL, &error));
|
| + EXPECT_FALSE(error.empty());
|
| +
|
| + // Remove the restriction.
|
| + policy_.UnregisterDelegate(&no_modify_status_);
|
| + error.clear();
|
| + EXPECT_TRUE(policy_.UserMayModifyStatus(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +}
|
| +
|
| +TEST_F(ExtensionManagementPolicyTest, UserMayModifyUsage) {
|
| + // No delegates registered.
|
| + string16 error;
|
| + EXPECT_TRUE(policy_.UserMayModifyUsage(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // One delegate, no relevant restriction.
|
| + policy_.RegisterDelegate(&allow_all_);
|
| + EXPECT_TRUE(policy_.UserMayModifyUsage(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Two delegates, no relevant restrictions.
|
| + policy_.RegisterDelegate(&no_modify_status_);
|
| + EXPECT_TRUE(policy_.UserMayModifyUsage(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Three delegates, one with a relevant restriction.
|
| + policy_.RegisterDelegate(&no_modify_usage_);
|
| + EXPECT_FALSE(policy_.UserMayModifyUsage(NULL, &error));
|
| + EXPECT_FALSE(error.empty());
|
| +
|
| + // Remove the restriction.
|
| + policy_.UnregisterDelegate(&no_modify_usage_);
|
| + error.clear();
|
| + EXPECT_TRUE(policy_.UserMayModifyUsage(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +}
|
| +
|
| +TEST_F(ExtensionManagementPolicyTest, MustRemainEnabled) {
|
| + // No delegates registered.
|
| + string16 error;
|
| + EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // One delegate, no relevant restriction.
|
| + policy_.RegisterDelegate(&allow_all_);
|
| + EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Two delegates, no relevant restrictions.
|
| + policy_.RegisterDelegate(&no_modify_status_);
|
| + EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +
|
| + // Three delegates, one with a relevant restriction.
|
| + policy_.RegisterDelegate(&must_remain_enabled_);
|
| + EXPECT_TRUE(policy_.MustRemainEnabled(NULL, &error));
|
| + EXPECT_FALSE(error.empty());
|
| +
|
| + // Remove the restriction.
|
| + policy_.UnregisterDelegate(&must_remain_enabled_);
|
| + error.clear();
|
| + EXPECT_FALSE(policy_.MustRemainEnabled(NULL, &error));
|
| + EXPECT_TRUE(error.empty());
|
| +}
|
| +
|
| +TEST_F(ExtensionManagementPolicyTest, ErrorHandling) {
|
| + // The error parameter should be unchanged if no restriction was found.
|
| + std::string original_error = "Ceci est en effet une erreur.";
|
| + string16 error = UTF8ToUTF16(original_error);
|
| + EXPECT_TRUE(policy_.UserMayModifyStatus(NULL, &error));
|
| + EXPECT_EQ(original_error, UTF16ToUTF8(error));
|
| +
|
| + // Ensure no crashes if no error message was requested.
|
| + EXPECT_TRUE(policy_.UserMayModifyStatus(NULL, NULL));
|
| + policy_.RegisterDelegate(&no_modify_status_);
|
| + EXPECT_FALSE(policy_.UserMayModifyStatus(NULL, NULL));
|
| +
|
| + // Make sure returned error is correct.
|
| + EXPECT_FALSE(policy_.UserMayModifyStatus(NULL, &error));
|
| + EXPECT_EQ(UTF8ToUTF16(TestDelegate::expected_error()), error);
|
| +}
|
|
|
| Property changes on: chrome\browser\extensions\extension_management_policy_unittest.cc
|
| ___________________________________________________________________
|
| Added: svn:executable
|
| + *
|
| Added: svn:eol-style
|
| + LF
|
|
|
|
|