Commit 0bc30622 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS][EG2] Convert fullscreen EG tests to EG2

This required adding new API to ChromeEarlGrey to fetch the current
fullscreen viewport insets.

Bug: 987646
Change-Id: I18a897a558074025da81262b17429e09417fe61a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1889112Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Auto-Submit: Kurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710988}
parent 0187a21a
...@@ -157,6 +157,7 @@ source_set("unit_tests") { ...@@ -157,6 +157,7 @@ source_set("unit_tests") {
} }
source_set("eg_tests") { source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
testonly = true testonly = true
sources = [ sources = [
"fullscreen_egtest.mm", "fullscreen_egtest.mm",
...@@ -168,11 +169,13 @@ source_set("eg_tests") { ...@@ -168,11 +169,13 @@ source_set("eg_tests") {
":fullscreen", ":fullscreen",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/browser/ui/fullscreen/test:eg_test_support",
"//ios/chrome/browser/ui/side_swipe", "//ios/chrome/browser/ui/side_swipe",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/test:eg_test_support", "//ios/chrome/test:eg_test_support",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/web:earl_grey_test_support", "//ios/web:earl_grey_test_support",
"//ios/web/common", "//ios/web/common",
"//ios/web/public", "//ios/web/public",
...@@ -181,3 +184,29 @@ source_set("eg_tests") { ...@@ -181,3 +184,29 @@ source_set("eg_tests") {
] ]
libs = [ "XCTest.framework" ] libs = [ "XCTest.framework" ]
} }
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"fullscreen_egtest.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//ios/chrome/browser/ui/fullscreen/test:eg_test_support+eg2",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/common",
"//ios/web/public/test/http_server",
"//url",
]
libs = [ "UIKit.framework" ]
}
...@@ -2,31 +2,24 @@ ...@@ -2,31 +2,24 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/ios/ios_util.h" #include "base/ios/ios_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#import "ios/chrome/browser/ui/fullscreen/test/fullscreen_app_interface.h"
#include "ios/chrome/browser/ui/util/ui_util.h" #include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.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_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.h" #import "ios/chrome/test/scoped_eg_synchronization_disabler.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/common/features.h" #import "ios/web/common/features.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#import "ios/web/public/test/http_server/error_page_response_provider.h" #import "ios/web/public/test/http_server/error_page_response_provider.h"
#import "ios/web/public/test/http_server/http_server.h" #import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h" #include "ios/web/public/test/http_server/http_server_util.h"
#import "ios/web/public/web_client.h"
#import "ios/web/public/web_state.h"
#include "url/gurl.h" #include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -46,9 +39,7 @@ const int kPageHeightEM = 200; ...@@ -46,9 +39,7 @@ const int kPageHeightEM = 200;
// Hides the toolbar by scrolling down. // Hides the toolbar by scrolling down.
void HideToolbarUsingUI() { void HideToolbarUsingUI() {
[[EarlGrey [[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()]
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionUp)]; performAction:grey_swipeFastInDirection(kGREYDirectionUp)];
} }
...@@ -117,13 +108,7 @@ void AssertURLIs(const GURL& expectedURL) { ...@@ -117,13 +108,7 @@ void AssertURLIs(const GURL& expectedURL) {
errorMessage); errorMessage);
// Initial y scroll positions are set to make room for the toolbar. // Initial y scroll positions are set to make room for the toolbar.
// TODO(crbug.com/618887) Replace use of specific values when API which CGFloat yOffset = -[FullscreenAppInterface currentViewportInsets].top;
// generates these values is exposed.
CGFloat yOffset = [ChromeEarlGrey isIPadIdiom] ? -89.0 : -48.0;
// The safe area is included in the top inset as well as the toolbar
// heights.
yOffset -=
chrome_test_util::GetCurrentWebState()->GetView().safeAreaInsets.top;
DCHECK_LT(yOffset, 0); DCHECK_LT(yOffset, 0);
[[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()] [[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()]
assertWithMatcher:grey_scrollViewContentOffset(CGPointMake(0, yOffset))]; assertWithMatcher:grey_scrollViewContentOffset(CGPointMake(0, yOffset))];
...@@ -145,9 +130,7 @@ void AssertURLIs(const GURL& expectedURL) { ...@@ -145,9 +130,7 @@ void AssertURLIs(const GURL& expectedURL) {
std::make_unique<ScopedSynchronizationDisabler>(); std::make_unique<ScopedSynchronizationDisabler>();
// Test that the toolbar is still visible after a user swipes down. // Test that the toolbar is still visible after a user swipes down.
[[EarlGrey [[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()]
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
[ChromeEarlGreyUI waitForToolbarVisible:YES]; [ChromeEarlGreyUI waitForToolbarVisible:YES];
...@@ -176,9 +159,7 @@ void AssertURLIs(const GURL& expectedURL) { ...@@ -176,9 +159,7 @@ void AssertURLIs(const GURL& expectedURL) {
[ChromeEarlGreyUI waitForToolbarVisible:NO]; [ChromeEarlGreyUI waitForToolbarVisible:NO];
// Test that the toolbar is visible after a user swipes down. // Test that the toolbar is visible after a user swipes down.
[[EarlGrey [[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()]
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
[ChromeEarlGreyUI waitForToolbarVisible:YES]; [ChromeEarlGreyUI waitForToolbarVisible:YES];
...@@ -196,34 +177,21 @@ void AssertURLIs(const GURL& expectedURL) { ...@@ -196,34 +177,21 @@ void AssertURLIs(const GURL& expectedURL) {
// Hide the toolbar. The page is not long enough to dismiss the toolbar using // Hide the toolbar. The page is not long enough to dismiss the toolbar using
// the UI so we have to zoom in. // the UI so we have to zoom in.
const char script[] = NSString* script = @"(function(){"
"(function(){" "var metas = document.getElementsByTagName('meta');"
"var metas = document.getElementsByTagName('meta');" "for (var i=0; i<metas.length; i++) {"
"for (var i=0; i<metas.length; i++) {" " if (metas[i].getAttribute('name') == 'viewport') {"
" if (metas[i].getAttribute('name') == 'viewport') {" " metas[i].setAttribute('content', 'width=10');"
" metas[i].setAttribute('content', 'width=10');" " return;"
" return;" " }"
" }" "}"
"}" "document.body.innerHTML += \"<meta name='viewport' "
"document.body.innerHTML += \"<meta name='viewport' content='width=10'>\"" "content='width=10'>\""
"})()"; "})()";
[ChromeEarlGrey executeJavaScript:script];
__block bool finished = false;
chrome_test_util::GetCurrentWebState()->ExecuteJavaScript(
base::UTF8ToUTF16(script), base::BindOnce(^(const base::Value*) {
finished = true;
}));
GREYAssert(WaitUntilConditionOrTimeout(kWaitForJSCompletionTimeout,
^{
return finished;
}),
@"JavaScript to hide the toolbar did not complete");
// Scroll up to be sure the toolbar can be dismissed by scrolling down. // Scroll up to be sure the toolbar can be dismissed by scrolling down.
[[EarlGrey [[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()]
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
// Scroll to hide the UI. // Scroll to hide the UI.
...@@ -251,9 +219,7 @@ void AssertURLIs(const GURL& expectedURL) { ...@@ -251,9 +219,7 @@ void AssertURLIs(const GURL& expectedURL) {
HideToolbarUsingUI(); HideToolbarUsingUI();
[ChromeEarlGreyUI waitForToolbarVisible:NO]; [ChromeEarlGreyUI waitForToolbarVisible:NO];
// Simulate a user scroll up. // Simulate a user scroll up.
[[EarlGrey [[EarlGrey selectElementWithMatcher:WebStateScrollViewMatcher()]
selectElementWithMatcher:WebViewScrollView(
chrome_test_util::GetCurrentWebState())]
performAction:grey_swipeFastInDirection(kGREYDirectionDown)]; performAction:grey_swipeFastInDirection(kGREYDirectionDown)];
[ChromeEarlGreyUI waitForToolbarVisible:YES]; [ChromeEarlGreyUI waitForToolbarVisible:YES];
} }
......
...@@ -28,3 +28,50 @@ source_set("test") { ...@@ -28,3 +28,50 @@ source_set("test") {
"//testing/gtest", "//testing/gtest",
] ]
} }
source_set("eg_test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"fullscreen_app_interface.h",
"fullscreen_app_interface.mm",
]
deps = [
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/test/app:test_support",
]
}
source_set("eg_app_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"fullscreen_app_interface.h",
"fullscreen_app_interface.mm",
]
deps = [
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/fullscreen",
"//ios/chrome/test/app:test_support",
]
}
source_set("eg_test_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"fullscreen_app_interface.h",
"fullscreen_app_interface_stub.mm",
]
deps = [
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
]
}
// Copyright 2019 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_FULLSCREEN_TEST_FULLSCREEN_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_UI_FULLSCREEN_TEST_FULLSCREEN_APP_INTERFACE_H_
#import <UIKit/UIKit.h>
// FullscreenAppInterface contains the app-side implementation for helpers.
// These helpers are compiled into the app binary and can be called from either
// app or test code.
@interface FullscreenAppInterface : NSObject
// Returns the current viewport insets for the visible web content view.
+ (UIEdgeInsets)currentViewportInsets;
@end
#endif // IOS_CHROME_BROWSER_UI_FULLSCREEN_TEST_FULLSCREEN_APP_INTERFACE_H_
// Copyright 2019 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/fullscreen/test/fullscreen_app_interface.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller_factory.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/web/public/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation FullscreenAppInterface
+ (UIEdgeInsets)currentViewportInsets {
web::WebState* webState = chrome_test_util::GetCurrentWebState();
if (!webState)
return UIEdgeInsetsZero;
ios::ChromeBrowserState* browserState =
ios::ChromeBrowserState::FromBrowserState(webState->GetBrowserState());
FullscreenController* fullscreenController =
FullscreenControllerFactory::GetForBrowserState(browserState);
if (!fullscreenController)
return UIEdgeInsetsZero;
return fullscreenController->GetCurrentViewportInsets();
}
@end
// Copyright 2019 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/fullscreen/test/fullscreen_app_interface.h"
#import "ios/third_party/earl_grey2/src/CommonLib/DistantObject/GREYTestApplicationDistantObject.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(FullscreenAppInterface)
...@@ -373,6 +373,7 @@ source_set("eg_app_support+eg2") { ...@@ -373,6 +373,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant", "//ios/chrome/browser/ui/content_suggestions:content_suggestions_constant",
"//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui", "//ios/chrome/browser/ui/content_suggestions:content_suggestions_ui",
"//ios/chrome/browser/ui/content_suggestions:eg_app_support+eg2", "//ios/chrome/browser/ui/content_suggestions:eg_app_support+eg2",
"//ios/chrome/browser/ui/fullscreen/test:eg_app_support+eg2",
"//ios/chrome/browser/ui/history:constants", "//ios/chrome/browser/ui/history:constants",
"//ios/chrome/browser/ui/location_bar:location_bar", "//ios/chrome/browser/ui/location_bar:location_bar",
"//ios/chrome/browser/ui/omnibox:omnibox_internal", "//ios/chrome/browser/ui/omnibox:omnibox_internal",
......
...@@ -70,6 +70,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") { ...@@ -70,6 +70,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
"//ios/chrome/browser/ui/content_suggestions:eg2_tests", "//ios/chrome/browser/ui/content_suggestions:eg2_tests",
"//ios/chrome/browser/ui/dialogs:eg2_tests", "//ios/chrome/browser/ui/dialogs:eg2_tests",
"//ios/chrome/browser/ui/download:eg2_tests", "//ios/chrome/browser/ui/download:eg2_tests",
"//ios/chrome/browser/ui/fullscreen:eg2_tests",
"//ios/chrome/browser/ui/integration_tests:eg2_tests", "//ios/chrome/browser/ui/integration_tests:eg2_tests",
"//ios/chrome/browser/ui/ntp:eg2_tests", "//ios/chrome/browser/ui/ntp:eg2_tests",
"//ios/chrome/browser/ui/omnibox/popup:eg2_tests", "//ios/chrome/browser/ui/omnibox/popup:eg2_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