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 <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
7 #import <WebKit/WebKit.h> | 7 #import <WebKit/WebKit.h> |
8 #import <XCTest/XCTest.h> | 8 #import <XCTest/XCTest.h> |
9 | 9 |
10 #include "base/ios/block_types.h" | 10 #include "base/ios/block_types.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #import "ios/testing/earl_grey/matchers.h" | 12 #import "ios/testing/earl_grey/matchers.h" |
13 #import "ios/web/public/test/http_server.h" | 13 #import "ios/web/public/test/http_server.h" |
14 #include "ios/web/public/test/http_server_util.h" | 14 #include "ios/web/public/test/http_server_util.h" |
15 #import "ios/web/public/test/web_view_interaction_test_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" | 16 #import "ios/web/shell/test/app/web_shell_test_util.h" |
18 #include "ios/web/shell/test/app/web_view_interaction_test_util.h" | 17 #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" | 18 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" |
20 #import "ios/web/shell/test/earl_grey/shell_actions.h" | 19 #import "ios/web/shell/test/earl_grey/shell_actions.h" |
| 20 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" |
21 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | 21 #import "ios/web/shell/test/earl_grey/shell_matchers.h" |
22 | 22 |
23 #if !defined(__has_feature) || !__has_feature(objc_arc) | 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
24 #error "This file requires ARC support." | 24 #error "This file requires ARC support." |
25 #endif | 25 #endif |
26 | 26 |
27 using testing::contextMenuItemWithText; | 27 using testing::contextMenuItemWithText; |
28 using testing::elementToDismissContextMenu; | 28 using testing::elementToDismissContextMenu; |
29 | 29 |
30 // Context menu test cases for the web shell. | 30 // Context menu test cases for the web shell. |
(...skipping 11 matching lines...) Expand all Loading... |
42 // The initial page contains a link to the destination URL. | 42 // The initial page contains a link to the destination URL. |
43 std::string linkID = "link"; | 43 std::string linkID = "link"; |
44 responses[initialURL] = | 44 responses[initialURL] = |
45 "<body>" | 45 "<body>" |
46 "<a href='" + | 46 "<a href='" + |
47 destinationURL.spec() + "' id='" + linkID + | 47 destinationURL.spec() + "' id='" + linkID + |
48 "'>link for context menu</a>" | 48 "'>link for context menu</a>" |
49 "</span></body>"; | 49 "</span></body>"; |
50 | 50 |
51 web::test::SetUpSimpleHttpServer(responses); | 51 web::test::SetUpSimpleHttpServer(responses); |
52 web::shell_test_util::LoadUrl(initialURL); | 52 [ShellEarlGrey loadURL:initialURL]; |
53 | 53 |
54 [[EarlGrey selectElementWithMatcher:web::webView()] | 54 [[EarlGrey selectElementWithMatcher:web::webView()] |
55 performAction:web::longPressElementForContextMenu( | 55 performAction:web::longPressElementForContextMenu( |
56 linkID, true /* menu should appear */)]; | 56 linkID, true /* menu should appear */)]; |
57 | 57 |
58 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); | 58 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); |
59 | 59 |
60 // Context menu should have a "copy link" item. | 60 // Context menu should have a "copy link" item. |
61 [[EarlGrey selectElementWithMatcher:copyItem] | 61 [[EarlGrey selectElementWithMatcher:copyItem] |
62 assertWithMatcher:grey_notNil()]; | 62 assertWithMatcher:grey_notNil()]; |
(...skipping 16 matching lines...) Expand all Loading... |
79 // The initial page contains a link to the destination URL that has an | 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. | 80 // ancestor that disables the context menu via -webkit-touch-callout. |
81 std::string linkID = "link"; | 81 std::string linkID = "link"; |
82 responses[initialURL] = "<body><a href='" + destinationURL.spec() + | 82 responses[initialURL] = "<body><a href='" + destinationURL.spec() + |
83 "' style='-webkit-touch-callout: none' id='" + | 83 "' style='-webkit-touch-callout: none' id='" + |
84 linkID + | 84 linkID + |
85 "'>no-callout link</a>" | 85 "'>no-callout link</a>" |
86 "</body>"; | 86 "</body>"; |
87 | 87 |
88 web::test::SetUpSimpleHttpServer(responses); | 88 web::test::SetUpSimpleHttpServer(responses); |
89 web::shell_test_util::LoadUrl(initialURL); | 89 [ShellEarlGrey loadURL:initialURL]; |
90 | 90 |
91 [[EarlGrey selectElementWithMatcher:web::webView()] | 91 [[EarlGrey selectElementWithMatcher:web::webView()] |
92 performAction:web::longPressElementForContextMenu( | 92 performAction:web::longPressElementForContextMenu( |
93 linkID, false /* menu shouldn't appear */)]; | 93 linkID, false /* menu shouldn't appear */)]; |
94 | 94 |
95 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); | 95 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); |
96 | 96 |
97 // Verify no context menu. | 97 // Verify no context menu. |
98 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; | 98 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
99 } | 99 } |
(...skipping 10 matching lines...) Expand all Loading... |
110 // ancestor that disables the context menu via -webkit-touch-callout. | 110 // ancestor that disables the context menu via -webkit-touch-callout. |
111 std::string linkID = "link"; | 111 std::string linkID = "link"; |
112 responses[initialURL] = | 112 responses[initialURL] = |
113 "<body style='-webkit-touch-callout: none'>" | 113 "<body style='-webkit-touch-callout: none'>" |
114 "<a href='" + | 114 "<a href='" + |
115 destinationURL.spec() + "' id='" + linkID + | 115 destinationURL.spec() + "' id='" + linkID + |
116 "'>ancestor no-callout link</a>" | 116 "'>ancestor no-callout link</a>" |
117 "</body>"; | 117 "</body>"; |
118 | 118 |
119 web::test::SetUpSimpleHttpServer(responses); | 119 web::test::SetUpSimpleHttpServer(responses); |
120 web::shell_test_util::LoadUrl(initialURL); | 120 [ShellEarlGrey loadURL:initialURL]; |
121 | 121 |
122 [[EarlGrey selectElementWithMatcher:web::webView()] | 122 [[EarlGrey selectElementWithMatcher:web::webView()] |
123 performAction:web::longPressElementForContextMenu( | 123 performAction:web::longPressElementForContextMenu( |
124 linkID, false /* menu shouldn't appear */)]; | 124 linkID, false /* menu shouldn't appear */)]; |
125 | 125 |
126 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); | 126 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); |
127 | 127 |
128 // Verify no context menu. | 128 // Verify no context menu. |
129 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; | 129 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
130 } | 130 } |
(...skipping 11 matching lines...) Expand all Loading... |
142 std::string linkID = "link"; | 142 std::string linkID = "link"; |
143 responses[initialURL] = | 143 responses[initialURL] = |
144 "<body style='-webkit-touch-callout: none'>" | 144 "<body style='-webkit-touch-callout: none'>" |
145 "<a href='" + | 145 "<a href='" + |
146 destinationURL.spec() + "' style='-webkit-touch-callout: default' id='" + | 146 destinationURL.spec() + "' style='-webkit-touch-callout: default' id='" + |
147 linkID + | 147 linkID + |
148 "'>override no-callout link</a>" | 148 "'>override no-callout link</a>" |
149 "</body>"; | 149 "</body>"; |
150 | 150 |
151 web::test::SetUpSimpleHttpServer(responses); | 151 web::test::SetUpSimpleHttpServer(responses); |
152 web::shell_test_util::LoadUrl(initialURL); | 152 [ShellEarlGrey loadURL:initialURL]; |
153 | 153 |
154 [[EarlGrey selectElementWithMatcher:web::webView()] | 154 [[EarlGrey selectElementWithMatcher:web::webView()] |
155 performAction:web::longPressElementForContextMenu( | 155 performAction:web::longPressElementForContextMenu( |
156 linkID, true /* menu should appear */)]; | 156 linkID, true /* menu should appear */)]; |
157 | 157 |
158 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); | 158 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); |
159 | 159 |
160 // Context menu should have a "copy link" item. | 160 // Context menu should have a "copy link" item. |
161 [[EarlGrey selectElementWithMatcher:copyItem] | 161 [[EarlGrey selectElementWithMatcher:copyItem] |
162 assertWithMatcher:grey_notNil()]; | 162 assertWithMatcher:grey_notNil()]; |
163 | 163 |
164 // Dismiss the context menu. | 164 // Dismiss the context menu. |
165 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")] | 165 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")] |
166 performAction:grey_tap()]; | 166 performAction:grey_tap()]; |
167 | 167 |
168 // Context menu should go away after the tap. | 168 // Context menu should go away after the tap. |
169 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; | 169 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
170 } | 170 } |
171 | 171 |
172 @end | 172 @end |
OLD | NEW |