This source file includes following definitions.
- AddWarning
- TEST
- TEST
#include "chrome/browser/extensions/extension_warning_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/test/base/testing_profile.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace {
class TestExtensionWarningService : public ExtensionWarningService {
public:
explicit TestExtensionWarningService(Profile* profile)
: ExtensionWarningService(profile) {
}
virtual ~TestExtensionWarningService() {}
void AddWarning(const ExtensionWarning& warning) {
ExtensionWarningSet warnings;
warnings.insert(warning);
AddWarnings(warnings);
}
};
class MockObserver : public ExtensionWarningService::Observer {
public:
virtual ~MockObserver() {}
MOCK_METHOD0(ExtensionWarningsChanged, void());
};
const char* ext1_id = "extension1";
const char* ext2_id = "extension2";
const ExtensionWarning::WarningType warning_1 =
ExtensionWarning::kNetworkDelay;
const ExtensionWarning::WarningType warning_2 =
ExtensionWarning::kNetworkConflict;
}
TEST(ExtensionWarningServiceTest, SetWarning) {
TestingProfile profile;
TestExtensionWarningService warning_service(&profile);
MockObserver observer;
warning_service.AddObserver(&observer);
EXPECT_CALL(observer, ExtensionWarningsChanged());
warning_service.AddWarning(
ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
testing::Mock::VerifyAndClearExpectations(&warning_service);
warning_service.AddWarning(
ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
testing::Mock::VerifyAndClearExpectations(&warning_service);
warning_service.RemoveObserver(&observer);
}
TEST(ExtensionWarningServiceTest, ClearWarnings) {
TestingProfile profile;
TestExtensionWarningService warning_service(&profile);
MockObserver observer;
warning_service.AddObserver(&observer);
EXPECT_CALL(observer, ExtensionWarningsChanged());
ExtensionWarningSet warning_set;
warning_set.insert(ExtensionWarning::CreateNetworkDelayWarning(ext1_id));
warning_set.insert(ExtensionWarning::CreateNetworkConflictWarning(ext2_id));
warning_service.AddWarnings(warning_set);
testing::Mock::VerifyAndClearExpectations(&warning_service);
EXPECT_CALL(observer, ExtensionWarningsChanged());
std::set<ExtensionWarning::WarningType> to_clear;
to_clear.insert(warning_2);
warning_service.ClearWarnings(to_clear);
testing::Mock::VerifyAndClearExpectations(&warning_service);
std::set<ExtensionWarning::WarningType> existing_warnings =
warning_service.GetWarningTypesAffectingExtension(ext1_id);
EXPECT_EQ(1u, existing_warnings.size());
existing_warnings =
warning_service.GetWarningTypesAffectingExtension(ext2_id);
EXPECT_EQ(0u, existing_warnings.size());
EXPECT_CALL(observer, ExtensionWarningsChanged());
to_clear.insert(warning_1);
warning_service.ClearWarnings(to_clear);
testing::Mock::VerifyAndClearExpectations(&warning_service);
existing_warnings =
warning_service.GetWarningTypesAffectingExtension(ext1_id);
EXPECT_EQ(0u, existing_warnings.size());
existing_warnings =
warning_service.GetWarningTypesAffectingExtension(ext2_id);
EXPECT_EQ(0u, existing_warnings.size());
warning_service.RemoveObserver(&observer);
}
}