| 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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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. |
| 31 @interface ContextMenuTestCase : ShellBaseTestCase | 31 @interface ContextMenuTestCase : ShellBaseTestCase |
| 32 @end | 32 @end |
| 33 | 33 |
| 34 @implementation ContextMenuTestCase | 34 @implementation ContextMenuTestCase |
| 35 | 35 |
| 36 // TODO(crbug.com/675015): Re-enable this test on device. |
| 37 #if TARGET_IPHONE_SIMULATOR |
| 38 #define MAYBE_testContextMenu testContextMenu |
| 39 #else |
| 40 #define MAYBE_testContextMenu FLAKY_testContextMenu |
| 41 #endif |
| 36 // Tests context menu appears on a regular link. | 42 // Tests context menu appears on a regular link. |
| 37 - (void)testContextMenu { | 43 - (void)MAYBE_testContextMenu { |
| 38 // Create map of canned responses and set up the test HTML server. | 44 // Create map of canned responses and set up the test HTML server. |
| 39 std::map<GURL, std::string> responses; | 45 std::map<GURL, std::string> responses; |
| 40 GURL initialURL = web::test::HttpServer::MakeUrl("http://contextMenuOpen"); | 46 GURL initialURL = web::test::HttpServer::MakeUrl("http://contextMenuOpen"); |
| 41 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); | 47 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| 42 // The initial page contains a link to the destination URL. | 48 // The initial page contains a link to the destination URL. |
| 43 std::string linkID = "link"; | 49 std::string linkID = "link"; |
| 44 responses[initialURL] = | 50 responses[initialURL] = |
| 45 "<body>" | 51 "<body>" |
| 46 "<a href='" + | 52 "<a href='" + |
| 47 destinationURL.spec() + "' id='" + linkID + | 53 destinationURL.spec() + "' id='" + linkID + |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 assertWithMatcher:grey_notNil()]; | 68 assertWithMatcher:grey_notNil()]; |
| 63 | 69 |
| 64 // Dismiss the context menu. | 70 // Dismiss the context menu. |
| 65 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")] | 71 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")] |
| 66 performAction:grey_tap()]; | 72 performAction:grey_tap()]; |
| 67 | 73 |
| 68 // Context menu should go away after the tap. | 74 // Context menu should go away after the tap. |
| 69 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; | 75 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| 70 } | 76 } |
| 71 | 77 |
| 78 // TODO(crbug.com/675015): Re-enable this test on device. |
| 79 #if TARGET_IPHONE_SIMULATOR |
| 80 #define MAYBE_testContextMenuWebkitTouchCalloutNone \ |
| 81 testContextMenuWebkitTouchCalloutNone |
| 82 #else |
| 83 #define MAYBE_testContextMenuWebkitTouchCalloutNone \ |
| 84 FLAKY_testContextMenuWebkitTouchCalloutNone |
| 85 #endif |
| 72 // Tests context menu on element that has WebkitTouchCallout set to none. | 86 // Tests context menu on element that has WebkitTouchCallout set to none. |
| 73 - (void)testContextMenuWebkitTouchCalloutNone { | 87 - (void)MAYBE_testContextMenuWebkitTouchCalloutNone { |
| 74 // Create map of canned responses and set up the test HTML server. | 88 // Create map of canned responses and set up the test HTML server. |
| 75 std::map<GURL, std::string> responses; | 89 std::map<GURL, std::string> responses; |
| 76 GURL initialURL = | 90 GURL initialURL = |
| 77 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); | 91 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); |
| 78 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); | 92 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| 79 // The initial page contains a link to the destination URL that has an | 93 // The initial page contains a link to the destination URL that has an |
| 80 // ancestor that disables the context menu via -webkit-touch-callout. | 94 // ancestor that disables the context menu via -webkit-touch-callout. |
| 81 std::string linkID = "link"; | 95 std::string linkID = "link"; |
| 82 responses[initialURL] = "<body><a href='" + destinationURL.spec() + | 96 responses[initialURL] = "<body><a href='" + destinationURL.spec() + |
| 83 "' style='-webkit-touch-callout: none' id='" + | 97 "' style='-webkit-touch-callout: none' id='" + |
| 84 linkID + | 98 linkID + |
| 85 "'>no-callout link</a>" | 99 "'>no-callout link</a>" |
| 86 "</body>"; | 100 "</body>"; |
| 87 | 101 |
| 88 web::test::SetUpSimpleHttpServer(responses); | 102 web::test::SetUpSimpleHttpServer(responses); |
| 89 [ShellEarlGrey loadURL:initialURL]; | 103 [ShellEarlGrey loadURL:initialURL]; |
| 90 | 104 |
| 91 [[EarlGrey selectElementWithMatcher:web::webView()] | 105 [[EarlGrey selectElementWithMatcher:web::webView()] |
| 92 performAction:web::longPressElementForContextMenu( | 106 performAction:web::longPressElementForContextMenu( |
| 93 linkID, false /* menu shouldn't appear */)]; | 107 linkID, false /* menu shouldn't appear */)]; |
| 94 | 108 |
| 95 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); | 109 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); |
| 96 | 110 |
| 97 // Verify no context menu. | 111 // Verify no context menu. |
| 98 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; | 112 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| 99 } | 113 } |
| 100 | 114 |
| 115 // TODO(crbug.com/675015): Re-enable this test on device. |
| 116 #if TARGET_IPHONE_SIMULATOR |
| 117 #define MAYBE_testContextMenuWebkitTouchCalloutNoneFromAncestor \ |
| 118 testContextMenuWebkitTouchCalloutNoneFromAncestor |
| 119 #else |
| 120 #define MAYBE_testContextMenuWebkitTouchCalloutNoneFromAncestor \ |
| 121 FLAKY_testContextMenuWebkitTouchCalloutNoneFromAncestor |
| 122 #endif |
| 101 // Tests context menu on element that has WebkitTouchCallout set to none from an | 123 // Tests context menu on element that has WebkitTouchCallout set to none from an |
| 102 // ancestor. | 124 // ancestor. |
| 103 - (void)testContextMenuWebkitTouchCalloutNoneFromAncestor { | 125 - (void)MAYBE_testContextMenuWebkitTouchCalloutNoneFromAncestor { |
| 104 // Create map of canned responses and set up the test HTML server. | 126 // Create map of canned responses and set up the test HTML server. |
| 105 std::map<GURL, std::string> responses; | 127 std::map<GURL, std::string> responses; |
| 106 GURL initialURL = | 128 GURL initialURL = |
| 107 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); | 129 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); |
| 108 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); | 130 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| 109 // The initial page contains a link to the destination URL that has an | 131 // The initial page contains a link to the destination URL that has an |
| 110 // ancestor that disables the context menu via -webkit-touch-callout. | 132 // ancestor that disables the context menu via -webkit-touch-callout. |
| 111 std::string linkID = "link"; | 133 std::string linkID = "link"; |
| 112 responses[initialURL] = | 134 responses[initialURL] = |
| 113 "<body style='-webkit-touch-callout: none'>" | 135 "<body style='-webkit-touch-callout: none'>" |
| 114 "<a href='" + | 136 "<a href='" + |
| 115 destinationURL.spec() + "' id='" + linkID + | 137 destinationURL.spec() + "' id='" + linkID + |
| 116 "'>ancestor no-callout link</a>" | 138 "'>ancestor no-callout link</a>" |
| 117 "</body>"; | 139 "</body>"; |
| 118 | 140 |
| 119 web::test::SetUpSimpleHttpServer(responses); | 141 web::test::SetUpSimpleHttpServer(responses); |
| 120 [ShellEarlGrey loadURL:initialURL]; | 142 [ShellEarlGrey loadURL:initialURL]; |
| 121 | 143 |
| 122 [[EarlGrey selectElementWithMatcher:web::webView()] | 144 [[EarlGrey selectElementWithMatcher:web::webView()] |
| 123 performAction:web::longPressElementForContextMenu( | 145 performAction:web::longPressElementForContextMenu( |
| 124 linkID, false /* menu shouldn't appear */)]; | 146 linkID, false /* menu shouldn't appear */)]; |
| 125 | 147 |
| 126 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); | 148 id<GREYMatcher> copyItem = contextMenuItemWithText(@"Copy Link"); |
| 127 | 149 |
| 128 // Verify no context menu. | 150 // Verify no context menu. |
| 129 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; | 151 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| 130 } | 152 } |
| 131 | 153 |
| 154 // TODO(crbug.com/675015): Re-enable this test on device. |
| 155 #if TARGET_IPHONE_SIMULATOR |
| 156 #define MAYBE_testContextMenuWebkitTouchCalloutOverride \ |
| 157 testContextMenuWebkitTouchCalloutOverride |
| 158 #else |
| 159 #define MAYBE_testContextMenuWebkitTouchCalloutOverride \ |
| 160 FLAKY_testContextMenuWebkitTouchCalloutOverride |
| 161 #endif |
| 132 // Tests context menu on element that has WebkitTouchCallout set to none from an | 162 // Tests context menu on element that has WebkitTouchCallout set to none from an |
| 133 // ancestor and overridden. | 163 // ancestor and overridden. |
| 134 - (void)testContextMenuWebkitTouchCalloutOverride { | 164 - (void)MAYBE_testContextMenuWebkitTouchCalloutOverride { |
| 135 // Create map of canned responses and set up the test HTML server. | 165 // Create map of canned responses and set up the test HTML server. |
| 136 std::map<GURL, std::string> responses; | 166 std::map<GURL, std::string> responses; |
| 137 GURL initialURL = | 167 GURL initialURL = |
| 138 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); | 168 web::test::HttpServer::MakeUrl("http://contextMenuDisabledByWebkit"); |
| 139 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); | 169 GURL destinationURL = web::test::HttpServer::MakeUrl("http://destination"); |
| 140 // The initial page contains a link to the destination URL that has an | 170 // The initial page contains a link to the destination URL that has an |
| 141 // ancestor that disables the context menu via -webkit-touch-callout. | 171 // ancestor that disables the context menu via -webkit-touch-callout. |
| 142 std::string linkID = "link"; | 172 std::string linkID = "link"; |
| 143 responses[initialURL] = | 173 responses[initialURL] = |
| 144 "<body style='-webkit-touch-callout: none'>" | 174 "<body style='-webkit-touch-callout: none'>" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 163 | 193 |
| 164 // Dismiss the context menu. | 194 // Dismiss the context menu. |
| 165 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")] | 195 [[EarlGrey selectElementWithMatcher:elementToDismissContextMenu(@"Cancel")] |
| 166 performAction:grey_tap()]; | 196 performAction:grey_tap()]; |
| 167 | 197 |
| 168 // Context menu should go away after the tap. | 198 // Context menu should go away after the tap. |
| 169 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; | 199 [[EarlGrey selectElementWithMatcher:copyItem] assertWithMatcher:grey_nil()]; |
| 170 } | 200 } |
| 171 | 201 |
| 172 @end | 202 @end |
| OLD | NEW |