Chromium Code Reviews| Index: ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm |
| diff --git a/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm b/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm |
| index 79784cc5d55b84130ef0bcee09ef3c8c5e027ccc..a04d47bb4bb0c7ad22508119ff123031ab76bd16 100644 |
| --- a/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm |
| +++ b/ios/chrome/browser/ui/tools_menu/tools_popup_menu_egtest.mm |
| @@ -65,53 +65,38 @@ void GetResponseHeadersAndBody( |
| l10n_util::GetNSStringWithFixup(IDS_IOS_TOOLS_MENU_FIND_IN_PAGE)); |
| } |
| -// Matcher for the button to request desktop version. |
| +// Matcher for the button to request desktop site. |
| id<GREYMatcher> RequestDesktopButton() { |
| return grey_accessibilityID(kToolsMenuRequestDesktopId); |
| } |
| +// Matcher for the button to request mobile site. |
| +id<GREYMatcher> RequestMobileButton() { |
| + return grey_accessibilityID(kToolsMenuRequestMobileId); |
| +} |
| + |
| +// Matcher for the button to close the tools menu. |
| +id<GREYMatcher> CloseToolsMenuButton() { |
| + NSString* closeMenuButtonText = |
| + l10n_util::GetNSString(IDS_IOS_TOOLBAR_CLOSE_MENU); |
| + return grey_allOf(grey_accessibilityID(kToolbarToolsMenuButtonIdentifier), |
| + grey_accessibilityLabel(closeMenuButtonText), nil); |
| +} |
| + |
| const char kPDFURL[] = "http://ios/testing/data/http_server_files/testpage.pdf"; |
| +const char kUserAgentTestURL[] = |
| + "http://ios/testing/data/http_server_files/user_agent_test_page.html"; |
| +const char kMobileSiteLabel[] = "Mobile"; |
| +const char kDesktopSiteLabel[] = "Desktop"; |
| } // namespace |
| // Tests for the tools popup menu. |
| @interface ToolsPopupMenuTestCase : ChromeTestCase |
| -- (void)verifyMobileAndDesktopVersions:(const GURL&)url; |
| @end |
| @implementation ToolsPopupMenuTestCase |
| -// Verify that requesting desktop and mobile versions works. |
| -- (void)verifyMobileAndDesktopVersions:(const GURL&)url { |
| - NSString* const kMobileSiteLabel = @"Mobile"; |
| - NSString* const kDesktopSiteLabel = @"Desktop"; |
| - |
| - [ChromeEarlGrey loadURL:url]; |
| - |
| - // Verify initial reception of the mobile site. |
| - [[EarlGrey |
| - selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| - base::SysNSStringToUTF8(kMobileSiteLabel))] |
| - assertWithMatcher:grey_notNil()]; |
| - |
| - // Request and verify reception of the desktop site. |
| - [ChromeEarlGreyUI openToolsMenu]; |
| - [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| - performAction:grey_tap()]; |
| - [[EarlGrey |
| - selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| - base::SysNSStringToUTF8(kDesktopSiteLabel))] |
| - assertWithMatcher:grey_notNil()]; |
| - |
| - // Verify that going back returns to the mobile site. |
| - [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |
| - performAction:grey_tap()]; |
| - [[EarlGrey |
| - selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| - base::SysNSStringToUTF8(kMobileSiteLabel))] |
| - assertWithMatcher:grey_notNil()]; |
| -} |
| - |
| // Tests that the menu is closed when tapping the close button. |
| - (void)testOpenAndCloseToolsMenu { |
| [ChromeEarlGreyUI openToolsMenu]; |
| @@ -145,26 +130,237 @@ - (void)testNoSearchForPDF { |
| UIAccessibilityTraitNotEnabled)]; |
| } |
| -// Test requesting desktop version of page works and going back re-opens mobile |
| -// version of page. |
| -- (void)testToolsMenuRequestDesktopNetwork { |
| +// Tests requesting desktop site of a page works and the user agent sticks for |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
nit: |Tests that| ?
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
This is really great set of tests, do you want to
liaoyuke
2017/04/11 18:27:20
sure, that sounds reasonable, and btw, thank you f
liaoyuke
2017/04/11 18:27:20
Done.
|
| +// next navigations in the same tab. |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:56
nit: |the next navigations|?
liaoyuke
2017/04/11 18:27:20
Done.
|
| +- (void)testRequestDesktopSiteSticksForNextNavigation { |
| std::unique_ptr<web::DataResponseProvider> provider( |
| new UserAgentResponseProvider()); |
| web::test::SetUpHttpServer(std::move(provider)); |
| - const GURL networkLayerTestURL = |
| - web::test::HttpServer::MakeUrl("http://network"); |
| - [self verifyMobileAndDesktopVersions:networkLayerTestURL]; |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")]; |
| + // Verify initial reception of the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
Do you want to add |using chrome_test_util::WebVie
liaoyuke
2017/04/11 18:27:20
Done.
|
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the desktop site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Verify that desktop user agent sticks. |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://2.com")]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| } |
| -// Test requesting the desktop version of a page works correctly for |
| -// script-based desktop/mobile differentation. |
| +// Tests requesting desktop site of a page works and desktop user agent doesn't |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
nit: |Tests the requesting|?
liaoyuke
2017/04/11 18:27:20
Done.
|
| +// stick in new tab. |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
nit: s/doesn't stick in new tab/does not propagate
liaoyuke
2017/04/11 18:27:20
Done.
|
| +- (void)testRequestDesktopSiteDoesNotStickInNewTab { |
| + std::unique_ptr<web::DataResponseProvider> provider( |
| + new UserAgentResponseProvider()); |
| + web::test::SetUpHttpServer(std::move(provider)); |
| + |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")]; |
| + // Verify initial reception of the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the desktop site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Verify that desktop user agent doesn't stick in tab. |
| + [ChromeEarlGreyUI openNewTab]; |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://2.com")]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests requesting desktop site of a page works and going back re-opens mobile |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
|Tests that requesting|
liaoyuke
2017/04/11 18:27:20
Done.
|
| +// version of the page. |
| +- (void)testRequestDesktopSiteGoBackToMobile { |
| + std::unique_ptr<web::DataResponseProvider> provider( |
| + new UserAgentResponseProvider()); |
| + web::test::SetUpHttpServer(std::move(provider)); |
| + |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")]; |
| + // Verify initial reception of the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the desktop site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Verify that going back returns to the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests requesting mobile site of a page works and the user agent sticks for |
| +// next navigations in the same tab. |
| +- (void)testRequestMobileSiteSticksForNextNavigation { |
| + std::unique_ptr<web::DataResponseProvider> provider( |
| + new UserAgentResponseProvider()); |
| + web::test::SetUpHttpServer(std::move(provider)); |
| + |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")]; |
| + // Verify initial reception of the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the desktop site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the mobile site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestMobileButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Verify that mobile user agent sticks. |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://2.com")]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests requesting mobile site of a page works and going back re-opens desktop |
| +// version of the page. |
| +- (void)testRequestMobileSiteGoBackToDesktop { |
| + std::unique_ptr<web::DataResponseProvider> provider( |
| + new UserAgentResponseProvider()); |
| + web::test::SetUpHttpServer(std::move(provider)); |
| + |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl("http://1.com")]; |
| + // Verify initial reception of the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the desktop site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the mobile site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestMobileButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Verify that going back returns to the desktop site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::BackButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests requesting desktop site button is not enabled on new tab pages. |
| +- (void)testRequestDesktopSiteNotEnabledOnNewTabPage { |
| + // Verify tapping on request desktop button is no-op. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + assertWithMatcher:grey_notNil()] performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:CloseToolsMenuButton()] |
| + performAction:grey_tap()]; |
| +} |
| + |
| +// Tests requesting desktop site button is not enabled on native pages. |
| +- (void)testRequestDesktopSiteNotEnabledOnNativePage { |
| + [ChromeEarlGrey loadURL:GURL("chrome://version")]; |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
chrome://version is not native but WebUI. Do you w
liaoyuke
2017/04/11 18:27:20
Done.
|
| + |
| + // Verify tapping on request desktop button is no-op. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + assertWithMatcher:grey_notNil()] performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + [[EarlGrey selectElementWithMatcher:CloseToolsMenuButton()] |
| + performAction:grey_tap()]; |
| +} |
| + |
| +// Tests requesting desktop site works correctly for script-based desktop/mobile |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
What is "script-based desktop/mobile differentatio
liaoyuke
2017/04/11 18:27:20
Here is the script in the html file:
<script type=
Eugene But (OOO till 7-30)
2017/04/11 22:21:19
Those are useful tests in general, so I think we s
Eugene But (OOO till 7-30)
2017/04/11 22:21:19
How about "Tests that navigator.appVersion JavaScr
liaoyuke
2017/04/12 00:26:18
Thanks! The new name and comments are much more de
liaoyuke
2017/04/12 00:26:18
Acknowledged.
|
| +// differentation. |
| - (void)testToolsMenuRequestDesktopScript { |
|
Eugene But (OOO till 7-30)
2017/04/11 22:21:19
How about |testAppVersionJSAPIWithDesktopUser| age
liaoyuke
2017/04/12 00:26:18
Done.
|
| web::test::SetUpFileBasedHttpServer(); |
| - const GURL scriptLayerTestURL = web::test::HttpServer::MakeUrl( |
| - "http://ios/testing/data/http_server_files/" |
| - "request_desktop_test_page.html"); |
| - [self verifyMobileAndDesktopVersions:scriptLayerTestURL]; |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUserAgentTestURL)]; |
| + // Verify initial reception of the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the desktop site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| +} |
| + |
| +// Tests requesting mobile site works correctly for script-based desktop/mobile |
|
Eugene But (OOO till 7-30)
2017/04/11 02:11:57
Same questions here.
liaoyuke
2017/04/11 18:27:20
Acknowledged.
|
| +// differentation. |
| +- (void)testToolsMenuRequestMobileScript { |
| + web::test::SetUpFileBasedHttpServer(); |
| + [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUserAgentTestURL)]; |
| + // Verify initial reception of the mobile site. |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the desktop site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestDesktopButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kDesktopSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Request and verify reception of the mobile site. |
| + [ChromeEarlGreyUI openToolsMenu]; |
| + [[EarlGrey selectElementWithMatcher:RequestMobileButton()] |
| + performAction:grey_tap()]; |
| + [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| + kMobileSiteLabel)] |
| + assertWithMatcher:grey_notNil()]; |
| } |
| // Open tools menu and verify elements are accessible. |