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

Unified Diff: chrome/browser/extensions/error_console/error_console_unittest.cc

Issue 22938005: Add ErrorConsole UI for Extension Install Warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dc_ec_install_warnings
Patch Set: Dan's Created 7 years, 4 months 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/error_console/error_console_unittest.cc
diff --git a/chrome/browser/extensions/error_console/error_console_unittest.cc b/chrome/browser/extensions/error_console/error_console_unittest.cc
index 62b5320d1808498893a09b301a3544f1a15f9c83..1608494f2f35e1def0a9a3f362d944a09ec0247a 100644
--- a/chrome/browser/extensions/error_console/error_console_unittest.cc
+++ b/chrome/browser/extensions/error_console/error_console_unittest.cc
@@ -7,13 +7,17 @@
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
+#include "base/prefs/pref_service.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/common/url_constants.h"
#include "extensions/browser/extension_error.h"
#include "extensions/common/constants.h"
+#include "extensions/common/id_util.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::string16;
@@ -43,7 +47,7 @@ scoped_ptr<const ExtensionError> CreateNewRuntimeError(
bool from_incognito,
const std::string& extension_id,
const string16& message) {
- return scoped_ptr<const ExtensionError>(new JavascriptRuntimeError(
+ return scoped_ptr<const ExtensionError>(new RuntimeError(
from_incognito,
UTF8ToUTF16("source"),
message,
@@ -61,6 +65,12 @@ class ErrorConsoleUnitTest : public testing::Test {
}
virtual ~ErrorConsoleUnitTest() { }
+ virtual void SetUp() OVERRIDE {
+ testing::Test::SetUp();
+ // Errors are only kept if we have Developer Mode enabled.
+ profile_->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true);
+ }
+
protected:
scoped_ptr<TestingProfile> profile_;
ErrorConsole* error_console_;
@@ -73,11 +83,11 @@ TEST_F(ErrorConsoleUnitTest, AddAndRemoveErrors) {
const size_t kNumTotalErrors = 6;
const size_t kNumNonIncognitoErrors = 3;
- const char kId[] = "id";
+ const std::string kId = id_util::GenerateId("id");
// Populate with both incognito and non-incognito errors (evenly distributed).
for (size_t i = 0; i < kNumTotalErrors; ++i) {
error_console_->ReportError(
- CreateNewRuntimeError(i % 2 == 0, kId, string16()));
+ CreateNewRuntimeError(i % 2 == 0, kId, base::UintToString16(i)));
}
// There should only be one entry in the map, since errors are stored in lists
@@ -96,7 +106,7 @@ TEST_F(ErrorConsoleUnitTest, AddAndRemoveErrors) {
ASSERT_FALSE(errors[i]->from_incognito());
// Add another error for a different extension id.
- const char kSecondId[] = "id2";
+ const std::string kSecondId = id_util::GenerateId("id2");
error_console_->ReportError(
CreateNewRuntimeError(false, kSecondId, string16()));
@@ -127,7 +137,7 @@ TEST_F(ErrorConsoleUnitTest, ExcessiveErrorsGetCropped) {
// This constant matches one of the same name in error_console.cc.
const size_t kMaxErrorsPerExtension = 100;
const size_t kNumExtraErrors = 5;
- const char kId[] = "id";
+ const std::string kId = id_util::GenerateId("id");
// Add new errors, with each error's message set to its number.
for (size_t i = 0; i < kMaxErrorsPerExtension + kNumExtraErrors; ++i) {
@@ -143,11 +153,43 @@ TEST_F(ErrorConsoleUnitTest, ExcessiveErrorsGetCropped) {
// We should have popped off errors in the order they arrived, so the
// first stored error should be the 6th reported (zero-based)...
- ASSERT_EQ(errors.front()->message(),
- base::UintToString16(kNumExtraErrors));
+ ASSERT_EQ(base::UintToString16(kNumExtraErrors),
+ errors.front()->message());
// ..and the last stored should be the 105th reported.
- ASSERT_EQ(errors.back()->message(),
- base::UintToString16(kMaxErrorsPerExtension + kNumExtraErrors - 1));
+ ASSERT_EQ(base::UintToString16(kMaxErrorsPerExtension + kNumExtraErrors - 1),
+ errors.back()->message());
+}
+
+// Test to ensure that the error console will not add duplicate errors, but will
+// keep the latest version of an error.
+TEST_F(ErrorConsoleUnitTest, DuplicateErrorsAreReplaced) {
+ ASSERT_EQ(0u, error_console_->errors().size());
+
+ const std::string kId = id_util::GenerateId("id");
+
+ // Report a simple error.
+ error_console_->ReportError(
+ CreateNewRuntimeError(false, kId, EmptyString16()));
+
+ // Create a second, identical error, and save its location.
+ scoped_ptr<const ExtensionError> runtime_error2 =
+ CreateNewRuntimeError(false, kId, EmptyString16());
+ const ExtensionError* weak_error = runtime_error2.get();
+
+ // Add it to the error console.
+ error_console_->ReportError(runtime_error2.Pass());
+
+ // We should only have one error stored, since the two were identical and the
+ // older should have been replaced.
+ ASSERT_EQ(1u, error_console_->errors().size());
+ const ErrorConsole::ErrorList& errors =
+ error_console_->GetErrorsForExtension(kId);
+ ASSERT_EQ(1u, errors.size());
+
+ // Additionally, the only stored error should be the *second* error added,
+ // not the first.
+ // Pointer comparison.
+ ASSERT_EQ(weak_error, errors[0]);
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698