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