Commit 27e89d02 authored by Mohammad Refaat's avatar Mohammad Refaat Committed by Commit Bot

[EG2] Convert tab_order_egtest to EarlGrey2


Bug: 987646
Change-Id: I218a1e8857b1a22554e6e6435e0a42699938c5f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1862728
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706246}
parent 37c42ef4
......@@ -384,6 +384,7 @@ source_set("eg2_tests") {
"http_auth_egtest.mm",
"js_print_egtest.mm",
"navigation_egtest.mm",
"tab_order_egtest.mm",
"visible_url_egtest.mm",
]
......
......@@ -2,28 +2,22 @@
// 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/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/web/public/test/earl_grey/web_view_matchers.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#import "ios/web/public/test/element_selector.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using chrome_test_util::GetCurrentWebState;
using chrome_test_util::OpenLinkInNewTabButton;
using chrome_test_util::WebViewMatcher;
using web::WebViewInWebState;
namespace {
// This test uses test pages from in //ios/testing/data/http_server_files/.
......@@ -59,28 +53,27 @@ const char kLinksTestURL2Text[] = "arrived";
// Create a tab that will act as the parent tab.
[ChromeEarlGrey loadURL:URL1];
[ChromeEarlGrey waitForWebStateContainingText:kLinksTestURL1Text];
web::WebState* parentWebState = GetCurrentWebState();
NSString* parentTabID = [ChromeEarlGrey currentTabID];
// Child tab should be inserted after the parent.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(parentWebState)]
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID],
true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:2U];
web::WebState* childWebState1 = chrome_test_util::GetNextWebState();
NSString* childTab1ID = [ChromeEarlGrey nextTabID];
// New child tab should be inserted AFTER |childWebState1|.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(parentWebState)]
// New child tab should be inserted after the tab with |childTab1ID|.
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID],
true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:3U];
GREYAssertEqual(childWebState1, chrome_test_util::GetNextWebState(),
@"Unexpected next tab");
GREYAssertEqualObjects(childTab1ID, [ChromeEarlGrey nextTabID],
@"Unexpected next tab");
// Navigate the parent tab away and again to |kLinksTestURL1| to break
// grouping with the current child tabs. Total number of tabs should not
......@@ -96,7 +89,7 @@ const char kLinksTestURL2Text[] = "arrived";
GREYAssertEqual(3U, [ChromeEarlGrey mainTabCount],
@"Unexpected number of tabs");
// New child WebState should be inserted BEFORE |childWebState1|.
// New child tab should be inserted before the tab with |childTab1ID|.
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID],
......@@ -104,11 +97,11 @@ const char kLinksTestURL2Text[] = "arrived";
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:4U];
web::WebState* childWebState3 = chrome_test_util::GetNextWebState();
GREYAssertNotEqual(childWebState1, childWebState3,
@"Unexpected next web state");
NSString* childTab3ID = [ChromeEarlGrey nextTabID];
GREYAssertNotEqualObjects(childTab1ID, childTab3ID, @"Unexpected next tab");
// New child WebState should be inserted AFTER |childWebState3|.
// New child tab should be inserted after the tab with |childTab3ID|.
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID],
......@@ -116,27 +109,27 @@ const char kLinksTestURL2Text[] = "arrived";
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:5U];
GREYAssertEqual(childWebState3, chrome_test_util::GetNextWebState(),
@"Unexpected next web state");
GREYAssertEqualObjects(childTab3ID, [ChromeEarlGrey nextTabID],
@"Unexpected next web state");
// Verify that |childWebState1| is now at index 3.
// Verify that tab with |childTab1ID| is now at index 3.
[ChromeEarlGrey selectTabAtIndex:3];
GREYAssertEqual(childWebState1, GetCurrentWebState(),
@"Unexpected current web state");
GREYAssertEqualObjects(childTab1ID, [ChromeEarlGrey currentTabID],
@"Unexpected current web state");
// Add a non-owned tab. It should be added at the end and marked as the
// current web state. Next web state should wrap back to index 0, the original
// parent web state.
[ChromeEarlGrey openNewTab];
[ChromeEarlGrey waitForMainTabCount:6U];
GREYAssertEqual(parentWebState, chrome_test_util::GetNextWebState(),
@"Unexpected next web state");
GREYAssertEqualObjects(parentTabID, [ChromeEarlGrey nextTabID],
@"Unexpected next web state");
// Verify that |anotherWebState| is at index 5.
web::WebState* anotherWebState = GetCurrentWebState();
// Verify that tab with |anotherTabID| is at index 5.
NSString* anotherTabID = [ChromeEarlGrey currentTabID];
[ChromeEarlGrey selectTabAtIndex:5];
GREYAssertEqual(anotherWebState, GetCurrentWebState(),
@"Unexpected current web state");
GREYAssertEqualObjects(anotherTabID, [ChromeEarlGrey currentTabID],
@"Unexpected current web state");
}
@end
......@@ -265,6 +265,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/toolbar/keyboard_assist",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/test/app:test_support",
"//ios/testing:verify_custom_webkit",
"//ios/testing/earl_grey:earl_grey_support",
......@@ -373,6 +374,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/toolbar/keyboard_assist",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/test/app:test_support",
"//ios/testing:nserror_support",
"//ios/testing:verify_custom_webkit",
......
......@@ -246,6 +246,12 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// Returns the tab title of the next tab. Assumes that next tab exists.
- (NSString*)nextTabTitle;
// Returns a unique identifier for the current Tab.
- (NSString*)currentTabID;
// Returns a unique identifier for the next Tab.
- (NSString*)nextTabID;
#pragma mark - SignIn Utilities (EG2)
// Signs the user out, clears the known accounts entirely and checks whether the
......
......@@ -255,6 +255,14 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface nextTabTitle];
}
- (NSString*)currentTabID {
return [ChromeEarlGreyAppInterface currentTabID];
}
- (NSString*)nextTabID {
return [ChromeEarlGreyAppInterface nextTabID];
}
#pragma mark - Cookie Utilities (EG2)
- (NSDictionary*)cookies {
......
......@@ -112,6 +112,12 @@
// Returns the title of the next tab. Assumes that there is a next tab.
+ (NSString*)nextTabTitle;
// Returns a unique identifier for the current Tab.
+ (NSString*)currentTabID;
// Returns a unique identifier for the next Tab.
+ (NSString*)nextTabID;
#pragma mark - WebState Utilities (EG2)
// Attempts to tap the element with |element_id| within window.frames[0] of the
......
......@@ -15,6 +15,7 @@
#import "ios/chrome/browser/ntp/features.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/web/tab_id_tab_helper.h"
#import "ios/chrome/test/app/bookmarks_test_util.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/history_test_util.h"
......@@ -180,6 +181,16 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
[BrowserCommandDispatcherForMainBVC() goForward];
}
+ (NSString*)currentTabID {
web::WebState* web_state = chrome_test_util::GetCurrentWebState();
return TabIdTabHelper::FromWebState(web_state)->tab_id();
}
+ (NSString*)nextTabID {
web::WebState* web_state = chrome_test_util::GetNextWebState();
return TabIdTabHelper::FromWebState(web_state)->tab_id();
}
#pragma mark - WebState Utilities (EG2)
+ (NSError*)tapWebStateElementInIFrameWithID:(NSString*)elementID {
......
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