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 <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 #import <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
| 7 | 7 |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/strings/grit/components_strings.h" | 9 #include "components/strings/grit/components_strings.h" |
| 10 #import "ios/chrome/browser/ui/chrome_web_view_factory.h" | 10 #import "ios/chrome/browser/ui/chrome_web_view_factory.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 userAgent == kDesktopUserAgent) { | 50 userAgent == kDesktopUserAgent) { |
| 51 response_body->assign("Desktop"); | 51 response_body->assign("Desktop"); |
| 52 } else { | 52 } else { |
| 53 response_body->assign("Mobile"); | 53 response_body->assign("Mobile"); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Matcher for the button to find in page. | 58 // Matcher for the button to find in page. |
| 59 id<GREYMatcher> FindInPageButton() { | 59 id<GREYMatcher> FindInPageButton() { |
| 60 return chrome_test_util::buttonWithAccessibilityLabel( | 60 return chrome_test_util::ButtonWithAccessibilityLabel( |
| 61 l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE)); | 61 l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Matcher for the button to request desktop version. | 64 // Matcher for the button to request desktop version. |
| 65 id<GREYMatcher> RequestDesktopButton() { | 65 id<GREYMatcher> RequestDesktopButton() { |
| 66 return grey_accessibilityID(kToolsMenuRequestDesktopId); | 66 return grey_accessibilityID(kToolsMenuRequestDesktopId); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Matcher for the navigate backward button. | 69 // Matcher for the navigate backward button. |
| 70 id<GREYMatcher> BackButton() { | 70 id<GREYMatcher> BackButton() { |
| 71 return chrome_test_util::buttonWithAccessibilityLabelId(IDS_ACCNAME_BACK); | 71 return chrome_test_util::ButtonWithAccessibilityLabelId(IDS_ACCNAME_BACK); |
|
Eugene But (OOO till 7-30)
2017/01/23 19:39:04
Could you please use existing matcher from chrome_
baxley
2017/01/24 22:18:49
Done.
| |
| 72 } | 72 } |
| 73 | 73 |
| 74 const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf"; | 74 const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf"; |
| 75 | 75 |
| 76 } // namespace | 76 } // namespace |
| 77 | 77 |
| 78 // Tests for the tools popup menu. | 78 // Tests for the tools popup menu. |
| 79 @interface ToolsPopupMenuTestCase : ChromeTestCase | 79 @interface ToolsPopupMenuTestCase : ChromeTestCase |
| 80 - (void)verifyMobileAndDesktopVersions:(const GURL&)url; | 80 - (void)verifyMobileAndDesktopVersions:(const GURL&)url; |
| 81 @end | 81 @end |
| 82 | 82 |
| 83 @implementation ToolsPopupMenuTestCase | 83 @implementation ToolsPopupMenuTestCase |
| 84 | 84 |
| 85 // Verify that requesting desktop and mobile versions works. | 85 // Verify that requesting desktop and mobile versions works. |
| 86 - (void)verifyMobileAndDesktopVersions:(const GURL&)url { | 86 - (void)verifyMobileAndDesktopVersions:(const GURL&)url { |
| 87 NSString* const kMobileSiteLabel = @"Mobile"; | 87 NSString* const kMobileSiteLabel = @"Mobile"; |
| 88 NSString* const kDesktopSiteLabel = @"Desktop"; | 88 NSString* const kDesktopSiteLabel = @"Desktop"; |
| 89 | 89 |
| 90 [ChromeEarlGrey loadURL:url]; | 90 [ChromeEarlGrey loadURL:url]; |
| 91 | 91 |
| 92 // Verify initial reception of the mobile site. | 92 // Verify initial reception of the mobile site. |
| 93 [[EarlGrey | 93 [[EarlGrey |
| 94 selectElementWithMatcher:chrome_test_util::webViewContainingText( | 94 selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 95 base::SysNSStringToUTF8(kMobileSiteLabel))] | 95 base::SysNSStringToUTF8(kMobileSiteLabel))] |
| 96 assertWithMatcher:grey_notNil()]; | 96 assertWithMatcher:grey_notNil()]; |
| 97 | 97 |
| 98 // Request and verify reception of the desktop site. | 98 // Request and verify reception of the desktop site. |
| 99 [ChromeEarlGreyUI openToolsMenu]; | 99 [ChromeEarlGreyUI openToolsMenu]; |
| 100 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] | 100 [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| 101 performAction:grey_tap()]; | 101 performAction:grey_tap()]; |
| 102 [[EarlGrey | 102 [[EarlGrey |
| 103 selectElementWithMatcher:chrome_test_util::webViewContainingText( | 103 selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 104 base::SysNSStringToUTF8(kDesktopSiteLabel))] | 104 base::SysNSStringToUTF8(kDesktopSiteLabel))] |
| 105 assertWithMatcher:grey_notNil()]; | 105 assertWithMatcher:grey_notNil()]; |
| 106 | 106 |
| 107 // Verify that going back returns to the mobile site. | 107 // Verify that going back returns to the mobile site. |
| 108 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; | 108 [[EarlGrey selectElementWithMatcher:BackButton()] performAction:grey_tap()]; |
| 109 [[EarlGrey | 109 [[EarlGrey |
| 110 selectElementWithMatcher:chrome_test_util::webViewContainingText( | 110 selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 111 base::SysNSStringToUTF8(kMobileSiteLabel))] | 111 base::SysNSStringToUTF8(kMobileSiteLabel))] |
| 112 assertWithMatcher:grey_notNil()]; | 112 assertWithMatcher:grey_notNil()]; |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Tests that the menu is closed when tapping the close button. | 115 // Tests that the menu is closed when tapping the close button. |
| 116 - (void)testOpenAndCloseToolsMenu { | 116 - (void)testOpenAndCloseToolsMenu { |
| 117 [ChromeEarlGreyUI openToolsMenu]; | 117 [ChromeEarlGreyUI openToolsMenu]; |
| 118 | 118 |
| 119 if (!IsCompact()) { | 119 if (!IsCompact()) { |
| 120 [[EarlGrey | 120 [[EarlGrey |
| 121 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( | 121 selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( |
| 122 IDS_IOS_TOOLBAR_CLOSE_MENU))] | 122 IDS_IOS_TOOLBAR_CLOSE_MENU))] |
| 123 performAction:grey_tap()]; | 123 performAction:grey_tap()]; |
| 124 } else { | 124 } else { |
| 125 [[EarlGrey selectElementWithMatcher:chrome_test_util::toolsMenuButton()] | 125 [[EarlGrey selectElementWithMatcher:chrome_test_util::ToolsMenuButton()] |
| 126 performAction:grey_tap()]; | 126 performAction:grey_tap()]; |
| 127 } | 127 } |
| 128 | 128 |
| 129 [[EarlGrey | 129 [[EarlGrey |
| 130 selectElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] | 130 selectElementWithMatcher:grey_accessibilityID(kToolsMenuTableViewId)] |
| 131 assertWithMatcher:grey_notVisible()]; | 131 assertWithMatcher:grey_notVisible()]; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Navigates to a pdf page and verifies that the "Find in Page..." tool | 134 // Navigates to a pdf page and verifies that the "Find in Page..." tool |
| 135 // is not enabled | 135 // is not enabled |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 | 169 |
| 170 // Open tools menu and verify elements are accessible. | 170 // Open tools menu and verify elements are accessible. |
| 171 - (void)testAccessibilityOnToolsMenu { | 171 - (void)testAccessibilityOnToolsMenu { |
| 172 [ChromeEarlGreyUI openToolsMenu]; | 172 [ChromeEarlGreyUI openToolsMenu]; |
| 173 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 173 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 174 // Close Tools menu. | 174 // Close Tools menu. |
| 175 [ChromeTestCase removeAnyOpenMenusAndInfoBars]; | 175 [ChromeTestCase removeAnyOpenMenusAndInfoBars]; |
| 176 } | 176 } |
| 177 | 177 |
| 178 @end | 178 @end |
| OLD | NEW |