Chromium Code Reviews| Index: ios/chrome/browser/ui/sad_tab/sad_tab_view_egtest.mm |
| diff --git a/ios/chrome/browser/ui/sad_tab/sad_tab_view_egtest.mm b/ios/chrome/browser/ui/sad_tab/sad_tab_view_egtest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..605cf05526bfe0fb750f6f1465ea2dbe2a94b047 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/sad_tab/sad_tab_view_egtest.mm |
| @@ -0,0 +1,122 @@ |
| +// Copyright 2017 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 "base/ios/ios_util.h" |
| +#include "components/strings/grit/components_strings.h" |
| +#include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h" |
| +#import "ios/chrome/test/app/chrome_test_util.h" |
| +#import "ios/chrome/test/app/navigation_test_util.h" |
| +#import "ios/chrome/test/earl_grey/chrome_assertions.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_test_case.h" |
| +#import "ios/web/public/test/http_server/http_server.h" |
| +#include "ios/web/public/test/http_server/http_server_util.h" |
| +#include "ui/base/l10n/l10n_util_mac.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +// Sad Tab View integration tests for Chrome. |
| +@interface SadTabViewTestCase : ChromeTestCase |
| +@end |
| + |
| +@implementation SadTabViewTestCase |
| + |
| +// Verifies initial and repeated visits to the Sad Tab. |
| +// N.B. There is a mechanism which changes the Sad Tab UI if a crash URL is |
|
kkhorimoto
2017/06/23 21:54:46
What does N.B. mean?
PL
2017/06/23 22:16:03
N.B. = Note Bene = Take careful note of the follow
|
| +// visited within 60 seconds, for this reason this one test can not |
| +// be easily split up across multiple tests |
| +// as visiting Sad Tab may not be idempotent. |
|
baxley
2017/06/26 08:25:36
Great comment! it cleared up my question of why th
|
| +- (void)testSadTabView { |
| + // A matcher for the main title of the Sad Tab in 'reload' mode. |
| + NSString* reloadSadTabTitleString = |
|
kkhorimoto
2017/06/23 21:54:46
optional: You'd save a line by inlining the l10n_u
PL
2017/06/23 22:16:04
Yeah, I think you're right. Originally I thought t
|
| + l10n_util::GetNSString(IDS_SAD_TAB_MESSAGE); |
| + id<GREYMatcher> reloadSadTabTitleStringMatcher = |
| + [GREYMatchers matcherForText:reloadSadTabTitleString]; |
| + // A matcher for the main title of the Sad Tab in 'feedback' mode. |
| + NSString* feedbackSadTabTitleString = |
| + l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_TRY); |
| + id<GREYMatcher> feedbackSadTabTitleStringMatcher = |
| + chrome_test_util::ContainsText(feedbackSadTabTitleString); |
| + // A matcher for a help string suggesting the user use Incognito Mode. |
| + NSString* incognitoHelpString = |
| + l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_INCOGNITO); |
| + id<GREYMatcher> incognitoHelpStringMatcher = |
| + chrome_test_util::ContainsText(incognitoHelpString); |
|
baxley
2017/06/26 08:25:36
Optional nit: If you want to make the test shorter
PL
2017/06/26 23:51:47
That's interesting, I've put up a change that does
|
| + |
| + // Prepare a simple but known URL to avoid testing from the NTP. |
| + web::test::SetUpFileBasedHttpServer(); |
| + const GURL simple_URL = web::test::HttpServer::MakeUrl( |
| + "http://ios/testing/data/http_server_files/destination.html"); |
| + |
| + // Prepare a helper block to test Sad Tab navigating from and to normal pages. |
| + void (^loadAndCheckSimpleURL)() = ^void() { |
| + [ChromeEarlGrey loadURL:simple_URL]; |
| + [ChromeEarlGrey waitForWebViewContainingText:"You've arrived"]; |
| + [[EarlGrey selectElementWithMatcher:reloadSadTabTitleStringMatcher] |
| + assertWithMatcher:grey_nil()]; |
| + [[EarlGrey selectElementWithMatcher:feedbackSadTabTitleStringMatcher] |
| + assertWithMatcher:grey_nil()]; |
| + }; |
| + |
| + loadAndCheckSimpleURL(); |
| + |
| + // Navigate to the chrome://crash URL which should show the Sad Tab. |
| + // Use chome_test_util::LoadURL() directly to avoid ChomeEarlGray helper |
|
baxley
2017/06/26 08:25:37
nit: s/LoadURL/LoadUrl
s/ChromeEarlGray/ChromeEarl
PL
2017/06/26 23:51:47
Good catch, done! Thanks!
|
| + // methods which expect to wait for web content. |
|
baxley
2017/06/26 08:25:36
Another great comment! answering my question about
|
| + const GURL crash_URL = GURL("chrome://crash"); |
| + chrome_test_util::LoadUrl(crash_URL); |
| + [[EarlGrey selectElementWithMatcher:reloadSadTabTitleStringMatcher] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Ensure user can navigate away from Sad Tab, and the Sad Tab content |
| + // is no longer visible. |
| + loadAndCheckSimpleURL(); |
| + |
| + // A second visit to the crashing URL should show a feedback message. |
| + // It should also show help messages including an invitation to use |
| + // Incognito Mode. |
| + chrome_test_util::LoadUrl(crash_URL); |
| + [[EarlGrey selectElementWithMatcher:feedbackSadTabTitleStringMatcher] |
| + assertWithMatcher:grey_notNil()]; |
| + [[EarlGrey selectElementWithMatcher:incognitoHelpStringMatcher] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Again ensure a user can navigate away from Sad Tab, and the Sad Tab content |
| + // is no longer visible. |
| + loadAndCheckSimpleURL(); |
| + |
| + // Open an Incognito tab and browse somewhere, the repeated crash UI changes |
| + // dependent on the Incognito mode. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + id<GREYMatcher> newIncognitoTabButtonMatcher = |
| + grey_accessibilityID(kToolsMenuNewIncognitoTabId); |
| + [[EarlGrey selectElementWithMatcher:newIncognitoTabButtonMatcher] |
| + performAction:grey_tap()]; |
| + chrome_test_util::AssertIncognitoTabCount(1); |
| + loadAndCheckSimpleURL(); |
| + |
| + // Test an initial crash, and then a second crash in Incognito mode, as above. |
| + // Incognito mode should not be suggested if already in Incognito mode. |
| + chrome_test_util::LoadUrl(crash_URL); |
| + [[EarlGrey selectElementWithMatcher:reloadSadTabTitleStringMatcher] |
| + assertWithMatcher:grey_notNil()]; |
| + chrome_test_util::LoadUrl(crash_URL); |
| + [[EarlGrey selectElementWithMatcher:feedbackSadTabTitleStringMatcher] |
| + assertWithMatcher:grey_notNil()]; |
| + [[EarlGrey selectElementWithMatcher:incognitoHelpStringMatcher] |
| + assertWithMatcher:grey_nil()]; |
| + |
| + // Finally, ensure that the user can browse away from the Sad Tab page |
| + // in Incognito Mode. |
| + loadAndCheckSimpleURL(); |
| +} |
| + |
| +@end |