Commit e99f029d authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

[EG2] Convert tab_strip_egtest to EarlGrey2

Bug: 987646
Change-Id: Ic834aac16e4e78a3da0983d4ec2a2f719315e8db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1860107Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706063}
parent 0ff942f5
......@@ -112,6 +112,7 @@ source_set("unit_tests") {
}
source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
......@@ -123,8 +124,28 @@ source_set("eg_tests") {
"//ios/chrome/browser",
"//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",
"//ui/base",
]
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 = [
"tab_strip_egtest.mm",
]
deps = [
"//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,30 +2,17 @@
// 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>
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_title_util.h"
#import "ios/chrome/browser/ui/tabs/tab_view.h"
#include "ios/chrome/grit/ios_strings.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_ui.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#include "ui/base/l10n/l10n_util.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Matcher for the tab title for a given |web_state|.
id<GREYMatcher> TabTitleMatcher(web::WebState* web_state) {
return grey_text(tab_util::GetTabTitle(web_state));
}
} // namespace
// Tests for the tab strip shown on iPad.
@interface TabStripTestCase : ChromeTestCase
@end
......@@ -53,14 +40,13 @@ id<GREYMatcher> TabTitleMatcher(web::WebState* web_state) {
GREYAssertTrue([ChromeEarlGrey mainTabCount] > 1,
[ChromeEarlGrey mainTabCount] ? @"Only one tab open."
: @"No more tabs.");
web::WebState* nextWebState = chrome_test_util::GetNextWebState();
NSString* nextTabTitle = [ChromeEarlGrey nextTabTitle];
[[EarlGrey selectElementWithMatcher:TabTitleMatcher(nextWebState)]
[[EarlGrey selectElementWithMatcher:grey_text(nextTabTitle)]
performAction:grey_tap()];
web::WebState* newCurrentWebState = chrome_test_util::GetCurrentWebState();
GREYAssertTrue(newCurrentWebState == nextWebState,
@"The selected tab did not change to the next tab.");
GREYAssertEqualObjects([ChromeEarlGrey currentTabTitle], nextTabTitle,
@"The selected tab did not change to the next tab.");
}
}
......
......@@ -30,6 +30,12 @@ web::WebState* GetCurrentWebState();
// Gets next WebState and returns nullptr if less than two tabs are open.
web::WebState* GetNextWebState();
// Gets the current webState title. Assumes that the current webState exists.
NSString* GetCurrentTabTitle();
// Gets the next webState title. Assumes that the next webState exists.
NSString* GetNextTabTitle();
// Gets the WebState with the given index in the current mode (incognito or
// normal). Returns nullptr if less than |index| + 1 tabs are open.
web::WebState* GetWebStateAtIndexInCurrentMode(int index);
......
......@@ -12,6 +12,7 @@
#import "ios/chrome/browser/metrics/tab_usage_recorder.h"
#include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/tabs/tab_title_util.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/tab_grid/tab_switcher.h"
......@@ -109,6 +110,14 @@ web::WebState* GetWebStateAtIndexInCurrentMode(int index) {
return web_state_list->GetWebStateAt(index);
}
NSString* GetCurrentTabTitle() {
return tab_util::GetTabTitle(GetCurrentWebState());
}
NSString* GetNextTabTitle() {
return tab_util::GetTabTitle(GetNextWebState());
}
void CloseCurrentTab() {
WebStateList* web_state_list = GetCurrentWebStateList();
if (!web_state_list ||
......
......@@ -240,6 +240,12 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// exception if operation not succeeded.
- (void)resetTabUsageRecorder;
// Returns the tab title of the current tab.
- (NSString*)currentTabTitle;
// Returns the tab title of the next tab. Assumes that next tab exists.
- (NSString*)nextTabTitle;
#pragma mark - SignIn Utilities (EG2)
// Signs the user out, clears the known accounts entirely and checks whether the
......
......@@ -247,6 +247,14 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
EG_TEST_HELPER_ASSERT_TRUE(matchedElement, errorDescription);
}
- (NSString*)currentTabTitle {
return [ChromeEarlGreyAppInterface currentTabTitle];
}
- (NSString*)nextTabTitle {
return [ChromeEarlGreyAppInterface nextTabTitle];
}
#pragma mark - Cookie Utilities (EG2)
- (NSDictionary*)cookies {
......
......@@ -106,6 +106,12 @@
// Navigates forward to the next page without waiting for the page to load.
+ (void)startGoingForward;
// Returns the title of the current selected tab.
+ (NSString*)currentTabTitle;
// Returns the title of the next tab. Assumes that there is a next tab.
+ (NSString*)nextTabTitle;
#pragma mark - WebState Utilities (EG2)
// Attempts to tap the element with |element_id| within window.frames[0] of the
......
......@@ -147,6 +147,14 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
chrome_test_util::OpenNewIncognitoTab();
}
+ (NSString*)currentTabTitle {
return chrome_test_util::GetCurrentTabTitle();
}
+ (NSString*)nextTabTitle {
return chrome_test_util::GetNextTabTitle();
}
+ (void)closeAllTabsInCurrentMode {
chrome_test_util::CloseAllTabsInCurrentMode();
}
......
......@@ -48,6 +48,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
"//ios/chrome/browser/ui/page_info:eg2_tests",
"//ios/chrome/browser/ui/sad_tab:eg2_tests",
"//ios/chrome/browser/ui/settings/autofill:eg2_tests",
"//ios/chrome/browser/ui/tabs: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