Commit 0ce82e0f authored by edchin's avatar edchin Committed by Commit Bot

Reland "[ios] Create UI test for page info (site info)"

This is a reland of d3708f20

The previous CL did not return the device to the original rotation.

Original change's description:
> [ios] Create UI test for page info (site info)
>
> This CL creates an UI integration test that tests that the
> page info view gets automatically dismissed on device rotation.
>
> Change-Id: I02611cc2fab5a214b74af01d15cd8d12e19eff6e
> Reviewed-on: https://chromium-review.googlesource.com/c/1338561
> Commit-Queue: edchin <edchin@chromium.org>
> Reviewed-by: Gauthier Ambard <gambard@chromium.org>
> Reviewed-by: Rohit Rao <rohitrao@chromium.org>
> Reviewed-by: edchin <edchin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#608844}

Change-Id: I5c4a8286275b1ab3d411d4e355557d499607437a
Reviewed-on: https://chromium-review.googlesource.com/c/1343517
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611941}
parent 1752f776
......@@ -5,6 +5,8 @@
source_set("page_info") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"page_info_constants.h",
"page_info_constants.mm",
"page_info_model.cc",
"page_info_model.h",
"page_info_model_observer.h",
......@@ -58,3 +60,21 @@ source_set("coordinator") {
]
libs = [ "UIKit.framework" ]
}
source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"page_info_egtest.mm",
]
deps = [
":page_info",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test/earl_grey:test_support",
]
libs = [
"UIKit.framework",
"XCTest.framework",
]
}
// 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.
#ifndef IOS_CHROME_BROWSER_UI_PAGE_INFO_PAGE_INFO_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_PAGE_INFO_PAGE_INFO_CONSTANTS_H_
#import <Foundation/Foundation.h>
// Accessibility identifier for the page info view.
extern NSString* const kPageInfoViewAccessibilityIdentifier;
#endif // IOS_CHROME_BROWSER_UI_PAGE_INFO_PAGE_INFO_CONSTANTS_H_
// 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 "ios/chrome/browser/ui/page_info/page_info_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* const kPageInfoViewAccessibilityIdentifier =
@"PageInfoViewAccessibilityIdentifier";
// 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 <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import "ios/chrome/browser/ui/page_info/page_info_constants.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#include "ios/chrome/browser/ui/util/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_test_case.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface PageInfoTestCase : ChromeTestCase
@end
@implementation PageInfoTestCase
// Tests that rotating the device will automatically dismiss the page info view.
- (void)testShowPageInfoAndDismissOnDeviceRotation {
// TODO(crbug.com/652465): Enable the test for iPad when rotation bug is
// fixed.
if (IsIPadIdiom()) {
EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to device rotation bug.");
}
if ([[UIDevice currentDevice] orientation] != UIDeviceOrientationPortrait) {
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait
errorOrNil:nil];
}
[ChromeEarlGrey loadURL:GURL("https://invalid")];
[ChromeEarlGreyUI openToolsMenu];
[[[EarlGrey
selectElementWithMatcher:grey_allOf(grey_accessibilityID(
kToolsMenuSiteInformation),
grey_sufficientlyVisible(), nil)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_accessibilityID(kPopupMenuToolsMenuTableViewId)]
performAction:grey_tap()];
// Expect that the page info view has appeared.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kPageInfoViewAccessibilityIdentifier)]
assertWithMatcher:grey_sufficientlyVisible()];
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeRight
errorOrNil:nil];
// Expect that the page info view has disappeared.
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kPageInfoViewAccessibilityIdentifier)]
assertWithMatcher:grey_nil()];
}
@end
......@@ -14,6 +14,7 @@
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/commands/page_info_commands.h"
#import "ios/chrome/browser/ui/fancy_ui/bidi_container_view.h"
#import "ios/chrome/browser/ui/page_info/page_info_constants.h"
#include "ios/chrome/browser/ui/page_info/page_info_model.h"
#import "ios/chrome/browser/ui/page_info/requirements/page_info_presentation.h"
#import "ios/chrome/browser/ui/page_info/requirements/page_info_reloading.h"
......@@ -258,6 +259,8 @@ void PageInfoModelBubbleBridge::PerformLayout() {
[containerView_ setOpaque:NO];
[containerView_ setAlpha:0];
[containerView_ setAccessibilityViewIsModal:YES];
containerView_.accessibilityIdentifier =
kPageInfoViewAccessibilityIdentifier;
popupContainer_ = [[UIView alloc] initWithFrame:CGRectZero];
[popupContainer_ setBackgroundColor:[UIColor whiteColor]];
......
......@@ -97,6 +97,7 @@ chrome_ios_eg_test("ios_chrome_ui_egtests") {
"//ios/chrome/browser/ui/infobars:eg_tests",
"//ios/chrome/browser/ui/ntp:eg_tests",
"//ios/chrome/browser/ui/omnibox/popup:eg_tests",
"//ios/chrome/browser/ui/page_info:eg_tests",
"//ios/chrome/browser/ui/payments:eg_tests",
"//ios/chrome/browser/ui/popup_menu:eg_tests",
"//ios/chrome/browser/ui/print:eg_tests",
......
......@@ -92,6 +92,9 @@ const CFTimeInterval kDrainTimeout = 5;
BOOL _isHTTPServerStopped;
BOOL _isMockAuthenticationDisabled;
std::unique_ptr<net::EmbeddedTestServer> _testServer;
// The orientation of the device when entering these tests.
UIDeviceOrientation _originalOrientation;
}
// Cleans up mock authentication.
......@@ -192,6 +195,7 @@ const CFTimeInterval kDrainTimeout = 5;
_isHTTPServerStopped = NO;
_isMockAuthenticationDisabled = NO;
_tearDownHandler = nil;
_originalOrientation = [[UIDevice currentDevice] orientation];
chrome_test_util::ResetSigninPromoPreferences();
chrome_test_util::ResetMockAuthentication();
......@@ -224,6 +228,12 @@ const CFTimeInterval kDrainTimeout = 5;
// state.
[[self class] removeAnyOpenMenusAndInfoBars];
[[self class] closeAllTabs];
if ([[UIDevice currentDevice] orientation] != _originalOrientation) {
// Rotate the device back to the original orientation, since some tests
// attempt to run in other orientations.
[EarlGrey rotateDeviceToOrientation:_originalOrientation errorOrNil:nil];
}
[super tearDown];
}
......
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