Commit 4e06d8b8 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Reland of "Check SideSwipe location in window coordinates"

This CL changes the way the SideSwipe is checking if the touch location
is inside the toolbar frame or not by passing it in the window
coordinates instead of in the gesture's view coordinates.
This starts creating an issue as the toolbar frame is now contained in
a container, changing its frame's origin.

Bug: 883694
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I6387b2bc68cbbe6b272a4cb88d080fe3dd96c870
Reviewed-on: https://chromium-review.googlesource.com/1233336Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592734}
parent 54e508fa
...@@ -62,3 +62,25 @@ source_set("unit_tests") { ...@@ -62,3 +62,25 @@ source_set("unit_tests") {
"//third_party/ocmock", "//third_party/ocmock",
] ]
} }
source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"side_swipe_egtest.mm",
]
deps = [
":side_swipe",
"//base",
"//ios/chrome/browser",
"//ios/chrome/browser/ui:ui_util",
"//ios/chrome/browser/ui/toolbar/adaptive:adaptive_ui",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ios/web/public/test/http_server",
]
libs = [ "XCTest.framework" ]
}
...@@ -242,7 +242,8 @@ const NSUInteger kIpadGreySwipeTabCount = 8; ...@@ -242,7 +242,8 @@ const NSUInteger kIpadGreySwipeTabCount = 8;
// Since the toolbar and the contentView can overlap, check the toolbar frame // Since the toolbar and the contentView can overlap, check the toolbar frame
// first, and confirm the right gesture recognizer is firing. // first, and confirm the right gesture recognizer is firing.
if ([self.toolbarInteractionHandler isInsideToolbar:location]) { if ([self.toolbarInteractionHandler
isInsideToolbar:[gesture.view convertPoint:location toView:nil]]) {
if (![gesture isEqual:panGestureRecognizer_]) { if (![gesture isEqual:panGestureRecognizer_]) {
return NO; return NO;
} }
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#import "ios/chrome/browser/ui/toolbar/adaptive/primary_toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/adaptive/secondary_toolbar_view.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ios/testing/earl_grey/disabled_test_macros.h"
#include "net/test/embedded_test_server/default_handlers.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Integration tests for side swipe.
@interface SideSwipeTestCase : ChromeTestCase
@end
@implementation SideSwipeTestCase
#pragma mark - Tests
// Tests that swiping horizontally on the bottom toolbar is changing tab.
- (void)testSideSwipeBottomToolbar {
if (!IsSplitToolbarMode()) {
EARL_GREY_TEST_SKIPPED(
@"This tests should only be tested if the secondary toolbar is "
@"present");
}
[self checkSideSwipeOnToolbarClass:[SecondaryToolbarView class]];
}
// Tests that swiping horizontally on the top toolbar is changing tab.
- (void)testSideSwipeTopToolbar {
[self checkSideSwipeOnToolbarClass:[PrimaryToolbarView class]];
}
#pragma mark - Helpers
// Checks that side swipe on an element of class |klass| is working to change
// tab.
- (void)checkSideSwipeOnToolbarClass:(Class)klass {
// Setup the server.
net::test_server::RegisterDefaultHandlers(self.testServer);
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
// Load the first page.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/echo")];
[ChromeEarlGrey waitForWebViewContainingText:"Echo"];
// Open a new Tab to have a tab to switch to.
[ChromeEarlGreyUI openNewTab];
// Load the second page in the new tab.
[ChromeEarlGrey loadURL:self.testServer->GetURL("/defaultresponse")];
[ChromeEarlGrey waitForWebViewContainingText:"Default response"];
// Side swipe on the toolbar.
[[EarlGrey selectElementWithMatcher:grey_kindOfClass(klass)]
performAction:grey_swipeSlowInDirection(kGREYDirectionRight)];
// Check that we swiped back to our web page.
[ChromeEarlGrey waitForWebViewContainingText:"Echo"];
}
@end
...@@ -63,8 +63,10 @@ ...@@ -63,8 +63,10 @@
// points on the max X and Y edges, which will happen frequently with edge // points on the max X and Y edges, which will happen frequently with edge
// swipes from the right side. // swipes from the right side.
CGRect toolbarFrame = CGRect toolbarFrame =
CGRectInset([coordinator viewController].view.frame, -1, -1); CGRectInset([coordinator viewController].view.bounds, -1, -1);
if (CGRectContainsPoint(toolbarFrame, point)) CGPoint pointInToolbarCoordinates =
[[coordinator viewController].view convertPoint:point fromView:nil];
if (CGRectContainsPoint(toolbarFrame, pointInToolbarCoordinates))
return YES; return YES;
} }
return NO; return NO;
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
// Protocol used by SideSwipe to interact with the toolbar. // Protocol used by SideSwipe to interact with the toolbar.
@protocol SideSwipeToolbarInteracting @protocol SideSwipeToolbarInteracting
// Returns whether the |point| is inside a toolbar's frame. // Returns whether the |point| is inside a toolbar's frame. The |point| must be
// in the window coordinates.
- (BOOL)isInsideToolbar:(CGPoint)point; - (BOOL)isInsideToolbar:(CGPoint)point;
@end @end
......
...@@ -114,6 +114,7 @@ chrome_ios_eg_test("ios_chrome_ui_egtests") { ...@@ -114,6 +114,7 @@ chrome_ios_eg_test("ios_chrome_ui_egtests") {
"//ios/chrome/browser/ui/sad_tab:eg_tests", "//ios/chrome/browser/ui/sad_tab:eg_tests",
"//ios/chrome/browser/ui/safe_mode:eg_tests", "//ios/chrome/browser/ui/safe_mode:eg_tests",
"//ios/chrome/browser/ui/settings/sync_utils:eg_tests", "//ios/chrome/browser/ui/settings/sync_utils:eg_tests",
"//ios/chrome/browser/ui/side_swipe:eg_tests",
"//ios/chrome/browser/ui/signin_interaction:eg_tests", "//ios/chrome/browser/ui/signin_interaction:eg_tests",
"//ios/chrome/browser/ui/stack_view:eg_tests", "//ios/chrome/browser/ui/stack_view:eg_tests",
"//ios/chrome/browser/ui/tab_switcher:eg_tests", "//ios/chrome/browser/ui/tab_switcher:eg_tests",
......
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