Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: ios/web/shell/test/context_menu_egtest.mm

Issue 2275303004: Context menu egtests, plus related utilities. (Closed)
Patch Set: Fewer References. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/shell/test/BUILD.gn ('k') | ios/web/shell/test/earl_grey/shell_actions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <EarlGrey/EarlGrey.h>
6 #import <UIKit/UIKit.h>
7 #import <WebKit/WebKit.h>
8 #import <XCTest/XCTest.h>
9
10 #include "base/ios/block_types.h"
11 #include "base/strings/sys_string_conversions.h"
12 #import "ios/testing/earl_grey/matchers.h"
13 #import "ios/web/public/test/http_server.h"
14 #include "ios/web/public/test/http_server_util.h"
15 #import "ios/web/public/test/web_view_interaction_test_util.h"
16 #include "ios/web/shell/test/app/navigation_test_util.h"
17 #import "ios/web/shell/test/app/web_shell_test_util.h"
18 #include "ios/web/shell/test/app/web_view_interaction_test_util.h"
19 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h"
20 #import "ios/web/shell/test/earl_grey/shell_actions.h"
21 #import "ios/web/shell/test/earl_grey/shell_matchers.h"
22
23 #if !defined(__has_feature) || !__has_feature(objc_arc)
24 #error "This file requires ARC support."
25 #endif
26
27 using testing::contextMenuItemWithText;
28 using testing::elementToDismissContextMenu;
29
30 // Context menu test cases for the web shell.
31 @interface ContextMenuTestCase : ShellBaseTestCase
32 @end
33
34 @implementation ContextMenuTestCase
35
36 // Tests context menu appears on a regular link.
37 - (void)testContextMenu {
38 // Create map of canned responses and set up the test HTML server.
39 std::map<GURL, std::string> responses;
40 GURL initialURL = web::test::HttpServer::MakeUrl("http://contextMenuOpen");
41 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination");
42 // The initial page contains a link to the destination URL.
43 std::string linkID = "link";
44 responses[initialURL] =
45 "<body>"
46 "<a href='" +
47 destinationURL.spec() + "' id='" + linkID +
48 "'>link for context menu</a>"
49 "</span></body>";
50
51 web::test::SetUpSimpleHttpServer(responses);
52 web::shell_test_util::LoadUrl(initialURL);
53
54 [[EarlGrey selectElementWithMatcher:web::webView()]
55 performAction:web::longPressElementForContextMenu(
56 linkID, true /* menu should appear */)];
57
58 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link");
59
60 // Context menu should have a "copy link" item.
61 [[EarlGrey selectElementWithMatcher:copyItem]
62 assertWithMatcher:grey_notNil()];
63
64 // Dismiss the context menu.
65 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")]
66 performAction:grey_tap()];
67
68 // Context menu should go away after the tap.
69 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()];
70 }
71
72 // Tests context menu on element that has WebkitTouchCallout set to none.
73 - (void)testContextMenuWebkitTouchCalloutNone {
74 // Create map of canned responses and set up the test HTML server.
75 std::map<GURL, std::string> responses;
76 GURL initialURL =
77 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit");
78 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination");
79 // The initial page contains a link to the destination URL that has an
80 // ancestor that disables the context menu via -webkit-touch-callout.
81 std::string linkID = "link";
82 responses[initialURL] = "<body><a href='" + destinationURL.spec() +
83 "' style='-webkit-touch-callout: none' id='" +
84 linkID +
85 "'>no-callout link</a>"
86 "</body>";
87
88 web::test::SetUpSimpleHttpServer(responses);
89 web::shell_test_util::LoadUrl(initialURL);
90
91 [[EarlGrey selectElementWithMatcher:web::webView()]
92 performAction:web::longPressElementForContextMenu(
93 linkID, false /* menu shouldn't appear */)];
94
95 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link");
96
97 // Verify no context menu.
98 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()];
99 }
100
101 // Tests context menu on element that has WebkitTouchCallout set to none from an
102 // ancestor.
103 - (void)testContextMenuWebkitTouchCalloutNoneFromAncestor {
104 // Create map of canned responses and set up the test HTML server.
105 std::map<GURL, std::string> responses;
106 GURL initialURL =
107 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit");
108 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination");
109 // The initial page contains a link to the destination URL that has an
110 // ancestor that disables the context menu via -webkit-touch-callout.
111 std::string linkID = "link";
112 responses[initialURL] =
113 "<body style='-webkit-touch-callout: none'>"
114 "<a href='" +
115 destinationURL.spec() + "' id='" + linkID +
116 "'>ancestor no-callout link</a>"
117 "</body>";
118
119 web::test::SetUpSimpleHttpServer(responses);
120 web::shell_test_util::LoadUrl(initialURL);
121
122 [[EarlGrey selectElementWithMatcher:web::webView()]
123 performAction:web::longPressElementForContextMenu(
124 linkID, false /* menu shouldn't appear */)];
125
126 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link");
127
128 // Verify no context menu.
129 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()];
130 }
131
132 // Tests context menu on element that has WebkitTouchCallout set to none from an
133 // ancestor and overridden.
134 - (void)testContextMenuWebkitTouchCalloutOverride {
135 // Create map of canned responses and set up the test HTML server.
136 std::map<GURL, std::string> responses;
137 GURL initialURL =
138 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit");
139 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination");
140 // The initial page contains a link to the destination URL that has an
141 // ancestor that disables the context menu via -webkit-touch-callout.
142 std::string linkID = "link";
143 responses[initialURL] =
144 "<body style='-webkit-touch-callout: none'>"
145 "<a href='" +
146 destinationURL.spec() + "' style='-webkit-touch-callout: default' id='" +
147 linkID +
148 "'>override no-callout link</a>"
149 "</body>";
150
151 web::test::SetUpSimpleHttpServer(responses);
152 web::shell_test_util::LoadUrl(initialURL);
153
154 [[EarlGrey selectElementWithMatcher:web::webView()]
155 performAction:web::longPressElementForContextMenu(
156 linkID, true /* menu should appear */)];
157
158 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link");
159
160 // Context menu should have a "copy link" item.
161 [[EarlGrey selectElementWithMatcher:copyItem]
162 assertWithMatcher:grey_notNil()];
163
164 // Dismiss the context menu.
165 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")]
166 performAction:grey_tap()];
167
168 // Context menu should go away after the tap.
169 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()];
170 }
171
172 @end
OLDNEW
« no previous file with comments | « ios/web/shell/test/BUILD.gn ('k') | ios/web/shell/test/earl_grey/shell_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698