Skip to content

Commit

Permalink
[iOS] Add eg2 test for 'new window' option to history context menu.
Browse files Browse the repository at this point in the history
Bug: 1072370
Change-Id: I2051d3905f87f499d153fd1ed1d495ac013b4c4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2247018
Reviewed-by: Mark Cogan <marq@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#783591}
  • Loading branch information
Nazerke authored and Commit Bot committed Jun 29, 2020
1 parent 309daa6 commit 4da4ba8
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ios/chrome/browser/ui/history/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/settings/cells:clear_browsing_data_constants",
"//ios/chrome/browser/ui/table_view:feature_flags",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/common",
"//ios/chrome/test/earl_grey:test_support",
"//ios/testing/earl_grey:earl_grey_support",
Expand Down Expand Up @@ -183,6 +184,7 @@ source_set("eg2_tests") {
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/settings/cells:clear_browsing_data_constants",
"//ios/chrome/browser/ui/table_view:feature_flags",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/common",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
Expand Down
31 changes: 31 additions & 0 deletions ios/chrome/browser/ui/history/history_ui_egtest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/browser/ui/settings/cells/clear_browsing_data_constants.h"
#import "ios/chrome/browser/ui/table_view/feature_flags.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#include "ios/chrome/common/string_util.h"
#include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
Expand All @@ -33,6 +34,7 @@
using chrome_test_util::HistoryEntry;
using chrome_test_util::NavigationBarDoneButton;
using chrome_test_util::OpenLinkInNewTabButton;
using chrome_test_util::OpenLinkInNewWindowButton;

namespace {
char kURL1[] = "http://firstURL";
Expand Down Expand Up @@ -387,6 +389,35 @@ - (void)testContextMenuOpenInNewTab {
[ChromeEarlGrey waitForMainTabCount:2];
}

// Tests display and selection of 'Open in New Window' in a context menu on a
// history entry.
- (void)testContextMenuOpenInNewWindow {
if (!IsMultiwindowSupported())
return;

[self loadTestURLs];
[self openHistoryPanel];

[ChromeEarlGrey waitForBrowserCount:1];

// Long press on the history element.
[[EarlGrey
selectElementWithMatcher:HistoryEntry(_URL1.GetOrigin().spec(), kTitle1)]
performAction:grey_longPress()];

// Select "Open in New Window" and confirm that new tab is opened with
// selected URL in the new window.
[[EarlGrey selectElementWithMatcher:OpenLinkInNewWindowButton()]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
_URL1.GetContent())]
assertWithMatcher:grey_notNil()];
[ChromeEarlGrey waitForBrowserCount:2];

[ChromeEarlGrey closeCurrentTab];
[ChromeEarlGrey waitForBrowserCount:1];
}

// Tests display and selection of 'Open in New Incognito Tab' in a context menu
// on a history entry.
- (void)testContextMenuOpenInNewIncognitoTab {
Expand Down
3 changes: 3 additions & 0 deletions ios/chrome/test/app/chrome_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ SceneState* GetForegroundActiveScene();
// Returns the foreground, active scene controller.
SceneController* GetForegroundActiveSceneController();

// Returns the number of regular Browsers for the default profile.
NSUInteger RegularBrowserCount();

// Returns the current, non-incognito ChromeBrowserState.
ChromeBrowserState* GetOriginalBrowserState();

Expand Down
9 changes: 9 additions & 0 deletions ios/chrome/test/app/chrome_test_util.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state_manager.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/main/browser_list.h"
#import "ios/chrome/browser/main/browser_list_factory.h"
#import "ios/chrome/browser/metrics/previous_session_info.h"
#import "ios/chrome/browser/metrics/previous_session_info_private.h"
#import "ios/chrome/browser/ui/browser_view/browser_view_controller.h"
Expand Down Expand Up @@ -91,6 +93,13 @@ - (dispatch_queue_t)queue {
.controller;
}

NSUInteger RegularBrowserCount() {
return static_cast<NSUInteger>(
BrowserListFactory::GetForBrowserState(GetOriginalBrowserState())
->AllRegularBrowsers()
.size());
}

ChromeBrowserState* GetOriginalBrowserState() {
return GetBrowserState(false);
}
Expand Down
7 changes: 7 additions & 0 deletions ios/chrome/test/earl_grey/chrome_earl_grey.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// GREYAssert is induced.
- (void)waitForIncognitoTabCount:(NSUInteger)count;

// Waits for there to be |count| number of browsers within a timeout,
// or a GREYAssert is induced.
- (void)waitForBrowserCount:(NSUInteger)count;

// Loads |URL| as if it was opened from an external application.
- (void)openURLFromExternalApp:(const GURL&)URL;

Expand Down Expand Up @@ -294,6 +298,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// Returns the number of incognito tabs.
- (NSUInteger)incognitoTabCount WARN_UNUSED_RESULT;

// Returns the number of browsers.
- (NSUInteger)browserCount WARN_UNUSED_RESULT;

// Returns the index of active tab in normal (non-incognito) mode.
- (NSUInteger)indexOfActiveNormalTab;

Expand Down
28 changes: 28 additions & 0 deletions ios/chrome/test/earl_grey/chrome_earl_grey.mm
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ - (NSUInteger)incognitoTabCount {
return [ChromeEarlGreyAppInterface incognitoTabCount];
}

- (NSUInteger)browserCount {
return [ChromeEarlGreyAppInterface browserCount];
}

- (NSUInteger)evictedMainTabCount {
return [ChromeEarlGreyAppInterface evictedMainTabCount];
}
Expand Down Expand Up @@ -509,6 +513,30 @@ - (void)waitForIncognitoTabCount:(NSUInteger)count {
EG_TEST_HELPER_ASSERT_TRUE(tabCountEqual, errorString);
}

- (void)waitForBrowserCount:(NSUInteger)count {
__block NSUInteger actualCount = [ChromeEarlGreyAppInterface browserCount];
NSString* conditionName = [NSString
stringWithFormat:@"Waiting for window count to become %" PRIuNS, count];

// Allow the UI to become idle, in case any tabs are being opened or closed.
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];

GREYCondition* browserCountCheck = [GREYCondition
conditionWithName:conditionName
block:^{
actualCount = [ChromeEarlGreyAppInterface browserCount];
return actualCount == count;
}];
bool browserCountEqual =
[browserCountCheck waitWithTimeout:kWaitForUIElementTimeout];

NSString* errorString = [NSString
stringWithFormat:@"Failed waiting for window count to become %" PRIuNS
"; actual count: %" PRIuNS,
count, actualCount];
EG_TEST_HELPER_ASSERT_TRUE(browserCountEqual, errorString);
}

