chromium/chrome/browser/extensions/extension_error_controller_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/extensions/extension_error_controller.h"

#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/values.h"
#include "chrome/browser/extensions/extension_error_ui.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_service_test_base.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/test/base/testing_profile.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "extensions/browser/blocklist_extension_prefs.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_builder.h"

namespace extensions {

namespace {

// Create a mock for the UI component of the error alert that is shown for
// blocklisted extensions. This allows us to test which extensions the alert
// is showing, and also eliminates the UI component (since this is a unit
// test).
class MockExtensionErrorUI : public ExtensionErrorUI {};

// We use this as a slight hack to get the created Error UI, if any. We should
// only ever have one (since this is a single-profile test), and this avoids
// the need for any kind of accessor to the ErrorController from
// ExtensionService.
MockExtensionErrorUI* g_error_ui =;

MockExtensionErrorUI::MockExtensionErrorUI(ExtensionErrorUI::Delegate* delegate)
    :{}

MockExtensionErrorUI::~MockExtensionErrorUI() {}

void MockExtensionErrorUI::CloseUI() {}

void MockExtensionErrorUI::Accept() {}

void MockExtensionErrorUI::Details() {}

bool MockExtensionErrorUI::ShowErrorInBubbleView() {}

void MockExtensionErrorUI::ShowExtensions() {}

void MockExtensionErrorUI::Close() {}

ExtensionErrorUI* CreateMockUI(ExtensionErrorUI::Delegate* delegate) {}

// Builds and returns a simple extension.
scoped_refptr<const Extension> BuildExtension() {}

}  // namespace

class ExtensionErrorControllerUnitTest : public ExtensionServiceTestBase {};

void ExtensionErrorControllerUnitTest::SetUp() {}

testing::AssertionResult
ExtensionErrorControllerUnitTest::AddBlocklistedExtension(
    const Extension* extension) {}

void ExtensionErrorControllerUnitTest::SetBlockExtensionPolicy(
    const Extension* extension) {}

ExtensionPrefs* ExtensionErrorControllerUnitTest::GetPrefs() {}

// Test that closing the extension alert for blocklisted extensions counts
// as acknowledging them in the prefs.
TEST_F(ExtensionErrorControllerUnitTest, ClosingAcknowledgesBlocklisted) {}

// Test that clicking "accept" on the extension alert counts as acknowledging
// blocklisted extensions.
TEST_F(ExtensionErrorControllerUnitTest, AcceptingAcknowledgesBlocklisted) {}

// Test that we don't warn for extensions which are blocklisted, but have
// already been acknowledged.
TEST_F(ExtensionErrorControllerUnitTest, DontWarnForAcknowledgedBlocklisted) {}

// Test there is no error ui if no extension is blocked by policy.
TEST_F(ExtensionErrorControllerUnitTest,
       ExtensionIsNotBlockedByEnterprisePolicy) {}

// Test error ui is presented and acknowledged whe an extension is blocked by
// policy.
TEST_F(ExtensionErrorControllerUnitTest, ExtensionIsBlockedByEnterprisePolicy) {}

// Test the case that the error UI is accepted when we no longer need to show
// error for a blocked extension. It includes the case that the policy is
// updated or the extension is moved to the disabled list.
TEST_F(ExtensionErrorControllerUnitTest, ExtensionIsUnblockedBeforeUIAccepted) {}

}  // namespace extensions