Commit f9e80770 authored by Rohit Rao's avatar Rohit Rao Committed by Commit Bot

[ios] Converts TabSwitcherTransitionTestCase to EG2.

BUG=987646

Change-Id: I41920758c20b88c0a20a609286a2203c4be2fce6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865404
Commit-Queue: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707394}
parent 30e651ad
...@@ -135,7 +135,11 @@ source_set("unit_tests") { ...@@ -135,7 +135,11 @@ source_set("unit_tests") {
} }
source_set("eg_tests") { source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ] defines = [ "CHROME_EARL_GREY_1" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true testonly = true
sources = [ sources = [
"tab_grid_egtest.mm", "tab_grid_egtest.mm",
...@@ -150,7 +154,31 @@ source_set("eg_tests") { ...@@ -150,7 +154,31 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/tab_grid:tab_grid_ui", "//ios/chrome/browser/ui/tab_grid:tab_grid_ui",
"//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/public/test/http_server", "//ios/web/public/test/http_server",
] ]
libs = [ "XCTest.framework" ] libs = [ "UIKit.framework" ]
}
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"tab_grid_transition_egtest.mm",
]
deps = [
":tab_grid_ui_constants",
"//base",
"//ios/chrome/app/strings",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//net:test_support",
]
libs = [ "UIKit.framework" ]
} }
...@@ -2,22 +2,17 @@ ...@@ -2,22 +2,17 @@
// 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 <UIKit/UIKit.h>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#include "base/bind.h" #include "base/bind.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#import "ios/chrome/app/main_controller.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_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/testing/earl_grey/earl_grey_test.h"
#include "net/test/embedded_test_server/http_request.h" #include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h" #include "net/test/embedded_test_server/http_response.h"
#include "net/test/embedded_test_server/request_handler_util.h" #include "net/test/embedded_test_server/request_handler_util.h"
...@@ -26,26 +21,24 @@ ...@@ -26,26 +21,24 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::TabGridDoneButton; using chrome_test_util::TabGridDoneButton;
using chrome_test_util::TabGridIncognitoTabsPanelButton; using chrome_test_util::TabGridIncognitoTabsPanelButton;
using chrome_test_util::TabGridNewIncognitoTabButton; using chrome_test_util::TabGridNewIncognitoTabButton;
using chrome_test_util::TabGridNewTabButton; using chrome_test_util::TabGridNewTabButton;
using chrome_test_util::TabGridOpenButton; using chrome_test_util::TabGridOpenButton;
using chrome_test_util::TabGridOpenTabsPanelButton; using chrome_test_util::TabGridOpenTabsPanelButton;
// using chrome_test_util::TabletTabSwitcherCloseButton;
// using chrome_test_util::TabletTabSwitcherIncognitoTabsPanelButton;
// using chrome_test_util::TabletTabSwitcherNewIncognitoTabButton;
// using chrome_test_util::TabletTabSwitcherNewTabButton;
// using chrome_test_util::TabletTabSwitcherOpenButton;
// using chrome_test_util::TabletTabSwitcherOpenTabsPanelButton;
namespace { namespace {
// Returns the tab model for non-incognito tabs. // Rotates the device to the given orientation.
TabModel* GetNormalTabModel() { void RotateDevice(UIDeviceOrientation orientation) {
return chrome_test_util::GetMainController() #if defined(CHROME_EARL_GREY_1)
.interfaceProvider.mainInterface.tabModel; [EarlGrey rotateDeviceToOrientation:orientation errorOrNil:nil];
#elif defined(CHROME_EARL_GREY_2)
[EarlGrey rotateDeviceToOrientation:orientation error:nil];
#else
#error
#endif
} }
// Shows the tab switcher by tapping the switcher button. Works on both phone // Shows the tab switcher by tapping the switcher button. Works on both phone
...@@ -115,8 +108,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -115,8 +108,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Rotate the device back to portrait if needed, since some tests attempt to run // Rotate the device back to portrait if needed, since some tests attempt to run
// in landscape. // in landscape.
- (void)tearDown { - (void)tearDown {
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait RotateDevice(UIDeviceOrientationPortrait);
errorOrNil:nil];
[super tearDown]; [super tearDown];
} }
...@@ -150,7 +142,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -150,7 +142,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Tests entering the tab switcher when one incognito tab is open. // Tests entering the tab switcher when one incognito tab is open.
- (void)testEnterSwitcherWithOneIncognitoTab { - (void)testEnterSwitcherWithOneIncognitoTab {
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[GetNormalTabModel() closeAllTabs]; [ChromeEarlGrey closeAllNormalTabs];
ShowTabSwitcher(); ShowTabSwitcher();
} }
...@@ -158,7 +150,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -158,7 +150,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Tests entering the tab switcher when more than one incognito tab is open. // Tests entering the tab switcher when more than one incognito tab is open.
- (void)testEnterSwitcherWithMultipleIncognitoTabs { - (void)testEnterSwitcherWithMultipleIncognitoTabs {
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[GetNormalTabModel() closeAllTabs]; [ChromeEarlGrey closeAllNormalTabs];
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
...@@ -182,7 +174,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -182,7 +174,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Tests entering the tab switcher by closing the last incognito tab. // Tests entering the tab switcher by closing the last incognito tab.
- (void)testEnterSwitcherByClosingLastIncognitoTab { - (void)testEnterSwitcherByClosingLastIncognitoTab {
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[GetNormalTabModel() closeAllTabs]; [ChromeEarlGrey closeAllNormalTabs];
[ChromeEarlGrey closeAllTabsInCurrentMode]; [ChromeEarlGrey closeAllTabsInCurrentMode];
} }
...@@ -228,7 +220,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -228,7 +220,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
// Set up by creating a new incognito tab and closing all normal tabs. // Set up by creating a new incognito tab and closing all normal tabs.
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[GetNormalTabModel() closeAllTabs]; [ChromeEarlGrey closeAllNormalTabs];
// Enter the switcher and open a new incognito tab using the new tab button. // Enter the switcher and open a new incognito tab using the new tab button.
ShowTabSwitcher(); ShowTabSwitcher();
...@@ -311,7 +303,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -311,7 +303,7 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab2_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab2_title]];
[ChromeEarlGreyUI openNewIncognitoTab]; [ChromeEarlGreyUI openNewIncognitoTab];
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab3_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab3_title]];
[GetNormalTabModel() closeAllTabs]; [ChromeEarlGrey closeAllNormalTabs];
ShowTabSwitcher(); ShowTabSwitcher();
SelectTab(tab1_title); SelectTab(tab1_title);
...@@ -378,24 +370,21 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle( ...@@ -378,24 +370,21 @@ std::unique_ptr<net::test_server::HttpResponse> HandleQueryTitle(
[ChromeEarlGrey loadURL:[self makeURLForTitle:tab_title]]; [ChromeEarlGrey loadURL:[self makeURLForTitle:tab_title]];
// Show the tab switcher and return to the BVC, in portrait. // Show the tab switcher and return to the BVC, in portrait.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait RotateDevice(UIDeviceOrientationPortrait);
errorOrNil:nil];
ShowTabSwitcher(); ShowTabSwitcher();
SelectTab(tab_title); SelectTab(tab_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)];
// Show the tab switcher and return to the BVC, in landscape. // Show the tab switcher and return to the BVC, in landscape.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationLandscapeLeft RotateDevice(UIDeviceOrientationLandscapeLeft);
errorOrNil:nil];
ShowTabSwitcher(); ShowTabSwitcher();
SelectTab(tab_title); SelectTab(tab_title);
[ChromeEarlGrey [ChromeEarlGrey
waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)]; waitForWebStateContainingText:base::SysNSStringToUTF8(tab_title)];
// Show the tab switcher and return to the BVC, in portrait. // Show the tab switcher and return to the BVC, in portrait.
[EarlGrey rotateDeviceToOrientation:UIDeviceOrientationPortrait RotateDevice(UIDeviceOrientationPortrait);
errorOrNil:nil];
ShowTabSwitcher(); ShowTabSwitcher();
SelectTab(tab_title); SelectTab(tab_title);
[ChromeEarlGrey [ChromeEarlGrey
......
...@@ -60,6 +60,7 @@ source_set("test_support") { ...@@ -60,6 +60,7 @@ source_set("test_support") {
"//ios/chrome/browser/content_settings", "//ios/chrome/browser/content_settings",
"//ios/chrome/browser/history", "//ios/chrome/browser/history",
"//ios/chrome/browser/infobars", "//ios/chrome/browser/infobars",
"//ios/chrome/browser/main",
"//ios/chrome/browser/metrics", "//ios/chrome/browser/metrics",
"//ios/chrome/browser/metrics:metrics_internal", "//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/signin", "//ios/chrome/browser/signin",
......
...@@ -78,6 +78,9 @@ BOOL SimulateTabsBackgrounding(); ...@@ -78,6 +78,9 @@ BOOL SimulateTabsBackgrounding();
// Evicts the tabs associated with the non-current browser mode. // Evicts the tabs associated with the non-current browser mode.
void EvictOtherTabModelTabs(); void EvictOtherTabModelTabs();
// Closes all normal (non-incognito) tabs. Return YES on success.
BOOL CloseAllNormalTabs() WARN_UNUSED_RESULT;
// Closes all incognito tabs. Return YES on success. // Closes all incognito tabs. Return YES on success.
BOOL CloseAllIncognitoTabs() WARN_UNUSED_RESULT; BOOL CloseAllIncognitoTabs() WARN_UNUSED_RESULT;
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#import "ios/chrome/app/main_controller_private.h" #import "ios/chrome/app/main_controller_private.h"
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/metrics/tab_usage_recorder.h" #import "ios/chrome/browser/metrics/tab_usage_recorder.h"
#include "ios/chrome/browser/system_flags.h" #include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_model.h" #import "ios/chrome/browser/tabs/tab_model.h"
...@@ -208,6 +209,17 @@ void EvictOtherTabModelTabs() { ...@@ -208,6 +209,17 @@ void EvictOtherTabModelTabs() {
enabler->SetWebUsageEnabled(true); enabler->SetWebUsageEnabled(true);
} }
BOOL CloseAllNormalTabs() {
MainController* main_controller = GetMainController();
DCHECK(main_controller);
Browser* browser = main_controller.interfaceProvider.mainInterface.browser;
DCHECK(browser);
browser->GetWebStateList()->CloseAllWebStates(
WebStateList::CLOSE_USER_ACTION);
return YES;
}
BOOL CloseAllIncognitoTabs() { BOOL CloseAllIncognitoTabs() {
MainController* main_controller = GetMainController(); MainController* main_controller = GetMainController();
DCHECK(main_controller); DCHECK(main_controller);
......
...@@ -208,6 +208,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -208,6 +208,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// normal after closing all tabs. // normal after closing all tabs.
- (void)closeAllTabsInCurrentMode; - (void)closeAllTabsInCurrentMode;
// Closes all normal (non-incognito) tabs and waits for the UI to complete
// within a timeout, or a GREYAssert is induced.
- (void)closeAllNormalTabs;
// Closes all incognito tabs and waits for the UI to complete within a // Closes all incognito tabs and waits for the UI to complete within a
// timeout, or a GREYAssert is induced. // timeout, or a GREYAssert is induced.
- (void)closeAllIncognitoTabs; - (void)closeAllIncognitoTabs;
......
...@@ -213,6 +213,12 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface) ...@@ -213,6 +213,12 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
} }
- (void)closeAllNormalTabs {
EG_TEST_HELPER_ASSERT_NO_ERROR(
[ChromeEarlGreyAppInterface closeAllNormalTabs]);
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
- (void)closeAllIncognitoTabs { - (void)closeAllIncognitoTabs {
EG_TEST_HELPER_ASSERT_NO_ERROR( EG_TEST_HELPER_ASSERT_NO_ERROR(
[ChromeEarlGreyAppInterface closeAllIncognitoTabs]); [ChromeEarlGreyAppInterface closeAllIncognitoTabs]);
......
...@@ -97,6 +97,10 @@ ...@@ -97,6 +97,10 @@
// normal after closing all tabs. // normal after closing all tabs.
+ (void)closeAllTabsInCurrentMode; + (void)closeAllTabsInCurrentMode;
// Closes all normal (non-incognito) tabs. If not succeed returns an NSError
// indicating why the operation failed, otherwise nil.
+ (NSError*)closeAllNormalTabs;
// Closes all incognito tabs. If not succeed returns an NSError indicating why // Closes all incognito tabs. If not succeed returns an NSError indicating why
// the operation failed, otherwise nil. // the operation failed, otherwise nil.
+ (NSError*)closeAllIncognitoTabs; + (NSError*)closeAllIncognitoTabs;
......
...@@ -165,6 +165,15 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -165,6 +165,15 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
chrome_test_util::CloseAllTabsInCurrentMode(); chrome_test_util::CloseAllTabsInCurrentMode();
} }
+ (NSError*)closeAllNormalTabs {
bool success = chrome_test_util::CloseAllNormalTabs();
if (!success) {
return testing::NSErrorWithLocalizedDescription(
@"Could not close all normal tabs");
}
return nil;
}
+ (NSError*)closeAllIncognitoTabs { + (NSError*)closeAllIncognitoTabs {
bool success = chrome_test_util::CloseAllIncognitoTabs(); bool success = chrome_test_util::CloseAllIncognitoTabs();
if (!success) { if (!success) {
......
...@@ -60,6 +60,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") { ...@@ -60,6 +60,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
"//ios/chrome/browser/ui/safe_mode:eg2_tests", "//ios/chrome/browser/ui/safe_mode:eg2_tests",
"//ios/chrome/browser/ui/settings/autofill:eg2_tests", "//ios/chrome/browser/ui/settings/autofill:eg2_tests",
"//ios/chrome/browser/ui/side_swipe:eg2_tests", "//ios/chrome/browser/ui/side_swipe:eg2_tests",
"//ios/chrome/browser/ui/tab_grid:eg2_tests",
"//ios/chrome/browser/ui/tabs:eg2_tests", "//ios/chrome/browser/ui/tabs:eg2_tests",
"//ios/chrome/browser/ui/toolbar:eg2_tests", "//ios/chrome/browser/ui/toolbar: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