| Index: extensions/renderer/bindings/api_last_error_unittest.cc
|
| diff --git a/extensions/renderer/bindings/api_last_error_unittest.cc b/extensions/renderer/bindings/api_last_error_unittest.cc
|
| index 09f42aacef405baa58460230b6a5f57f5fbe3f7d..adbd99603eae8741bccf7a175d6fec8da81cca2f 100644
|
| --- a/extensions/renderer/bindings/api_last_error_unittest.cc
|
| +++ b/extensions/renderer/bindings/api_last_error_unittest.cc
|
| @@ -41,7 +41,8 @@ std::string GetLastErrorMessage(v8::Local<v8::Object> parent,
|
| using ParentList =
|
| std::vector<std::pair<v8::Local<v8::Context>, v8::Local<v8::Object>>>;
|
| v8::Local<v8::Object> GetParent(const ParentList& parents,
|
| - v8::Local<v8::Context> context) {
|
| + v8::Local<v8::Context> context,
|
| + v8::Local<v8::Object>* secondary_parent) {
|
| // This would be simpler with a map<context, object>, but Local<> doesn't
|
| // define an operator<.
|
| for (const auto& parent : parents) {
|
| @@ -222,4 +223,55 @@ TEST_F(APILastErrorTest, MultipleContexts) {
|
| EXPECT_EQ("undefined", GetLastErrorMessage(parent_b, context_b));
|
| }
|
|
|
| +TEST_F(APILastErrorTest, SecondaryParent) {
|
| + auto get_parents = [](v8::Local<v8::Object> primary_parent,
|
| + v8::Local<v8::Object> secondary_parent,
|
| + v8::Local<v8::Context> context,
|
| + v8::Local<v8::Object>* secondary_parent_out) {
|
| + if (secondary_parent_out)
|
| + *secondary_parent_out = secondary_parent;
|
| + return primary_parent;
|
| + };
|
| +
|
| + 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; };
|
| +
|
| + v8::HandleScope handle_scope(isolate());
|
| + v8::Local<v8::Context> context = MainContext();
|
| + v8::Local<v8::Object> primary_parent = v8::Object::New(isolate());
|
| + v8::Local<v8::Object> secondary_parent = v8::Object::New(isolate());
|
| +
|
| + APILastError last_error(
|
| + base::Bind(get_parents, primary_parent, secondary_parent),
|
| + base::Bind(log_error, &console_error));
|
| +
|
| + last_error.SetError(context, "error");
|
| + EXPECT_TRUE(last_error.HasError(context));
|
| + EXPECT_EQ("\"error\"", GetLastErrorMessage(primary_parent, context));
|
| + EXPECT_EQ("\"error\"", GetLastErrorMessage(secondary_parent, context));
|
| + EXPECT_FALSE(console_error);
|
| +
|
| + last_error.ClearError(context, true);
|
| + EXPECT_FALSE(console_error);
|
| + EXPECT_EQ("undefined", GetLastErrorMessage(primary_parent, context));
|
| + EXPECT_EQ("undefined", GetLastErrorMessage(secondary_parent, context));
|
| +
|
| + // Accessing the primary parent's error should be sufficient to not log the
|
| + // error in the console.
|
| + last_error.SetError(context, "error");
|
| + EXPECT_EQ("\"error\"", GetLastErrorMessage(primary_parent, context));
|
| + last_error.ClearError(context, true);
|
| + EXPECT_FALSE(console_error);
|
| +
|
| + // Accessing only the secondary parent's error shouldn't count as access on
|
| + // the main error, and we should log it.
|
| + last_error.SetError(context, "error");
|
| + EXPECT_EQ("\"error\"", GetLastErrorMessage(secondary_parent, context));
|
| + last_error.ClearError(context, true);
|
| + ASSERT_TRUE(console_error);
|
| + EXPECT_EQ("Unchecked runtime.lastError: error", *console_error);
|
| +}
|
| +
|
| } // namespace extensions
|
|
|