Commit 2d3ce148 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] EG test that tests clear browsing data from tabgrid

Test covers the crash in bug 871769. That was fixed with CommandDispatcher forwarding BrowsingDataCommands protocol methods. ApplicationCommands conforms to BrowsingDataCommands, but tabgrid coordinator needs to explicitly dispatch both.

Change-Id: I484f37864f2620eaa85c44e3a20c6d4aebd2f072
Reviewed-on: https://chromium-review.googlesource.com/1171796
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583389}
parent f2b6eadf
...@@ -133,6 +133,7 @@ source_set("egtest_support") { ...@@ -133,6 +133,7 @@ source_set("egtest_support") {
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/ui:ui_util", "//ios/chrome/browser/ui:ui_util",
"//ios/chrome/browser/ui/ntp/recent_tabs",
"//ios/chrome/browser/ui/tools_menu/public", "//ios/chrome/browser/ui/tools_menu/public",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
...@@ -150,7 +151,9 @@ source_set("eg_tests") { ...@@ -150,7 +151,9 @@ source_set("eg_tests") {
deps = [ deps = [
":egtest_support", ":egtest_support",
"//ios/chrome/browser/ui/tab_grid:tab_grid_ui",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
"//ios/web/public/test/http_server",
] ]
libs = [ "XCTest.framework" ] libs = [ "XCTest.framework" ]
} }
......
...@@ -16,6 +16,7 @@ extern NSString* const kTabGridCloseAllButtonIdentifier; ...@@ -16,6 +16,7 @@ extern NSString* const kTabGridCloseAllButtonIdentifier;
extern NSString* const kTabGridUndoCloseAllButtonIdentifier; extern NSString* const kTabGridUndoCloseAllButtonIdentifier;
extern NSString* const kTabGridIncognitoTabsEmptyStateIdentifier; extern NSString* const kTabGridIncognitoTabsEmptyStateIdentifier;
extern NSString* const kTabGridRegularTabsEmptyStateIdentifier; extern NSString* const kTabGridRegularTabsEmptyStateIdentifier;
extern NSString* const kTabGridScrollViewIdentifier;
// All kxxxColor constants are RGB values stored in a Hex integer. These will be // All kxxxColor constants are RGB values stored in a Hex integer. These will be
// converted into UIColors using the UIColorFromRGB() function, from // converted into UIColors using the UIColorFromRGB() function, from
......
...@@ -24,6 +24,7 @@ NSString* const kTabGridIncognitoTabsEmptyStateIdentifier = ...@@ -24,6 +24,7 @@ NSString* const kTabGridIncognitoTabsEmptyStateIdentifier =
@"TabGridIncognitoTabsEmptyStateIdentifier"; @"TabGridIncognitoTabsEmptyStateIdentifier";
NSString* const kTabGridRegularTabsEmptyStateIdentifier = NSString* const kTabGridRegularTabsEmptyStateIdentifier =
@"TabGridRegularTabsEmptyStateIdentifier"; @"TabGridRegularTabsEmptyStateIdentifier";
NSString* const kTabGridScrollViewIdentifier = @"kTabGridScrollViewIdentifier";
// The color of the text buttons in the toolbars. // The color of the text buttons in the toolbars.
const int kTabGridToolbarTextButtonColor = 0xFFFFFF; const int kTabGridToolbarTextButtonColor = 0xFFFFFF;
......
...@@ -2,20 +2,61 @@ ...@@ -2,20 +2,61 @@
// 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.
#include "base/strings/stringprintf.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_constants.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_egtest_util.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_egtest_util.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_earl_grey_ui.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/http_server/http_server.h"
#import "ios/web/public/test/http_server/http_server_util.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
@interface TabGridTestCase : ChromeTestCase namespace {
char kURL1[] = "http://firstURL";
char kURL2[] = "http://secondURL";
char kURL3[] = "http://thirdURL";
char kTitle1[] = "Page 1";
char kTitle2[] = "Page 2";
char kResponse1[] = "Test Page 1 content";
char kResponse2[] = "Test Page 2 content";
char kResponse3[] = "Test Page 3 content";
} // namespace
@interface TabGridTestCase : ChromeTestCase {
GURL _URL1;
GURL _URL2;
GURL _URL3;
}
@end @end
@implementation TabGridTestCase @implementation TabGridTestCase
// Set up called once for the class.
+ (void)setUp {
[super setUp];
std::map<GURL, std::string> responses;
const char kPageFormat[] = "<head><title>%s</title></head><body>%s</body>";
responses[web::test::HttpServer::MakeUrl(kURL1)] =
base::StringPrintf(kPageFormat, kTitle1, kResponse1);
responses[web::test::HttpServer::MakeUrl(kURL2)] =
base::StringPrintf(kPageFormat, kTitle2, kResponse2);
// Page 3 does not have <title> tag, so URL will be its title.
responses[web::test::HttpServer::MakeUrl(kURL3)] = kResponse3;
web::test::SetUpSimpleHttpServer(responses);
}
- (void)setUp {
[super setUp];
_URL1 = web::test::HttpServer::MakeUrl(kURL1);
_URL2 = web::test::HttpServer::MakeUrl(kURL2);
_URL3 = web::test::HttpServer::MakeUrl(kURL3);
}
// Tests entering and leaving the tab grid. // Tests entering and leaving the tab grid.
- (void)testEnteringAndLeavingTabGrid { - (void)testEnteringAndLeavingTabGrid {
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
...@@ -98,4 +139,37 @@ ...@@ -98,4 +139,37 @@
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
} }
- (void)loadTestURLs {
[ChromeEarlGrey loadURL:_URL1];
[ChromeEarlGrey waitForWebViewContainingText:kResponse1];
[ChromeEarlGrey loadURL:_URL2];
[ChromeEarlGrey waitForWebViewContainingText:kResponse2];
[ChromeEarlGrey loadURL:_URL3];
[ChromeEarlGrey waitForWebViewContainingText:kResponse3];
}
// Test that Clear Browsing Data can be successfully done from tab grid.
- (void)testClearBrowsingData {
// Load history
[self loadTestURLs];
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShowTabsButton()]
performAction:grey_tap()];
// Swipe over to Recent Tabs
[[EarlGrey selectElementWithMatcher:grey_accessibilityID(
kTabGridScrollViewIdentifier)]
performAction:[GREYActions
actionForSwipeFastInDirection:kGREYDirectionLeft]];
// Tap on "Show History"
// Undo is available after close all action.
[[EarlGrey
selectElementWithMatcher:chrome_test_util::TabGridSelectShowHistoryCell()]
performAction:grey_tap()];
[ChromeEarlGreyUI openAndClearBrowsingDataFromHistory];
[ChromeEarlGreyUI assertHistoryHasNoEntries];
}
@end @end
...@@ -23,6 +23,9 @@ id<GREYMatcher> TabGridCloseAllButton(); ...@@ -23,6 +23,9 @@ id<GREYMatcher> TabGridCloseAllButton();
// in the tab grid. // in the tab grid.
id<GREYMatcher> TabGridUndoCloseAllButton(); id<GREYMatcher> TabGridUndoCloseAllButton();
// Returns the GREYMatcher for the cell that opens History in Recent Tabs.
id<GREYMatcher> TabGridSelectShowHistoryCell();
// Returns the GREYMatcher for the regular tabs empty state view. // Returns the GREYMatcher for the regular tabs empty state view.
id<GREYMatcher> TabGridRegularTabsEmptyStateView(); id<GREYMatcher> TabGridRegularTabsEmptyStateView();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import <EarlGrey/EarlGrey.h> #import <EarlGrey/EarlGrey.h>
#import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_constants.h"
#import "ios/chrome/browser/ui/tab_grid/grid/grid_constants.h" #import "ios/chrome/browser/ui/tab_grid/grid/grid_constants.h"
#import "ios/chrome/browser/ui/tab_grid/tab_grid_constants.h" #import "ios/chrome/browser/ui/tab_grid/tab_grid_constants.h"
#import "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h" #import "ios/chrome/browser/ui/tools_menu/public/tools_menu_constants.h"
...@@ -51,6 +52,12 @@ id<GREYMatcher> TabGridUndoCloseAllButton() { ...@@ -51,6 +52,12 @@ id<GREYMatcher> TabGridUndoCloseAllButton() {
grey_sufficientlyVisible(), nil); grey_sufficientlyVisible(), nil);
} }
id<GREYMatcher> TabGridSelectShowHistoryCell() {
return grey_allOf(grey_accessibilityID(
kRecentTabsShowFullHistoryCellAccessibilityIdentifier),
grey_sufficientlyVisible(), nil);
}
id<GREYMatcher> TabGridRegularTabsEmptyStateView() { id<GREYMatcher> TabGridRegularTabsEmptyStateView() {
return grey_allOf( return grey_allOf(
grey_accessibilityID(kTabGridRegularTabsEmptyStateIdentifier), grey_accessibilityID(kTabGridRegularTabsEmptyStateIdentifier),
......
...@@ -542,6 +542,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) { ...@@ -542,6 +542,7 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
[self.view addSubview:scrollView]; [self.view addSubview:scrollView];
self.scrollContentView = contentView; self.scrollContentView = contentView;
self.scrollView = scrollView; self.scrollView = scrollView;
self.scrollView.accessibilityIdentifier = kTabGridScrollViewIdentifier;
NSArray* constraints = @[ NSArray* constraints = @[
[contentView.topAnchor constraintEqualToAnchor:scrollView.topAnchor], [contentView.topAnchor constraintEqualToAnchor:scrollView.topAnchor],
[contentView.bottomAnchor constraintEqualToAnchor:scrollView.bottomAnchor], [contentView.bottomAnchor constraintEqualToAnchor:scrollView.bottomAnchor],
......
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