Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(294)

Side by Side Diff: ios/chrome/browser/ui/sad_tab/sad_tab_view_egtest.mm

Issue 2952343002: EG Tests for Sad Tab View (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import <EarlGrey/EarlGrey.h>
6 #import <XCTest/XCTest.h>
7
8 #include "base/ios/ios_util.h"
9 #include "components/strings/grit/components_strings.h"
10 #include "ios/chrome/browser/ui/tools_menu/tools_menu_constants.h"
11 #import "ios/chrome/test/app/chrome_test_util.h"
12 #import "ios/chrome/test/app/navigation_test_util.h"
13 #import "ios/chrome/test/earl_grey/chrome_assertions.h"
14 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
15 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
16 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
17 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
18 #import "ios/web/public/test/http_server/http_server.h"
19 #include "ios/web/public/test/http_server/http_server_util.h"
20 #include "ui/base/l10n/l10n_util_mac.h"
21
22 #if !defined(__has_feature) || !__has_feature(objc_arc)
23 #error "This file requires ARC support."
24 #endif
25
26 // Sad Tab View integration tests for Chrome.
27 @interface SadTabViewTestCase : ChromeTestCase
28 @end
29
30 @implementation SadTabViewTestCase
31
32 // Verifies initial and repeated visits to the Sad Tab.
33 // 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
34 // visited within 60 seconds, for this reason this one test can not
35 // be easily split up across multiple tests
36 // 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
37 - (void)testSadTabView {
38 // A matcher for the main title of the Sad Tab in 'reload' mode.
39 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
40 l10n_util::GetNSString(IDS_SAD_TAB_MESSAGE);
41 id<GREYMatcher> reloadSadTabTitleStringMatcher =
42 [GREYMatchers matcherForText:reloadSadTabTitleString];
43 // A matcher for the main title of the Sad Tab in 'feedback' mode.
44 NSString* feedbackSadTabTitleString =
45 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_TRY);
46 id<GREYMatcher> feedbackSadTabTitleStringMatcher =
47 chrome_test_util::ContainsText(feedbackSadTabTitleString);
48 // A matcher for a help string suggesting the user use Incognito Mode.
49 NSString* incognitoHelpString =
50 l10n_util::GetNSString(IDS_SAD_TAB_RELOAD_INCOGNITO);
51 id<GREYMatcher> incognitoHelpStringMatcher =
52 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
53
54 // Prepare a simple but known URL to avoid testing from the NTP.
55 web::test::SetUpFileBasedHttpServer();
56 const GURL simple_URL = web::test::HttpServer::MakeUrl(
57 "http://ios/testing/data/http_server_files/destination.html");
58
59 // Prepare a helper block to test Sad Tab navigating from and to normal pages.
60 void (^loadAndCheckSimpleURL)() = ^void() {
61 [ChromeEarlGrey loadURL:simple_URL];
62 [ChromeEarlGrey waitForWebViewContainingText:"You've arrived"];
63 [[EarlGrey selectElementWithMatcher:reloadSadTabTitleStringMatcher]
64 assertWithMatcher:grey_nil()];
65 [[EarlGrey selectElementWithMatcher:feedbackSadTabTitleStringMatcher]
66 assertWithMatcher:grey_nil()];
67 };
68
69 loadAndCheckSimpleURL();
70
71 // Navigate to the chrome://crash URL which should show the Sad Tab.
72 // 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!
73 // methods which expect to wait for web content.
baxley 2017/06/26 08:25:36 Another great comment! answering my question about
74 const GURL crash_URL = GURL("chrome://crash");
75 chrome_test_util::LoadUrl(crash_URL);
76 [[EarlGrey selectElementWithMatcher:reloadSadTabTitleStringMatcher]
77 assertWithMatcher:grey_notNil()];
78
79 // Ensure user can navigate away from Sad Tab, and the Sad Tab content
80 // is no longer visible.
81 loadAndCheckSimpleURL();
82
83 // A second visit to the crashing URL should show a feedback message.
84 // It should also show help messages including an invitation to use
85 // Incognito Mode.
86 chrome_test_util::LoadUrl(crash_URL);
87 [[EarlGrey selectElementWithMatcher:feedbackSadTabTitleStringMatcher]
88 assertWithMatcher:grey_notNil()];
89 [[EarlGrey selectElementWithMatcher:incognitoHelpStringMatcher]
90 assertWithMatcher:grey_notNil()];
91
92 // Again ensure a user can navigate away from Sad Tab, and the Sad Tab content
93 // is no longer visible.
94 loadAndCheckSimpleURL();
95
96 // Open an Incognito tab and browse somewhere, the repeated crash UI changes
97 // dependent on the Incognito mode.
98 [ChromeEarlGreyUI openToolsMenu];
99 id<GREYMatcher> newIncognitoTabButtonMatcher =
100 grey_accessibilityID(kToolsMenuNewIncognitoTabId);
101 [[EarlGrey selectElementWithMatcher:newIncognitoTabButtonMatcher]
102 performAction:grey_tap()];
103 chrome_test_util::AssertIncognitoTabCount(1);
104 loadAndCheckSimpleURL();
105
106 // Test an initial crash, and then a second crash in Incognito mode, as above.
107 // Incognito mode should not be suggested if already in Incognito mode.
108 chrome_test_util::LoadUrl(crash_URL);
109 [[EarlGrey selectElementWithMatcher:reloadSadTabTitleStringMatcher]
110 assertWithMatcher:grey_notNil()];
111 chrome_test_util::LoadUrl(crash_URL);
112 [[EarlGrey selectElementWithMatcher:feedbackSadTabTitleStringMatcher]
113 assertWithMatcher:grey_notNil()];
114 [[EarlGrey selectElementWithMatcher:incognitoHelpStringMatcher]
115 assertWithMatcher:grey_nil()];
116
117 // Finally, ensure that the user can browse away from the Sad Tab page
118 // in Incognito Mode.
119 loadAndCheckSimpleURL();
120 }
121
122 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698