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

Unified Diff: extensions/renderer/api_event_handler_unittest.cc

Issue 2722463006: [Extensions Bindings] Notify of event unregistration on invalidation (Closed)
Patch Set: nits Created 3 years, 10 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: extensions/renderer/api_event_handler_unittest.cc
diff --git a/extensions/renderer/api_event_handler_unittest.cc b/extensions/renderer/api_event_handler_unittest.cc
index e4d39d255a8312c413ef9b2df3a6702d6f27c547..e2b33be6d4186b1eddd2f767c71a692f6cc70622 100644
--- a/extensions/renderer/api_event_handler_unittest.cc
+++ b/extensions/renderer/api_event_handler_unittest.cc
@@ -128,6 +128,8 @@ TEST_F(APIEventHandlerTest, AddingRemovingAndQueryingEventListeners) {
gin::Converter<bool>::FromV8(isolate(), result, &has_listeners));
EXPECT_FALSE(has_listeners);
}
+
+ handler.InvalidateContext(context);
}
// Tests listening for and firing different events.
@@ -226,6 +228,8 @@ TEST_F(APIEventHandlerTest, FiringEvents) {
EXPECT_EQ(2, get_fired_count("alphaCount1"));
EXPECT_EQ(2, get_fired_count("alphaCount2"));
EXPECT_EQ(1, get_fired_count("betaCount"));
+
+ handler.InvalidateContext(context);
}
// Tests firing events with arguments.
@@ -263,6 +267,8 @@ TEST_F(APIEventHandlerTest, EventArguments) {
EXPECT_EQ(
ReplaceSingleQuotes(kArguments),
GetStringPropertyFromObject(context->Global(), context, "eventArgs"));
+
+ handler.InvalidateContext(context);
}
// Test dispatching events to multiple contexts.
@@ -348,6 +354,9 @@ TEST_F(APIEventHandlerTest, MultipleContexts) {
GetStringPropertyFromObject(context_b->Global(), context_b,
"eventArgs"));
}
+
+ handler.InvalidateContext(context_a);
+ handler.InvalidateContext(context_b);
}
TEST_F(APIEventHandlerTest, DifferentCallingMethods) {
@@ -403,6 +412,8 @@ TEST_F(APIEventHandlerTest, DifferentCallingMethods) {
context, 1, args);
}
EXPECT_EQ(2u, handler.GetNumEventListenersForTesting(kEventName, context));
+
+ handler.InvalidateContext(context);
}
TEST_F(APIEventHandlerTest, TestDispatchFromJs) {
@@ -443,6 +454,8 @@ TEST_F(APIEventHandlerTest, TestDispatchFromJs) {
EXPECT_EQ("[42,\"foo\",{\"bar\":\"baz\"}]",
GetStringPropertyFromObject(
context->Global(), context, "eventArgs"));
+
+ handler.InvalidateContext(context);
}
// Test listeners that remove themselves in their handling of the event.
@@ -499,6 +512,7 @@ TEST_F(APIEventHandlerTest, RemovingListenersWhileHandlingEvent) {
handler.FireEventInContext(kEventName, context, base::ListValue());
EXPECT_EQ(0u, handler.GetNumEventListenersForTesting(kEventName, context));
+ handler.InvalidateContext(context);
// TODO(devlin): Another possible test: register listener a and listener b,
// where a removes b and b removes a. Theoretically, only one should be
// notified. Investigate what we currently do in JS-style bindings.
@@ -583,6 +597,8 @@ TEST_F(APIEventHandlerTest, TestEventListenersThrowingExceptions) {
EXPECT_EQ("[42]", GetStringPropertyFromObject(context->Global(), context,
"eventArgs"));
EXPECT_TRUE(did_throw);
+
+ handler.InvalidateContext(context);
}
// Tests being notified as listeners are added or removed from events.
@@ -705,6 +721,26 @@ TEST_F(APIEventHandlerTest, CallbackNotifications) {
}
EXPECT_EQ(1u,
handler.GetNumEventListenersForTesting(kEventName1, context_b));
+
+ // When the contexts are invalidated, we should receive listener removed
+ // notifications.
+ EXPECT_CALL(
+ change_handler,
+ Run(kEventName1, binding::EventListenersChanged::NO_LISTENERS, context_a))
+ .Times(1);
+ EXPECT_CALL(
+ change_handler,
+ Run(kEventName2, binding::EventListenersChanged::NO_LISTENERS, context_a))
+ .Times(1);
+ handler.InvalidateContext(context_a);
+ ::testing::Mock::VerifyAndClearExpectations(&change_handler);
+
+ EXPECT_CALL(
+ change_handler,
+ Run(kEventName1, binding::EventListenersChanged::NO_LISTENERS, context_b))
+ .Times(1);
+ handler.InvalidateContext(context_b);
+ ::testing::Mock::VerifyAndClearExpectations(&change_handler);
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698