Commit 9781ec38 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

[iOS] Add additional Context Menu metrics.

The ContextMenu.DelayedElementDetails metric ensures that all awaiting
requests are eventually processed by either the user cancelling or by
the DOM element details being returned.

The ContextMenu.CancelSystemTouches metric logs that the system touches
were cancelled. This value should match the number of Context Menus
shown, otherwise a user could continue to interact with the page after
the Context Menu has been displayed.

Bug: 817517
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I4dc5d9d14eba12c06ca034b80c037bd673230878
Reviewed-on: https://chromium-review.googlesource.com/1102994
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568450}
parent ad509518
...@@ -477,12 +477,36 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) { ...@@ -477,12 +477,36 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
}); });
} }
// Tests that system touches are cancelled when the context menu is shown.
// (While the kContextMenuElementPostMessage feature is enabled.)
- (void)testContextMenuCancelSystemTouchesMetricPostMessage {
base::test::ScopedFeatureList scopedFeatureList;
scopedFeatureList.InitAndEnableFeature(
web::features::kContextMenuElementPostMessage);
chrome_test_util::HistogramTester histogramTester;
const GURL pageURL = self.testServer->GetURL(kLogoPagePath);
[ChromeEarlGrey loadURL:pageURL];
[ChromeEarlGrey waitForWebViewContainingText:kLogoPageText];
LongPressElement(kLogoPageChromiumImageId);
TapOnContextMenuButton(OpenImageButton());
[ChromeEarlGrey waitForPageToFinishLoading];
// Verify that system touches were cancelled.
histogramTester.ExpectTotalCount("ContextMenu.CancelSystemTouches", 1,
^(NSString* error) {
GREYFail(error);
});
}
// Tests that the system selected text callout is displayed instead of the // Tests that the system selected text callout is displayed instead of the
// context menu when user long presses on plain text. // context menu when user long presses on plain text.
- (void)testContextMenuSelectedTextCalloutPostMessage { - (void)testContextMenuSelectedTextCalloutPostMessage {
base::test::ScopedFeatureList scopedFeatureList; base::test::ScopedFeatureList scopedFeatureList;
scopedFeatureList.InitAndEnableFeature( scopedFeatureList.InitAndEnableFeature(
web::features::kContextMenuElementPostMessage); web::features::kContextMenuElementPostMessage);
chrome_test_util::HistogramTester histogramTester;
// Load the destination page directly because it has a plain text message on // Load the destination page directly because it has a plain text message on
// it. // it.
...@@ -499,6 +523,12 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) { ...@@ -499,6 +523,12 @@ void SelectTabAtIndexInCurrentMode(NSUInteger index) {
// Verify that system text selection callout is displayed. // Verify that system text selection callout is displayed.
[[[EarlGrey selectElementWithMatcher:SystemSelectionCalloutCopyButton()] [[[EarlGrey selectElementWithMatcher:SystemSelectionCalloutCopyButton()]
inRoot:SystemSelectionCallout()] assertWithMatcher:grey_notNil()]; inRoot:SystemSelectionCallout()] assertWithMatcher:grey_notNil()];
// Verify that system touches were not cancelled.
histogramTester.ExpectTotalCount("ContextMenu.CancelSystemTouches", 0,
^(NSString* error) {
GREYFail(error);
});
} }
@end @end
...@@ -60,6 +60,25 @@ enum class ContextMenuElementFrame { ...@@ -60,6 +60,25 @@ enum class ContextMenuElementFrame {
Count Count
}; };
// Name of the histogram for recording when the gesture recognizer recognizes a
// long press before the DOM element details are available.
const std::string kContextMenuDelayedElementDetailsHistogram =
"ContextMenu.DelayedElementDetails";
// Enum used to record resulting action when the gesture recognizer recognizes a
// long press before the DOM element details are available.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class DelayedElementDetailsState {
// Recorded when the context menu is displayed when receiving the dom element
// details after the gesture recognizer had already recognized a long press.
Show = 0,
// Recorded when the context menu is not displayed after the gesture
// recognizer fully recognized a long press.
Cancel = 1,
kMaxValue = Cancel
};
// Struct to track the details of the element at |location| in |webView|. // Struct to track the details of the element at |location| in |webView|.
struct ContextMenuInfo { struct ContextMenuInfo {
// The location of the long press. // The location of the long press.
...@@ -291,6 +310,7 @@ struct ContextMenuInfo { ...@@ -291,6 +310,7 @@ struct ContextMenuInfo {
} else { } else {
// Shows the context menu once the DOM element information is set. // Shows the context menu once the DOM element information is set.
_contextMenuNeedsDisplay = YES; _contextMenuNeedsDisplay = YES;
UMA_HISTOGRAM_BOOLEAN("ContextMenu.WaitingForElementDetails", true);
} }
} }
} }
...@@ -333,6 +353,8 @@ struct ContextMenuInfo { ...@@ -333,6 +353,8 @@ struct ContextMenuInfo {
} }
- (void)cancelAllTouches { - (void)cancelAllTouches {
UMA_HISTOGRAM_BOOLEAN("ContextMenu.CancelSystemTouches", true);
// Disable web view scrolling. // Disable web view scrolling.
CancelTouches(self.webView.scrollView.panGestureRecognizer); CancelTouches(self.webView.scrollView.panGestureRecognizer);
...@@ -354,6 +376,8 @@ struct ContextMenuInfo { ...@@ -354,6 +376,8 @@ struct ContextMenuInfo {
- (void)setDOMElementForLastTouch:(NSDictionary*)element { - (void)setDOMElementForLastTouch:(NSDictionary*)element {
_contextMenuInfoForLastTouch.dom_element = [element copy]; _contextMenuInfoForLastTouch.dom_element = [element copy];
if (_contextMenuNeedsDisplay) { if (_contextMenuNeedsDisplay) {
UMA_HISTOGRAM_ENUMERATION(kContextMenuDelayedElementDetailsHistogram,
DelayedElementDetailsState::Show);
[self showContextMenu]; [self showContextMenu];
} }
} }
...@@ -390,6 +414,10 @@ struct ContextMenuInfo { ...@@ -390,6 +414,10 @@ struct ContextMenuInfo {
} }
- (void)cancelContextMenuDisplay { - (void)cancelContextMenuDisplay {
if (_contextMenuNeedsDisplay) {
UMA_HISTOGRAM_ENUMERATION(kContextMenuDelayedElementDetailsHistogram,
DelayedElementDetailsState::Cancel);
}
_contextMenuNeedsDisplay = NO; _contextMenuNeedsDisplay = NO;
for (HTMLElementFetchRequest* fetchRequest in _pendingElementFetchRequests for (HTMLElementFetchRequest* fetchRequest in _pendingElementFetchRequests
.allValues) { .allValues) {
......
...@@ -7209,6 +7209,21 @@ Called by update_net_error_codes.py.--> ...@@ -7209,6 +7209,21 @@ Called by update_net_error_codes.py.-->
<int value="12" label="CONTEXT_LOST_INVALID_GPU_MESSAGE"/> <int value="12" label="CONTEXT_LOST_INVALID_GPU_MESSAGE"/>
</enum> </enum>
<enum name="ContextMenuDelayedElementDetails">
<summary>
Used to record resulting action when the gesture recognizer recognizes a
long press before the DOM element details are available.
</summary>
<int value="0" label="Show">
Recorded when the context menu is shown once the DOM element details become
available.
</int>
<int value="1" label="Cancel">
Recorded when the context menu display is cancelled before the DOM element
details are available.
</int>
</enum>
<enum name="ContextMenuDOMElementFrame"> <enum name="ContextMenuDOMElementFrame">
<summary>The frame that the element was found in.</summary> <summary>The frame that the element was found in.</summary>
<int value="0" label="Main frame"> <int value="0" label="Main frame">
...@@ -13400,6 +13400,26 @@ uploading your change for review. ...@@ -13400,6 +13400,26 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="ContextMenu.CancelSystemTouches" enum="BooleanHit">
<owner>michaeldo@chromium.org</owner>
<summary>
Logs true when the system touches are cancelled in order to show the Context
Menu instead of performing a default system action. Only logged on iOS.
</summary>
</histogram>
<histogram name="ContextMenu.DelayedElementDetails"
enum="ContextMenuDelayedElementDetails">
<owner>michaeldo@chromium.org</owner>
<summary>
Logged when DOM element details are not yet available when the user
completes a long press. Also logs if the context menu was shown once the
element details became available or if the display was cancelled. This
ensures that all context menu gestures are eventually processed. Only logged
on iOS.
</summary>
</histogram>
<histogram name="ContextMenu.DOMElementFetchDuration" units="ms"> <histogram name="ContextMenu.DOMElementFetchDuration" units="ms">
<owner>michaeldo@chromium.org</owner> <owner>michaeldo@chromium.org</owner>
<summary> <summary>
...@@ -13458,6 +13478,15 @@ uploading your change for review. ...@@ -13458,6 +13478,15 @@ uploading your change for review.
</summary> </summary>
</histogram> </histogram>
<histogram name="ContextMenu.WaitingForElementDetails" enum="BooleanHit">
<owner>michaeldo@chromium.org</owner>
<summary>
Logs true when the context menu gesture recognizer fully recognizes a long
press, but is still waiting on the DOM element details before the context
menu can be shown. Only logged on iOS.
</summary>
</histogram>
<histogram name="ContextualSuggestions.EnabledState" enum="BooleanEnabled"> <histogram name="ContextualSuggestions.EnabledState" enum="BooleanEnabled">
<owner>huayinz@chromium.org</owner> <owner>huayinz@chromium.org</owner>
<owner>twellington@chromium.org</owner> <owner>twellington@chromium.org</owner>
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