| OLD | NEW |
| (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 <UIKit/UIKit.h> | |
| 6 #import <WebKit/WebKit.h> | |
| 7 #import <XCTest/XCTest.h> | |
| 8 | |
| 9 #import <EarlGrey/EarlGrey.h> | |
| 10 | |
| 11 #include "base/strings/sys_string_conversions.h" | |
| 12 #import "ios/web/public/test/http_server.h" | |
| 13 #include "ios/web/public/test/http_server_util.h" | |
| 14 #include "ios/web/shell/test/app/navigation_test_util.h" | |
| 15 #include "ios/web/shell/test/app/web_view_interaction_test_util.h" | |
| 16 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h" | |
| 17 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | |
| 18 | |
| 19 // Navigation test cases for the web shell. These are Earl Grey integration | |
| 20 // tests, which are based on XCTest. | |
| 21 @interface CRWWebShellNavigationTest : ShellBaseTestCase | |
| 22 | |
| 23 @end | |
| 24 | |
| 25 @implementation CRWWebShellNavigationTest | |
| 26 | |
| 27 // Tests clicking a link to about:blank. | |
| 28 - (void)testNavigationLinkToAboutBlank { | |
| 29 const GURL URL = web::test::HttpServer::MakeUrl( | |
| 30 "http://ios/web/shell/test/http_server_files/basic_navigation_test.html"); | |
| 31 web::test::SetUpFileBasedHttpServer(); | |
| 32 | |
| 33 web::shell_test_util::LoadUrl(URL); | |
| 34 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL.spec())] | |
| 35 assertWithMatcher:grey_notNil()]; | |
| 36 | |
| 37 web::shell_test_util::TapWebViewElementWithId( | |
| 38 "basic-link-navigation-to-about-blank"); | |
| 39 | |
| 40 [[EarlGrey selectElementWithMatcher:web::addressFieldText("about:blank")] | |
| 41 assertWithMatcher:grey_notNil()]; | |
| 42 } | |
| 43 | |
| 44 // Tests the back and forward button after entering two URLs. | |
| 45 - (void)testNavigationBackAndForward { | |
| 46 // Create map of canned responses and set up the test HTML server. | |
| 47 std::map<GURL, std::string> responses; | |
| 48 const GURL URL1 = web::test::HttpServer::MakeUrl("http://firstURL"); | |
| 49 std::string response1 = "Test Page 1"; | |
| 50 responses[URL1] = response1; | |
| 51 | |
| 52 const GURL URL2 = web::test::HttpServer::MakeUrl("http://secondURL"); | |
| 53 std::string response2 = "Test Page 2"; | |
| 54 responses[URL2] = response2; | |
| 55 | |
| 56 web::test::SetUpSimpleHttpServer(responses); | |
| 57 | |
| 58 web::shell_test_util::LoadUrl(URL1); | |
| 59 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL1.spec())] | |
| 60 assertWithMatcher:grey_notNil()]; | |
| 61 [[EarlGrey selectElementWithMatcher:web::webViewContainingText(response1)] | |
| 62 assertWithMatcher:grey_notNil()]; | |
| 63 | |
| 64 web::shell_test_util::LoadUrl(URL2); | |
| 65 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL2.spec())] | |
| 66 assertWithMatcher:grey_notNil()]; | |
| 67 [[EarlGrey selectElementWithMatcher:web::webViewContainingText(response2)] | |
| 68 assertWithMatcher:grey_notNil()]; | |
| 69 | |
| 70 [[EarlGrey selectElementWithMatcher:web::backButton()] | |
| 71 performAction:grey_tap()]; | |
| 72 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL1.spec())] | |
| 73 assertWithMatcher:grey_notNil()]; | |
| 74 [[EarlGrey selectElementWithMatcher:web::webViewContainingText(response1)] | |
| 75 assertWithMatcher:grey_notNil()]; | |
| 76 | |
| 77 [[EarlGrey selectElementWithMatcher:web::forwardButton()] | |
| 78 performAction:grey_tap()]; | |
| 79 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL2.spec())] | |
| 80 assertWithMatcher:grey_notNil()]; | |
| 81 [[EarlGrey selectElementWithMatcher:web::webViewContainingText(response2)] | |
| 82 assertWithMatcher:grey_notNil()]; | |
| 83 } | |
| 84 | |
| 85 // Tests back and forward navigation where a fragment link is tapped. | |
| 86 - (void)testNavigationBackAndForwardAfterFragmentLink { | |
| 87 // Create map of canned responses and set up the test HTML server. | |
| 88 std::map<GURL, std::string> responses; | |
| 89 const GURL URL1 = web::test::HttpServer::MakeUrl("http://fragmentLink"); | |
| 90 const std::string response = "<a href='#hash' id='link'>link</a>"; | |
| 91 responses[URL1] = response; | |
| 92 | |
| 93 const GURL URL2 = web::test::HttpServer::MakeUrl("http://fragmentLink/#hash"); | |
| 94 | |
| 95 web::test::SetUpSimpleHttpServer(responses); | |
| 96 | |
| 97 web::shell_test_util::LoadUrl(URL1); | |
| 98 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL1.spec())] | |
| 99 assertWithMatcher:grey_notNil()]; | |
| 100 | |
| 101 web::shell_test_util::TapWebViewElementWithId("link"); | |
| 102 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL2.spec())] | |
| 103 assertWithMatcher:grey_notNil()]; | |
| 104 | |
| 105 [[EarlGrey selectElementWithMatcher:web::backButton()] | |
| 106 performAction:grey_tap()]; | |
| 107 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL1.spec())] | |
| 108 assertWithMatcher:grey_notNil()]; | |
| 109 | |
| 110 [[EarlGrey selectElementWithMatcher:web::forwardButton()] | |
| 111 performAction:grey_tap()]; | |
| 112 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL2.spec())] | |
| 113 assertWithMatcher:grey_notNil()]; | |
| 114 } | |
| 115 | |
| 116 // Tests tapping a link with onclick="event.preventDefault()" and verifies that | |
| 117 // the URL didn't change.. | |
| 118 - (void)testNavigationLinkPreventDefaultOverridesHref { | |
| 119 // Create map of canned responses and set up the test HTML server. | |
| 120 std::map<GURL, std::string> responses; | |
| 121 const GURL URL = web::test::HttpServer::MakeUrl("http://overridesHrefLink"); | |
| 122 const char pageHTML[] = | |
| 123 "<script>" | |
| 124 " function printMsg() {" | |
| 125 " document.body.appendChild(document.createTextNode('Default " | |
| 126 "prevented!'));" | |
| 127 " }" | |
| 128 "</script>" | |
| 129 "<a href='#hash' id='overrides-href' onclick='event.preventDefault(); " | |
| 130 "printMsg();'>redirectLink</a>"; | |
| 131 responses[URL] = pageHTML; | |
| 132 | |
| 133 web::test::SetUpSimpleHttpServer(responses); | |
| 134 | |
| 135 web::shell_test_util::LoadUrl(URL); | |
| 136 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL.spec())] | |
| 137 assertWithMatcher:grey_notNil()]; | |
| 138 | |
| 139 web::shell_test_util::TapWebViewElementWithId("overrides-href"); | |
| 140 | |
| 141 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL.spec())] | |
| 142 assertWithMatcher:grey_notNil()]; | |
| 143 [[EarlGrey | |
| 144 selectElementWithMatcher:web::webViewContainingText("Default prevented!")] | |
| 145 assertWithMatcher:grey_notNil()]; | |
| 146 } | |
| 147 | |
| 148 // Tests tapping on a link with unsupported URL scheme. | |
| 149 - (void)testNavigationUnsupportedSchema { | |
| 150 // Create map of canned responses and set up the test HTML server. | |
| 151 std::map<GURL, std::string> responses; | |
| 152 const GURL URL = | |
| 153 web::test::HttpServer::MakeUrl("http://urlWithUnsupportedSchemeLink"); | |
| 154 const char pageHTML[] = | |
| 155 "<script>" | |
| 156 " function printMsg() {" | |
| 157 " document.body.appendChild(document.createTextNode(" | |
| 158 " 'No navigation!'));" | |
| 159 " }" | |
| 160 "</script>" | |
| 161 "<a href='aaa://unsupported' id='link' " | |
| 162 "onclick='printMsg();'>unsupportedScheme</a>"; | |
| 163 responses[URL] = pageHTML; | |
| 164 | |
| 165 web::test::SetUpSimpleHttpServer(responses); | |
| 166 | |
| 167 web::shell_test_util::LoadUrl(URL); | |
| 168 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL.spec())] | |
| 169 assertWithMatcher:grey_notNil()]; | |
| 170 | |
| 171 web::shell_test_util::TapWebViewElementWithId("link"); | |
| 172 | |
| 173 [[EarlGrey selectElementWithMatcher:web::addressFieldText(URL.spec())] | |
| 174 assertWithMatcher:grey_notNil()]; | |
| 175 [[EarlGrey | |
| 176 selectElementWithMatcher:web::webViewContainingText("No navigation!")] | |
| 177 assertWithMatcher:grey_notNil()]; | |
| 178 } | |
| 179 | |
| 180 @end | |
| OLD | NEW |