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") { ...@@ -384,6 +384,7 @@ source_set("eg2_tests") {
"http_auth_egtest.mm", "http_auth_egtest.mm",
"js_print_egtest.mm", "js_print_egtest.mm",
"navigation_egtest.mm", "navigation_egtest.mm",
"tab_order_egtest.mm",
"visible_url_egtest.mm", "visible_url_egtest.mm",
] ]
......
...@@ -2,28 +2,22 @@ ...@@ -2,28 +2,22 @@
// 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 <XCTest/XCTest.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_actions.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_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/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" #import "ios/web/public/test/element_selector.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
using chrome_test_util::GetCurrentWebState;
using chrome_test_util::OpenLinkInNewTabButton; using chrome_test_util::OpenLinkInNewTabButton;
using chrome_test_util::WebViewMatcher; using chrome_test_util::WebViewMatcher;
using web::WebViewInWebState;
namespace { namespace {
// This test uses test pages from in //ios/testing/data/http_server_files/. // This test uses test pages from in //ios/testing/data/http_server_files/.
...@@ -59,27 +53,26 @@ const char kLinksTestURL2Text[] = "arrived"; ...@@ -59,27 +53,26 @@ const char kLinksTestURL2Text[] = "arrived";
// Create a tab that will act as the parent tab. // Create a tab that will act as the parent tab.
[ChromeEarlGrey loadURL:URL1]; [ChromeEarlGrey loadURL:URL1];
[ChromeEarlGrey waitForWebStateContainingText:kLinksTestURL1Text]; [ChromeEarlGrey waitForWebStateContainingText:kLinksTestURL1Text];
web::WebState* parentWebState = GetCurrentWebState(); NSString* parentTabID = [ChromeEarlGrey currentTabID];
// Child tab should be inserted after the parent. // Child tab should be inserted after the parent.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(parentWebState)] [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu( performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID], [ElementSelector selectorWithElementID:kLinkSelectorID],
true /* menu should appear */)]; true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:2U]; [ChromeEarlGrey waitForMainTabCount:2U];
web::WebState* childWebState1 = chrome_test_util::GetNextWebState(); NSString* childTab1ID = [ChromeEarlGrey nextTabID];
// New child tab should be inserted AFTER |childWebState1|. // New child tab should be inserted after the tab with |childTab1ID|.
[[EarlGrey selectElementWithMatcher:WebViewInWebState(parentWebState)] [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu( performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID], [ElementSelector selectorWithElementID:kLinkSelectorID],
true /* menu should appear */)]; true /* menu should appear */)];
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:3U]; [ChromeEarlGrey waitForMainTabCount:3U];
GREYAssertEqual(childWebState1, chrome_test_util::GetNextWebState(), GREYAssertEqualObjects(childTab1ID, [ChromeEarlGrey nextTabID],
@"Unexpected next tab"); @"Unexpected next tab");
// Navigate the parent tab away and again to |kLinksTestURL1| to break // Navigate the parent tab away and again to |kLinksTestURL1| to break
...@@ -96,7 +89,7 @@ const char kLinksTestURL2Text[] = "arrived"; ...@@ -96,7 +89,7 @@ const char kLinksTestURL2Text[] = "arrived";
GREYAssertEqual(3U, [ChromeEarlGrey mainTabCount], GREYAssertEqual(3U, [ChromeEarlGrey mainTabCount],
@"Unexpected number of tabs"); @"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()] [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu( performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID], [ElementSelector selectorWithElementID:kLinkSelectorID],
...@@ -104,11 +97,11 @@ const char kLinksTestURL2Text[] = "arrived"; ...@@ -104,11 +97,11 @@ const char kLinksTestURL2Text[] = "arrived";
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:4U]; [ChromeEarlGrey waitForMainTabCount:4U];
web::WebState* childWebState3 = chrome_test_util::GetNextWebState(); NSString* childTab3ID = [ChromeEarlGrey nextTabID];
GREYAssertNotEqual(childWebState1, childWebState3,
@"Unexpected next web state"); 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()] [[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu( performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkSelectorID], [ElementSelector selectorWithElementID:kLinkSelectorID],
...@@ -116,12 +109,12 @@ const char kLinksTestURL2Text[] = "arrived"; ...@@ -116,12 +109,12 @@ const char kLinksTestURL2Text[] = "arrived";
[[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()]
performAction:grey_tap()]; performAction:grey_tap()];
[ChromeEarlGrey waitForMainTabCount:5U]; [ChromeEarlGrey waitForMainTabCount:5U];
GREYAssertEqual(childWebState3, chrome_test_util::GetNextWebState(), GREYAssertEqualObjects(childTab3ID, [ChromeEarlGrey nextTabID],
@"Unexpected next web state"); @"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]; [ChromeEarlGrey selectTabAtIndex:3];
GREYAssertEqual(childWebState1, GetCurrentWebState(), GREYAssertEqualObjects(childTab1ID, [ChromeEarlGrey currentTabID],
@"Unexpected current web state"); @"Unexpected current web state");
// Add a non-owned tab. It should be added at the end and marked as the // Add a non-owned tab. It should be added at the end and marked as the
...@@ -129,13 +122,13 @@ const char kLinksTestURL2Text[] = "arrived"; ...@@ -129,13 +122,13 @@ const char kLinksTestURL2Text[] = "arrived";
// parent web state. // parent web state.
[ChromeEarlGrey openNewTab]; [ChromeEarlGrey openNewTab];
[ChromeEarlGrey waitForMainTabCount:6U]; [ChromeEarlGrey waitForMainTabCount:6U];
GREYAssertEqual(parentWebState, chrome_test_util::GetNextWebState(), GREYAssertEqualObjects(parentTabID, [ChromeEarlGrey nextTabID],
@"Unexpected next web state"); @"Unexpected next web state");
// Verify that |anotherWebState| is at index 5. // Verify that tab with |anotherTabID| is at index 5.
web::WebState* anotherWebState = GetCurrentWebState(); NSString* anotherTabID = [ChromeEarlGrey currentTabID];
[ChromeEarlGrey selectTabAtIndex:5]; [ChromeEarlGrey selectTabAtIndex:5];
GREYAssertEqual(anotherWebState, GetCurrentWebState(), GREYAssertEqualObjects(anotherTabID, [ChromeEarlGrey currentTabID],
@"Unexpected current web state"); @"Unexpected current web state");
} }
......
...@@ -265,6 +265,7 @@ source_set("test_support") { ...@@ -265,6 +265,7 @@ source_set("test_support") {
"//ios/chrome/browser/ui/toolbar/keyboard_assist", "//ios/chrome/browser/ui/toolbar/keyboard_assist",
"//ios/chrome/browser/ui/toolbar/public", "//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/testing:verify_custom_webkit", "//ios/testing:verify_custom_webkit",
"//ios/testing/earl_grey:earl_grey_support", "//ios/testing/earl_grey:earl_grey_support",
...@@ -373,6 +374,7 @@ source_set("eg_app_support+eg2") { ...@@ -373,6 +374,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/toolbar/keyboard_assist", "//ios/chrome/browser/ui/toolbar/keyboard_assist",
"//ios/chrome/browser/ui/toolbar/public", "//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/testing:nserror_support", "//ios/testing:nserror_support",
"//ios/testing:verify_custom_webkit", "//ios/testing:verify_custom_webkit",
......
...@@ -246,6 +246,12 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -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. // Returns the tab title of the next tab. Assumes that next tab exists.
- (NSString*)nextTabTitle; - (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) #pragma mark - SignIn Utilities (EG2)
// Signs the user out, clears the known accounts entirely and checks whether the // 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) ...@@ -255,6 +255,14 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface nextTabTitle]; return [ChromeEarlGreyAppInterface nextTabTitle];
} }
- (NSString*)currentTabID {
return [ChromeEarlGreyAppInterface currentTabID];
}
- (NSString*)nextTabID {
return [ChromeEarlGreyAppInterface nextTabID];
}
#pragma mark - Cookie Utilities (EG2) #pragma mark - Cookie Utilities (EG2)
- (NSDictionary*)cookies { - (NSDictionary*)cookies {
......
...@@ -112,6 +112,12 @@ ...@@ -112,6 +112,12 @@
// Returns the title of the next tab. Assumes that there is a next tab. // Returns the title of the next tab. Assumes that there is a next tab.
+ (NSString*)nextTabTitle; + (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) #pragma mark - WebState Utilities (EG2)
// Attempts to tap the element with |element_id| within window.frames[0] of the // Attempts to tap the element with |element_id| within window.frames[0] of the
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "ios/chrome/browser/ntp/features.h" #import "ios/chrome/browser/ntp/features.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h" #import "ios/chrome/browser/ui/settings/autofill/features.h"
#import "ios/chrome/browser/ui/ui_feature_flags.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/bookmarks_test_util.h"
#import "ios/chrome/test/app/chrome_test_util.h" #import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/history_test_util.h" #import "ios/chrome/test/app/history_test_util.h"
...@@ -180,6 +181,16 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -180,6 +181,16 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
[BrowserCommandDispatcherForMainBVC() goForward]; [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) #pragma mark - WebState Utilities (EG2)
+ (NSError*)tapWebStateElementInIFrameWithID:(NSString*)elementID { + (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