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

Unified Diff: extensions/renderer/api_last_error_unittest.cc

Issue 2819683002: [Extenisons Bindings] Don't throw unchecked errors; add console errors (Closed)
Patch Set: jbroman's Created 3 years, 8 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
« no previous file with comments | « extensions/renderer/api_last_error.cc ('k') | extensions/renderer/api_request_handler_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/renderer/api_last_error_unittest.cc
diff --git a/extensions/renderer/api_last_error_unittest.cc b/extensions/renderer/api_last_error_unittest.cc
index 9556dfa0379c38d337bc88675fd8e2522a41d0d1..0ec57e86bc7a8e86e33ef87513d111db9d884971 100644
--- a/extensions/renderer/api_last_error_unittest.cc
+++ b/extensions/renderer/api_last_error_unittest.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
+#include "base/optional.h"
#include "extensions/renderer/api_binding_test.h"
#include "extensions/renderer/api_binding_test_util.h"
#include "gin/converter.h"
@@ -15,6 +16,9 @@ namespace extensions {
namespace {
+void DoNothingWithError(v8::Local<v8::Context> context,
+ const std::string& error) {}
+
std::string GetLastError(v8::Local<v8::Object> parent,
v8::Local<v8::Context> context) {
v8::Local<v8::Value> last_error =
@@ -50,7 +54,8 @@ TEST_F(APILastErrorTest, TestLastError) {
v8::Local<v8::Object> parent_object = v8::Object::New(isolate());
ParentList parents = {{context, parent_object}};
- APILastError last_error(base::Bind(&GetParent, parents));
+ APILastError last_error(base::Bind(&GetParent, parents),
+ base::Bind(&DoNothingWithError));
EXPECT_EQ("undefined", GetLastError(parent_object, context));
// Check that the key isn't present on the object (as opposed to simply being
@@ -75,27 +80,36 @@ TEST_F(APILastErrorTest, ReportIfUnchecked) {
v8::Local<v8::Context> context = MainContext();
v8::Local<v8::Object> parent_object = v8::Object::New(isolate());
+ base::Optional<std::string> console_error;
+ auto log_error = [](base::Optional<std::string>* console_error,
+ v8::Local<v8::Context> context,
+ const std::string& error) { *console_error = error; };
+
ParentList parents = {{context, parent_object}};
- APILastError last_error(base::Bind(&GetParent, parents));
+ APILastError last_error(base::Bind(&GetParent, parents),
+ base::Bind(log_error, &console_error));
{
v8::TryCatch try_catch(isolate());
last_error.SetError(context, "foo");
// GetLastError() will count as accessing the error property, so we
- // shouldn't throw an exception.
+ // shouldn't log an error.
EXPECT_EQ("\"foo\"", GetLastError(parent_object, context));
last_error.ClearError(context, true);
+ EXPECT_FALSE(console_error);
EXPECT_FALSE(try_catch.HasCaught());
}
{
v8::TryCatch try_catch(isolate());
- // This time, we should throw an exception.
+ // This time, we should log an error.
last_error.SetError(context, "A last error");
last_error.ClearError(context, true);
- ASSERT_TRUE(try_catch.HasCaught());
- EXPECT_EQ("Uncaught Error: A last error",
- gin::V8ToString(try_catch.Message()->Get()));
+ ASSERT_TRUE(console_error);
+ EXPECT_EQ("Unchecked runtime.lastError: A last error", *console_error);
+ // We shouldn't have thrown an exception in order to prevent disrupting
+ // JS execution.
+ EXPECT_FALSE(try_catch.HasCaught());
}
}
@@ -107,7 +121,8 @@ TEST_F(APILastErrorTest, NonLastErrorObject) {
v8::Local<v8::Object> parent_object = v8::Object::New(isolate());
ParentList parents = {{context, parent_object}};
- APILastError last_error(base::Bind(&GetParent, parents));
+ APILastError last_error(base::Bind(&GetParent, parents),
+ base::Bind(&DoNothingWithError));
auto checked_set = [context](v8::Local<v8::Object> object,
base::StringPiece key,
@@ -143,7 +158,8 @@ TEST_F(APILastErrorTest, MultipleContexts) {
v8::Local<v8::Object> parent_a = v8::Object::New(isolate());
v8::Local<v8::Object> parent_b = v8::Object::New(isolate());
ParentList parents = {{context_a, parent_a}, {context_b, parent_b}};
- APILastError last_error(base::Bind(&GetParent, parents));
+ APILastError last_error(base::Bind(&GetParent, parents),
+ base::Bind(&DoNothingWithError));
last_error.SetError(context_a, "Last error a");
EXPECT_EQ("\"Last error a\"", GetLastError(parent_a, context_a));
« no previous file with comments | « extensions/renderer/api_last_error.cc ('k') | extensions/renderer/api_request_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698