Chromium Code Reviews| Index: ios/web/shell/test/context_menu_egtest.mm |
| diff --git a/ios/web/shell/test/context_menu_egtest.mm b/ios/web/shell/test/context_menu_egtest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..eaaef3470f0346f16e6744245de90597bb3d6b4c |
| --- /dev/null |
| +++ b/ios/web/shell/test/context_menu_egtest.mm |
| @@ -0,0 +1,170 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import <UIKit/UIKit.h> |
| +#import <WebKit/WebKit.h> |
| +#import <XCTest/XCTest.h> |
| + |
| +#import <EarlGrey/EarlGrey.h> |
|
Eugene But (OOO till 7-30)
2016/08/30 18:11:05
NIT: Please put this import along with other frame
marq (ping after 24h)
2016/08/31 13:07:58
Done.
|
| + |
| +#include "base/ios/block_types.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#import "ios/testing/earl_grey/matchers.h" |
| +#import "ios/web/public/test/http_server.h" |
| +#include "ios/web/public/test/http_server_util.h" |
| +#import "ios/web/public/test/web_view_interaction_test_util.h" |
| +#include "ios/web/shell/test/app/navigation_test_util.h" |
| +#import "ios/web/shell/test/app/web_shell_test_util.h" |
| +#include "ios/web/shell/test/app/web_view_interaction_test_util.h" |
| +#import "ios/web/shell/test/earl_grey/shell_base_test_case.h" |
| +#import "ios/web/shell/test/earl_grey/shell_actions.h" |
| +#import "ios/web/shell/test/earl_grey/shell_matchers.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +using testing::contextMenuItemContainingText; |
| +using testing::elementToDismissContextMenu; |
| + |
| +// Context menu test cases for the web shell. |
| +@interface ContextMenuTestCase : ShellBaseTestCase |
| +@end |
| + |
| +@implementation ContextMenuTestCase |
| + |
| +// Tests context menu appears on a regular link. |
| + |
|
Eugene But (OOO till 7-30)
2016/08/30 18:11:05
Drop endline
marq (ping after 24h)
2016/08/31 13:07:58
Done.
|
| +- (void)testContextMenu { |
| + // Create map of canned responses and set up the test HTML server. |
| + std::map<GURL, std::string> responses; |
| + GURL initialURL = web::test::HttpServer::MakeUrl("http://contextMenuOpen"); |
| + GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| + // The initial page contains a link to the destination URL. |
| + std::string linkId = "link"; |
|
Eugene But (OOO till 7-30)
2016/08/30 18:11:05
s/linkId/linkID
Please fix in other places as wel
marq (ping after 24h)
2016/08/31 13:07:58
Done.
|
| + responses[initialURL] = |
| + "<body>" |
| + "<a href='" + |
| + destinationURL.spec() + "' id='" + linkId + |
| + "'>link for context menu</a>" |
| + "</span></body>"; |
| + |
| + web::test::SetUpSimpleHttpServer(responses); |
| + web::shell_test_util::LoadUrl(initialURL); |
| + |
| + web::LongPressWebViewElementForContextMenu(linkId, |
| + true /* menu should appear */); |
| + |
| + id<GREYMatcher> copyItem = contextMenuItemContainingText(@"Copy"); |
|
Eugene But (OOO till 7-30)
2016/08/30 18:11:05
NIT: Is there a reason why contextMenuItemContaini
marq (ping after 24h)
2016/08/31 13:07:58
In two cases |copyItem| is used twice, so I'd rath
|
| + |
| + // Context menu should have a "copy" item. |
|
Eugene But (OOO till 7-30)
2016/08/30 18:11:05
System context menu also has "Copy" item. Should w
marq (ping after 24h)
2016/08/31 13:07:58
Let's make the web shell item "Copy Link".
|
| + [[EarlGrey selectElementWithMatcher:copyItem] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Dismiss the context menu |
| + [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu()] |
| + performAction:grey_tap()]; |
| + |
| + // Context menu should go away after the tap. |
| + [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| +} |
| + |
| +// Tests context menu on element that has WebkitTouchCallout set to none. |
| +- (void)testContextMenuWebkitTouchCalloutNone { |
| + // Create map of canned responses and set up the test HTML server. |
| + std::map<GURL, std::string> responses; |
| + GURL initialURL = |
| + web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); |
| + GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| + // The initial page contains a link to the destination URL that has an |
| + // ancestor that disables the context menu via -webkit-touch-callout. |
| + std::string linkId = "link"; |
| + responses[initialURL] = "<body><a href='" + destinationURL.spec() + |
| + "' style='-webkit-touch-callout: none' id='" + |
| + linkId + |
| + "'>no-callout link</a>" |
| + "</body>"; |
| + |
| + web::test::SetUpSimpleHttpServer(responses); |
| + web::shell_test_util::LoadUrl(initialURL); |
| + |
| + web::LongPressWebViewElementForContextMenu(linkId, |
| + false /* menu shouldn't appear */); |
| + |
| + id<GREYMatcher> copyItem = contextMenuItemContainingText(@"Copy"); |
| + |
| + // Verify no context menu. |
| + [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| +} |
| + |
| +// Tests context menu on element that has WebkitTouchCallout set to none from an |
| +// ancestor. |
| +- (void)testContextMenuWebkitTouchCalloutNoneFromAncestor { |
| + // Create map of canned responses and set up the test HTML server. |
| + std::map<GURL, std::string> responses; |
| + GURL initialURL = |
| + web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); |
| + GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| + // The initial page contains a link to the destination URL that has an |
| + // ancestor that disables the context menu via -webkit-touch-callout. |
| + std::string linkId = "link"; |
| + responses[initialURL] = |
| + "<body style='-webkit-touch-callout: none'>" |
| + "<a href='" + |
| + destinationURL.spec() + "' id='" + linkId + |
| + "'>ancestor no-callout link</a>" |
| + "</body>"; |
| + |
| + web::test::SetUpSimpleHttpServer(responses); |
| + web::shell_test_util::LoadUrl(initialURL); |
| + |
| + web::LongPressWebViewElementForContextMenu(linkId, |
| + false /* menu shouldn't appear */); |
| + |
| + id<GREYMatcher> copyItem = contextMenuItemContainingText(@"Copy"); |
| + |
| + // Verify no context menu. |
| + [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| +} |
| + |
| +// Tests context menu on element that has WebkitTouchCallout set to none from an |
| +// ancestor and overridden. |
| +- (void)testContextMenuWebkitTouchCalloutOverride { |
| + // Create map of canned responses and set up the test HTML server. |
| + std::map<GURL, std::string> responses; |
| + GURL initialURL = |
| + web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); |
| + GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| + // The initial page contains a link to the destination URL that has an |
| + // ancestor that disables the context menu via -webkit-touch-callout. |
| + std::string linkId = "link"; |
| + responses[initialURL] = |
| + "<body style='-webkit-touch-callout: none'>" |
| + "<a href='" + |
| + destinationURL.spec() + "' style='-webkit-touch-callout: default' id='" + |
| + linkId + |
| + "'>override no-callout link</a>" |
| + "</body>"; |
| + |
| + web::test::SetUpSimpleHttpServer(responses); |
| + web::shell_test_util::LoadUrl(initialURL); |
| + |
| + web::LongPressWebViewElementForContextMenu(linkId, |
| + true /* menu should appear */); |
| + |
| + id<GREYMatcher> copyItem = contextMenuItemContainingText(@"Copy"); |
| + |
| + // Context menu should have a "copy" item. |
| + [[EarlGrey selectElementWithMatcher:copyItem] |
| + assertWithMatcher:grey_notNil()]; |
| + |
| + // Dismiss the context menu |
| + [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu()] |
| + performAction:grey_tap()]; |
| + |
| + // Context menu should go away after the tap. |
| + [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| +} |
| + |
| +@end |