Commit 92d8795b authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] 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: Iaf42b36ce01c47addd87ae71772abff605e75a1c
Reviewed-on: https://chromium-review.googlesource.com/1224387
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592014}
parent 1d6c313b
......@@ -62,3 +62,25 @@ source_set("unit_tests") {
"//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;
// Since the toolbar and the contentView can overlap, check the toolbar frame
// 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_]) {
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
......@@ -68,7 +68,9 @@
// swipes from the right side.
CGRect toolbarFrame =
CGRectInset([coordinator viewController].view.frame, -1, -1);
if (CGRectContainsPoint(toolbarFrame, point))
CGRect frameInWindowCoordinates =
[[coordinator viewController].view convertRect:toolbarFrame toView:nil];
if (CGRectContainsPoint(frameInWindowCoordinates, point))
return YES;
}
return NO;
......
......@@ -10,7 +10,8 @@
// Protocol used by SideSwipe to interact with the toolbar.
@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;
@end
......
......@@ -123,6 +123,7 @@ chrome_ios_eg_test("ios_chrome_ui_egtests") {
"//ios/chrome/browser/ui/sad_tab:eg_tests",
"//ios/chrome/browser/ui/safe_mode: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/stack_view: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