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