| Index: ios/chrome/browser/ui/tabs/tab_strip_egtest.mm
|
| diff --git a/ios/chrome/browser/ui/tabs/tab_strip_egtest.mm b/ios/chrome/browser/ui/tabs/tab_strip_egtest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e6cb58c436c3d4caa60c052e8bce2ddc3ee044ae
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/ui/tabs/tab_strip_egtest.mm
|
| @@ -0,0 +1,104 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// 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/experimental_flags.h"
|
| +#import "ios/chrome/browser/ui/tabs/tab_view.h"
|
| +#import "ios/chrome/browser/ui/uikit_ui_util.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_ui.h"
|
| +#import "ios/chrome/test/earl_grey/chrome_test_case.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +
|
| +// Tests for the tab strip shown on iPad.
|
| +@interface TabStripTestCase : ChromeTestCase
|
| +@end
|
| +
|
| +@implementation TabStripTestCase
|
| +
|
| +// Test switching tabs using the tab strip.
|
| +- (void)testTabStripSwitchTabs {
|
| + // Only iPad has a tab strip.
|
| + if (IsCompact()) {
|
| + return;
|
| + }
|
| +
|
| + // TODO(crbug.com/238112): Make this test also handle the 'collapsed' tab
|
| + // case.
|
| + const int kNumberOfTabs = 3;
|
| + for (int i = 0; i < kNumberOfTabs - 1; i++) {
|
| + [ChromeEarlGreyUI openNewTab];
|
| + }
|
| +
|
| + // Note that the tab ordering wraps. E.g. if A, B, and C are open,
|
| + // and C is the current tab, the 'next' tab is 'A'.
|
| + for (int i = 0; i < kNumberOfTabs + 1; i++) {
|
| + GREYAssertTrue(chrome_test_util::GetMainTabCount() > 1,
|
| + chrome_test_util::GetMainTabCount() ? @"Only one tab open."
|
| + : @"No more tabs.");
|
| + Tab* nextTab = chrome_test_util::GetNextTab();
|
| + TabView* tabView = chrome_test_util::GetTabViewForTab(nextTab);
|
| +
|
| + [[EarlGrey
|
| + selectElementWithMatcher:grey_allOf(
|
| + grey_ancestor(grey_equalTo(tabView)),
|
| + grey_accessibilityID(@"Favicon"), nil)]
|
| + performAction:grey_tap()];
|
| +
|
| + Tab* newCurrentTab = chrome_test_util::GetCurrentTab();
|
| + GREYAssertTrue(newCurrentTab == nextTab,
|
| + @"The selected tab did not change to the next tab.");
|
| + }
|
| +}
|
| +
|
| +// Tests switching the mode using the mode toggle.
|
| +- (void)testTabStripSwitchModes {
|
| + // The toggle button only exists on iPad, and when the Tablet Tab Switcher
|
| + // isn't enabled.
|
| + if (IsCompact() || experimental_flags::IsTabSwitcherEnabled()) {
|
| + return;
|
| + }
|
| +
|
| + // Open two normal tabs.
|
| + [ChromeEarlGreyUI openNewTab];
|
| + [ChromeEarlGreyUI openNewTab];
|
| +
|
| + // Open two incognito tabs.
|
| + [ChromeEarlGreyUI openNewIncognitoTab];
|
| + [ChromeEarlGreyUI openNewIncognitoTab];
|
| +
|
| + // Switch back to normal mode.
|
| + [[EarlGrey selectElementWithMatcher:
|
| + grey_accessibilityLabel(l10n_util::GetNSString(
|
| + IDS_IOS_SWITCH_BROWSER_MODE_LEAVE_INCOGNITO))]
|
| + performAction:grey_tap()];
|
| + GREYAssertFalse(chrome_test_util::IsIncognitoMode(),
|
| + @"Current tab is incognito.");
|
| +
|
| + // Switch back to incognito mode.
|
| + [[EarlGrey selectElementWithMatcher:
|
| + grey_accessibilityLabel(l10n_util::GetNSString(
|
| + IDS_IOS_SWITCH_BROWSER_MODE_ENTER_INCOGNITO))]
|
| + performAction:grey_tap()];
|
| + GREYAssertTrue(chrome_test_util::IsIncognitoMode(),
|
| + @"Current tab is not incognito.");
|
| +
|
| + // Close both incognito tabs.
|
| + chrome_test_util::CloseAllTabsInCurrentMode();
|
| +
|
| + // We should be in normal mode.
|
| + GREYAssertFalse(chrome_test_util::IsIncognitoMode(),
|
| + @"Current tab is incognito.");
|
| +
|
| + // There should be no incognito switch.
|
| + [[EarlGrey selectElementWithMatcher:
|
| + grey_accessibilityID(l10n_util::GetNSString(
|
| + IDS_IOS_SWITCH_BROWSER_MODE_ENTER_INCOGNITO))]
|
| + assertWithMatcher:grey_notVisible()];
|
| +}
|
| +
|
| +@end
|
|
|