Commit 68de9b4d authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Fix ContextMenu.UnexpectedFindElementResultHandlerMessage logging.

Ensure that expected FindElementResultHandler messages do not trigger
the ContextMenu.UnexpectedFindElementResultHandlerMessage histogram.
The message should not be considered unexpected even if the message is
received after the CRWContextMenuController has cancelled showing the
context menu.

Bug: 228355
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Iff6535420cd7a2eb8ba516f5d777c07352915852
Reviewed-on: https://chromium-review.googlesource.com/996526Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548458}
parent 1519479b
......@@ -388,7 +388,10 @@ struct ContextMenuInfo {
- (void)cancelContextMenuDisplay {
_contextMenuNeedsDisplay = NO;
[_pendingElementFetchRequests removeAllObjects];
for (HTMLElementFetchRequest* fetchRequest in _pendingElementFetchRequests
.allValues) {
[fetchRequest invalidate];
}
}
#pragma mark -
......
......@@ -24,8 +24,12 @@ class TimeTicks;
(void (^)(NSDictionary*))foundElementHandler NS_DESIGNATED_INITIALIZER;
// Calls the |foundElementHandler| from the receiver's initializer with
// |response| as the parameter.
// |response| as the parameter. This method has no effect if |invalidate| has
// been called.
- (void)runHandlerWithResponse:(NSDictionary*)response;
// Removes the stored |foundElementHandler| from the receiver's initializer.
// |runHandlerWithResponse:| will have no effect if called after |invalidate|.
- (void)invalidate;
@end
......
......@@ -31,7 +31,13 @@
}
- (void)runHandlerWithResponse:(NSDictionary*)response {
_foundElementHandler(response);
if (_foundElementHandler) {
_foundElementHandler(response);
}
}
- (void)invalidate {
_foundElementHandler = nullptr;
}
@end
......@@ -45,4 +45,18 @@ TEST_F(HtmlElementFetchRequestTest, RunHandler) {
EXPECT_NSEQ(response, received_response);
}
// Tests that |runHandlerWithResponse:| does not run the handler from the
// object's initializer if |invalidate| has been called.
TEST_F(HtmlElementFetchRequestTest, Invalidate) {
__block bool handler_called = false;
void (^handler)(NSDictionary*) = ^(NSDictionary* response) {
handler_called = true;
};
HTMLElementFetchRequest* request =
[[HTMLElementFetchRequest alloc] initWithFoundElementHandler:handler];
[request invalidate];
[request runHandlerWithResponse:nil];
EXPECT_FALSE(handler_called);
}
} // namespace web
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment