This source file includes following definitions.
- SetUp
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/extensions/error_console/error_console.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_service.h"
#include "base/strings/string_number_conversions.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "extensions/browser/extension_error.h"
#include "extensions/browser/extension_error_test_util.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/feature_switch.h"
#include "extensions/common/id_util.h"
#include "extensions/common/value_builder.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
using error_test_util::CreateNewManifestError;
using error_test_util::CreateNewRuntimeError;
class ErrorConsoleUnitTest : public testing::Test {
public:
ErrorConsoleUnitTest() : error_console_(NULL) { }
virtual ~ErrorConsoleUnitTest() { }
virtual void SetUp() OVERRIDE {
testing::Test::SetUp();
FeatureSwitch::error_console()->SetOverrideValue(
FeatureSwitch::OVERRIDE_ENABLED);
profile_.reset(new TestingProfile);
profile_->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true);
error_console_ = ErrorConsole::Get(profile_.get());
}
protected:
scoped_ptr<TestingProfile> profile_;
ErrorConsole* error_console_;
};
TEST_F(ErrorConsoleUnitTest, EnableAndDisableErrorConsole) {
scoped_ptr<ScopedCurrentChannel> channel_override(
new ScopedCurrentChannel(chrome::VersionInfo::CHANNEL_DEV));
ASSERT_EQ(chrome::VersionInfo::CHANNEL_DEV, GetCurrentChannel());
FeatureSwitch::error_console()->SetOverrideValue(
FeatureSwitch::OVERRIDE_DISABLED);
EXPECT_TRUE(error_console_->enabled());
EXPECT_TRUE(error_console_->IsEnabledForChromeExtensionsPage());
EXPECT_FALSE(error_console_->IsEnabledForAppsDeveloperTools());
profile_->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, false);
EXPECT_FALSE(error_console_->enabled());
EXPECT_FALSE(error_console_->IsEnabledForChromeExtensionsPage());
EXPECT_FALSE(error_console_->IsEnabledForAppsDeveloperTools());
channel_override.reset();
channel_override.reset(
new ScopedCurrentChannel(chrome::VersionInfo::CHANNEL_BETA));
profile_->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true);
EXPECT_FALSE(error_console_->enabled());
EXPECT_FALSE(error_console_->IsEnabledForChromeExtensionsPage());
EXPECT_FALSE(error_console_->IsEnabledForAppsDeveloperTools());
FeatureSwitch::error_console()->SetOverrideValue(
FeatureSwitch::OVERRIDE_ENABLED);
ASSERT_TRUE(FeatureSwitch::error_console()->IsEnabled());
profile_->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, false);
profile_->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true);
EXPECT_TRUE(error_console_->enabled());
EXPECT_TRUE(error_console_->IsEnabledForChromeExtensionsPage());
EXPECT_FALSE(error_console_->IsEnabledForAppsDeveloperTools());
FeatureSwitch::error_console()->SetOverrideValue(
FeatureSwitch::OVERRIDE_DISABLED);
const char kAppsDeveloperToolsExtensionId[] =
"ohmmkhmmmpcnpikjeljgnaoabkaalbgc";
scoped_refptr<Extension> adt =
ExtensionBuilder()
.SetManifest(
DictionaryBuilder().Set("name", "apps dev tools")
.Set("version", "0.2.0")
.Set("manifest_version", 2)
.Build())
.SetID(kAppsDeveloperToolsExtensionId)
.Build();
ExtensionRegistry* registry = ExtensionRegistry::Get(profile_.get());
registry->AddEnabled(adt);
registry->TriggerOnLoaded(adt);
EXPECT_TRUE(error_console_->enabled());
EXPECT_FALSE(error_console_->IsEnabledForChromeExtensionsPage());
EXPECT_TRUE(error_console_->IsEnabledForAppsDeveloperTools());
registry->RemoveEnabled(adt->id());
registry->TriggerOnUnloaded(adt);
EXPECT_FALSE(error_console_->enabled());
EXPECT_FALSE(error_console_->IsEnabledForChromeExtensionsPage());
EXPECT_FALSE(error_console_->IsEnabledForAppsDeveloperTools());
}
TEST_F(ErrorConsoleUnitTest, ReportErrors) {
const size_t kNumTotalErrors = 6;
const std::string kId = id_util::GenerateId("id");
ASSERT_EQ(0u, error_console_->GetErrorsForExtension(kId).size());
for (size_t i = 0; i < kNumTotalErrors; ++i) {
error_console_->ReportError(
CreateNewManifestError(kId, base::UintToString(i)));
}
ASSERT_EQ(kNumTotalErrors, error_console_->GetErrorsForExtension(kId).size());
}
TEST_F(ErrorConsoleUnitTest, DontStoreErrorsWithoutEnablingType) {
error_console_->set_default_reporting_for_test(ExtensionError::RUNTIME_ERROR,
false);
const std::string kId = id_util::GenerateId("id");
error_console_->ReportError(CreateNewRuntimeError(kId, "a"));
ASSERT_EQ(0u, error_console_->GetErrorsForExtension(kId).size());
error_console_->ReportError(CreateNewManifestError(kId, "b"));
ASSERT_EQ(1u, error_console_->GetErrorsForExtension(kId).size());
error_console_->ReportError(CreateNewRuntimeError(kId, "c"));
ASSERT_EQ(1u, error_console_->GetErrorsForExtension(kId).size());
error_console_->SetReportingForExtension(
kId, ExtensionError::RUNTIME_ERROR, true);
error_console_->ReportError(CreateNewManifestError(kId, "d"));
ASSERT_EQ(2u, error_console_->GetErrorsForExtension(kId).size());
error_console_->ReportError(CreateNewRuntimeError(kId, "e"));
ASSERT_EQ(3u, error_console_->GetErrorsForExtension(kId).size());
const std::string kId2 = id_util::GenerateId("id2");
error_console_->ReportError(CreateNewRuntimeError(kId2, "f"));
ASSERT_EQ(0u, error_console_->GetErrorsForExtension(kId2).size());
error_console_->ReportError(CreateNewManifestError(kId2, "g"));
ASSERT_EQ(1u, error_console_->GetErrorsForExtension(kId2).size());
error_console_->UseDefaultReportingForExtension(kId);
error_console_->ReportError(CreateNewManifestError(kId, "h"));
ASSERT_EQ(4u, error_console_->GetErrorsForExtension(kId).size());
error_console_->ReportError(CreateNewRuntimeError(kId, "i"));
ASSERT_EQ(4u, error_console_->GetErrorsForExtension(kId).size());
}
}