- (NSUInteger)indexOfActiveNormalTab {
return [ChromeEarlGreyAppInterface indexOfActiveNormalTab];
}
Expand Down
3 changes: 3 additions & 0 deletions ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
// Returns the number of open incognito tabs.
+ (NSUInteger)incognitoTabCount WARN_UNUSED_RESULT;

// Returns the number of open browsers.
+ (NSUInteger)browserCount WARN_UNUSED_RESULT;

// Simulates a backgrounding.
// If not succeed returns an NSError indicating why the
// operation failed, otherwise nil.
Expand Down
4 changes: 4 additions & 0 deletions ios/chrome/test/earl_grey/chrome_earl_grey_app_interface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ + (NSUInteger)incognitoTabCount {
return chrome_test_util::GetIncognitoTabCount();
}

+ (NSUInteger)browserCount {
return chrome_test_util::RegularBrowserCount();
}

+ (NSUInteger)evictedMainTabCount {
return chrome_test_util::GetEvictedMainTabCount();
}
Expand Down
4 changes: 4 additions & 0 deletions ios/chrome/test/earl_grey/chrome_matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ id<GREYMatcher> SyncSwitchCell(NSString* accessibility_label,
// a link.
id<GREYMatcher> OpenLinkInNewTabButton();

// Matcher for the Open in New Window option in the context menu when long
// pressing a link.
id<GREYMatcher> OpenLinkInNewWindowButton();

// Matcher for the done button on the navigation bar.
id<GREYMatcher> NavigationBarDoneButton();

Expand Down
4 changes: 4 additions & 0 deletions ios/chrome/test/earl_grey/chrome_matchers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@
return [ChromeMatchersAppInterface openLinkInNewTabButton];
}

id<GREYMatcher> OpenLinkInNewWindowButton() {
return [ChromeMatchersAppInterface openLinkInNewWindowButton];
}

id<GREYMatcher> NavigationBarDoneButton() {
return [ChromeMatchersAppInterface navigationBarDoneButton];
}
Expand Down
4 changes: 4 additions & 0 deletions ios/chrome/test/earl_grey/chrome_matchers_app_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
// a link.
+ (id<GREYMatcher>)openLinkInNewTabButton;

// Matcher for the Open in New Window option in the context menu when long
// pressing a link.
+ (id<GREYMatcher>)openLinkInNewWindowButton;

// Matcher for the done button on the navigation bar.
+ (id<GREYMatcher>)navigationBarDoneButton;

Expand Down
5 changes: 5 additions & 0 deletions ios/chrome/test/earl_grey/chrome_matchers_app_interface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ @implementation ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)];
}

+ (id<GREYMatcher>)openLinkInNewWindowButton {
return [ChromeMatchersAppInterface
buttonWithAccessibilityLabelID:(IDS_IOS_CONTENT_CONTEXT_OPENINNEWWINDOW)];
}

+ (id<GREYMatcher>)navigationBarDoneButton {
return grey_allOf(
[ChromeMatchersAppInterface
Expand Down
1 change: 1 addition & 0 deletions ios/chrome/test/earl_grey/chrome_test_case.mm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
NSArray* multitaskingTests = @[
// Integration tests
@"testContextMenuOpenInNewTab", // ContextMenuTestCase
@"testContextMenuOpenInNewWindow", // ContextMenuTestCase
@"testSwitchToMain", // CookiesTestCase
@"testSwitchToIncognito", // CookiesTestCase
@"testFindDefaultFormAssistControls", // FormInputTestCase
Expand Down

0 comments on commit 4da4ba8

Please sign in to comment.