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