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

Side by Side Diff: ios/chrome/browser/ui/activity_services/activity_service_controller_egtest.mm

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 10 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <XCTest/XCTest.h> 5 #import <XCTest/XCTest.h>
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "components/strings/grit/components_strings.h" 8 #include "components/strings/grit/components_strings.h"
9 #import "ios/chrome/browser/ui/browser_view_controller_dependency_factory.h" 9 #import "ios/chrome/browser/ui/browser_view_controller_dependency_factory.h"
10 #import "ios/chrome/browser/ui/uikit_ui_util.h" 10 #import "ios/chrome/browser/ui/uikit_ui_util.h"
11 #include "ios/chrome/grit/ios_strings.h" 11 #include "ios/chrome/grit/ios_strings.h"
12 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" 12 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
13 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" 13 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
14 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 14 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
15 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 15 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
16 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" 16 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h"
17 #import "ios/chrome/test/app/chrome_test_util.h"
18 #import "ios/web/public/test/earl_grey/web_view_matchers.h"
17 #import "ios/web/public/test/http_server.h" 19 #import "ios/web/public/test/http_server.h"
18 #import "ios/web/public/test/http_server_util.h" 20 #import "ios/web/public/test/http_server_util.h"
19 #include "ios/web/public/test/response_providers/error_page_response_provider.h" 21 #include "ios/web/public/test/response_providers/error_page_response_provider.h"
20 #include "ios/web/public/test/response_providers/response_provider.h" 22 #include "ios/web/public/test/response_providers/response_provider.h"
21 #include "ui/base/l10n/l10n_util_mac.h" 23 #include "ui/base/l10n/l10n_util_mac.h"
22 24
23 namespace { 25 namespace {
24 26
25 // Assert the activity service is visible by checking the "copy" button. 27 // Assert the activity service is visible by checking the "copy" button.
26 void AssertActivityServiceVisible() { 28 void AssertActivityServiceVisible() {
27 [[EarlGrey 29 [[EarlGrey
28 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabel( 30 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel(
29 @"Copy")] 31 @"Copy")]
30 assertWithMatcher:grey_interactable()]; 32 assertWithMatcher:grey_interactable()];
31 } 33 }
32 34
33 // Assert the activity service is not visible by checking the "copy" button. 35 // Assert the activity service is not visible by checking the "copy" button.
34 void AssertActivityServiceNotVisible() { 36 void AssertActivityServiceNotVisible() {
35 [[EarlGrey 37 [[EarlGrey
36 selectElementWithMatcher: 38 selectElementWithMatcher:
37 grey_allOf(chrome_test_util::buttonWithAccessibilityLabel(@"Copy"), 39 grey_allOf(chrome_test_util::ButtonWithAccessibilityLabel(@"Copy"),
38 grey_interactable(), nil)] assertWithMatcher:grey_nil()]; 40 grey_interactable(), nil)] assertWithMatcher:grey_nil()];
39 } 41 }
40 42
41 // Returns a button with a print label. 43 // Returns a button with a print label.
42 id<GREYMatcher> printButton() { 44 id<GREYMatcher> PrintButton() {
43 return chrome_test_util::buttonWithAccessibilityLabel(@"Print"); 45 return chrome_test_util::ButtonWithAccessibilityLabel(@"Print");
44 } 46 }
45 47
46 } // namespace 48 } // namespace
47 49
48 // Earl grey integration tests for Activity Service Controller. 50 // Earl grey integration tests for Activity Service Controller.
49 @interface ActivityServiceControllerTestCase : ChromeTestCase 51 @interface ActivityServiceControllerTestCase : ChromeTestCase
50 @end 52 @end
51 53
52 @implementation ActivityServiceControllerTestCase 54 @implementation ActivityServiceControllerTestCase
53 55
54 // Test that when trying to print a page redirected to an unprintable page, a 56 // Test that when trying to print a page redirected to an unprintable page, a
55 // snackbar explaining that the page cannot be printed is displayed. 57 // snackbar explaining that the page cannot be printed is displayed.
56 - (void)testActivityServiceControllerPrintAfterRedirectionToUnprintablePage { 58 - (void)testActivityServiceControllerPrintAfterRedirectionToUnprintablePage {
57 std::map<GURL, std::string> responses; 59 std::map<GURL, std::string> responses;
58 const GURL regularPageURL = web::test::HttpServer::MakeUrl("http://choux"); 60 const GURL regularPageURL = web::test::HttpServer::MakeUrl("http://choux");
59 responses[regularPageURL] = "fleur"; 61 responses[regularPageURL] = "fleur";
60 web::test::SetUpHttpServer( 62 web::test::SetUpHttpServer(
61 base::MakeUnique<ErrorPageResponseProvider>(responses)); 63 base::MakeUnique<ErrorPageResponseProvider>(responses));
62 64
63 // Open a regular page and verify that you can share. 65 // Open a regular page and verify that you can share.
64 [ChromeEarlGrey loadURL:regularPageURL]; 66 [ChromeEarlGrey loadURL:regularPageURL];
65 [ChromeEarlGreyUI openShareMenu]; 67 [ChromeEarlGreyUI openShareMenu];
66 AssertActivityServiceVisible(); 68 AssertActivityServiceVisible();
67 69
68 // Open an error page. 70 // Open an error page.
69 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()]; 71 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()];
70 [[EarlGrey selectElementWithMatcher:chrome_test_util:: 72 id<GREYMatcher> webViewMatcher =
71 webViewBelongingToWebController()] 73 web::WebViewInWebState(chrome_test_util::GetCurrentWebState());
74 [[EarlGrey selectElementWithMatcher:webViewMatcher]
72 assertWithMatcher:grey_nil()]; 75 assertWithMatcher:grey_nil()];
73 NSString* const kError = 76 NSString* const kError =
74 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE); 77 l10n_util::GetNSString(IDS_ERRORPAGES_HEADING_NOT_AVAILABLE);
75 [[EarlGrey 78 [[EarlGrey
76 selectElementWithMatcher:chrome_test_util::staticHtmlViewContainingText( 79 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
77 kError)] assertWithMatcher:grey_notNil()]; 80 kError)] assertWithMatcher:grey_notNil()];
78 81
79 // Execute the Print action. 82 // Execute the Print action.
80 [[EarlGrey selectElementWithMatcher:printButton()] performAction:grey_tap()]; 83 [[EarlGrey selectElementWithMatcher:PrintButton()] performAction:grey_tap()];
81 84
82 // Verify that a toast notification appears. 85 // Verify that a toast notification appears.
83 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel( 86 [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(
84 @"This page cannot be printed.")] 87 @"This page cannot be printed.")]
85 assertWithMatcher:grey_interactable()]; 88 assertWithMatcher:grey_interactable()];
86 89
87 // Dismiss the snackbar. 90 // Dismiss the snackbar.
88 [MDCSnackbarManager dismissAndCallCompletionBlocksWithCategory: 91 [MDCSnackbarManager dismissAndCallCompletionBlocksWithCategory:
89 kBrowserViewControllerSnackbarCategory]; 92 kBrowserViewControllerSnackbarCategory];
90 } 93 }
91 94
92 - (void)testActivityServiceControllerCantPrintUnprintablePages { 95 - (void)testActivityServiceControllerCantPrintUnprintablePages {
93 std::unique_ptr<web::DataResponseProvider> provider( 96 std::unique_ptr<web::DataResponseProvider> provider(
94 new ErrorPageResponseProvider()); 97 new ErrorPageResponseProvider());
95 web::test::SetUpHttpServer(std::move(provider)); 98 web::test::SetUpHttpServer(std::move(provider));
96 99
97 // Open a page with an error. 100 // Open a page with an error.
98 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()]; 101 [ChromeEarlGrey loadURL:ErrorPageResponseProvider::GetDnsFailureUrl()];
99 102
100 // Verify that you can share, but that the Print action is not available. 103 // Verify that you can share, but that the Print action is not available.
101 [ChromeEarlGreyUI openShareMenu]; 104 [ChromeEarlGreyUI openShareMenu];
102 AssertActivityServiceVisible(); 105 AssertActivityServiceVisible();
103 [[EarlGrey selectElementWithMatcher:printButton()] 106 [[EarlGrey selectElementWithMatcher:PrintButton()]
104 assertWithMatcher:grey_nil()]; 107 assertWithMatcher:grey_nil()];
105 } 108 }
106 109
107 - (void)testActivityServiceControllerIsDisabled { 110 - (void)testActivityServiceControllerIsDisabled {
108 // Open an un-shareable page. 111 // Open an un-shareable page.
109 GURL kURL("chrome://version"); 112 GURL kURL("chrome://version");
110 [ChromeEarlGrey loadURL:kURL]; 113 [ChromeEarlGrey loadURL:kURL];
111 // Verify that the share button is disabled. 114 // Verify that the share button is disabled.
112 if (IsCompact()) { 115 if (IsCompact()) {
113 [ChromeEarlGreyUI openToolsMenu]; 116 [ChromeEarlGreyUI openToolsMenu];
114 } 117 }
115 id<GREYMatcher> share_button = chrome_test_util::shareButton(); 118 id<GREYMatcher> share_button = chrome_test_util::ShareButton();
116 [[EarlGrey selectElementWithMatcher:share_button] 119 [[EarlGrey selectElementWithMatcher:share_button]
117 assertWithMatcher:grey_accessibilityTrait( 120 assertWithMatcher:grey_accessibilityTrait(
118 UIAccessibilityTraitNotEnabled)]; 121 UIAccessibilityTraitNotEnabled)];
119 } 122 }
120 123
121 - (void)testOpenActivityServiceControllerAndCopy { 124 - (void)testOpenActivityServiceControllerAndCopy {
122 // Set up mock http server. 125 // Set up mock http server.
123 std::map<GURL, std::string> responses; 126 std::map<GURL, std::string> responses;
124 GURL url = web::test::HttpServer::MakeUrl("http://potato"); 127 GURL url = web::test::HttpServer::MakeUrl("http://potato");
125 responses[url] = "tomato"; 128 responses[url] = "tomato";
126 web::test::SetUpSimpleHttpServer(responses); 129 web::test::SetUpSimpleHttpServer(responses);
127 130
128 // Open page and open the share menu. 131 // Open page and open the share menu.
129 [ChromeEarlGrey loadURL:url]; 132 [ChromeEarlGrey loadURL:url];
130 [ChromeEarlGreyUI openShareMenu]; 133 [ChromeEarlGreyUI openShareMenu];
131 134
132 // Verify that the share menu is up and contains a Print action. 135 // Verify that the share menu is up and contains a Print action.
133 AssertActivityServiceVisible(); 136 AssertActivityServiceVisible();
134 [[EarlGrey selectElementWithMatcher:printButton()] 137 [[EarlGrey selectElementWithMatcher:PrintButton()]
135 assertWithMatcher:grey_interactable()]; 138 assertWithMatcher:grey_interactable()];
136 139
137 // Start the Copy action and verify that the share menu gets dismissed. 140 // Start the Copy action and verify that the share menu gets dismissed.
138 [[EarlGrey 141 [[EarlGrey
139 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabel( 142 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabel(
140 @"Copy")] performAction:grey_tap()]; 143 @"Copy")] performAction:grey_tap()];
141 AssertActivityServiceNotVisible(); 144 AssertActivityServiceNotVisible();
142 } 145 }
143 146
144 @end 147 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/activity_services/BUILD.gn ('k') | ios/chrome/browser/ui/alert_coordinator/alert_coordinator_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698