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

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: Requested UI Changes 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..87b2db6b45d777d33a48486bb6e77bec159306a6 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,48 @@ 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");
+ const size_t kNumErrors = 3u;
+
+ // Report three errors.
+ for (size_t i = 0; i < kNumErrors; ++i) {
+ error_console_->ReportError(
+ CreateNewRuntimeError(false, kId, base::UintToString16(i)));
+ }
+
+ // Create an error identical to the second error reported, and save its
+ // location.
+ const size_t kDuplicateError = 1u;
+ scoped_ptr<const ExtensionError> runtime_error2 =
+ CreateNewRuntimeError(false, kId, base::UintToString16(kDuplicateError));
+ const ExtensionError* weak_error = runtime_error2.get();
+
+ // Add it to the error console.
+ error_console_->ReportError(runtime_error2.Pass());
+
+ // We should only have three errors stored, since two of the four reported
+ // 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(kNumErrors, errors.size());
+
+ // The more-recently reported error should be in the slot of the error it
+ // replaced.
+ // Pointer comparison.
+ ASSERT_EQ(weak_error, errors[kDuplicateError]);
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698