| 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 |
| 11 #include "base/strings/sys_string_conversions.h" | |
| 12 #import "ios/web/public/test/http_server/http_server.h" | 11 #import "ios/web/public/test/http_server/http_server.h" |
| 13 #include "ios/web/public/test/http_server/http_server_util.h" | 12 #include "ios/web/public/test/http_server/http_server_util.h" |
| 14 #include "ios/web/shell/test/app/web_view_interaction_test_util.h" | 13 #include "ios/web/shell/test/app/web_view_interaction_test_util.h" |
| 15 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" | 14 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h" |
| 16 #import "ios/web/shell/test/earl_grey/shell_matchers.h" | 15 #import "ios/web/shell/test/earl_grey/shell_matchers.h" |
| 17 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" | 16 #import "ios/web/shell/test/earl_grey/web_shell_test_case.h" |
| 18 | 17 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." | 19 #error "This file requires ARC support." |
| 21 #endif | 20 #endif |
| (...skipping 20 matching lines...) Expand all Loading... |
| 42 | 41 |
| 43 [[EarlGrey selectElementWithMatcher:web::AddressFieldText("about:blank")] | 42 [[EarlGrey selectElementWithMatcher:web::AddressFieldText("about:blank")] |
| 44 assertWithMatcher:grey_notNil()]; | 43 assertWithMatcher:grey_notNil()]; |
| 45 } | 44 } |
| 46 | 45 |
| 47 // Tests the back and forward button after entering two URLs. | 46 // Tests the back and forward button after entering two URLs. |
| 48 - (void)testNavigationBackAndForward { | 47 - (void)testNavigationBackAndForward { |
| 49 // Create map of canned responses and set up the test HTML server. | 48 // Create map of canned responses and set up the test HTML server. |
| 50 std::map<GURL, std::string> responses; | 49 std::map<GURL, std::string> responses; |
| 51 const GURL URL1 = web::test::HttpServer::MakeUrl("http://firstURL"); | 50 const GURL URL1 = web::test::HttpServer::MakeUrl("http://firstURL"); |
| 52 std::string response1 = "Test Page 1"; | 51 const char response1[] = "Test Page 1"; |
| 53 responses[URL1] = response1; | 52 responses[URL1] = response1; |
| 54 | 53 |
| 55 const GURL URL2 = web::test::HttpServer::MakeUrl("http://secondURL"); | 54 const GURL URL2 = web::test::HttpServer::MakeUrl("http://secondURL"); |
| 56 std::string response2 = "Test Page 2"; | 55 const char response2[] = "Test Page 2"; |
| 57 responses[URL2] = response2; | 56 responses[URL2] = response2; |
| 58 | 57 |
| 59 web::test::SetUpSimpleHttpServer(responses); | 58 web::test::SetUpSimpleHttpServer(responses); |
| 60 | 59 |
| 61 [ShellEarlGrey loadURL:URL1]; | 60 [ShellEarlGrey loadURL:URL1]; |
| 62 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL1.spec())] | 61 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL1.spec())] |
| 63 assertWithMatcher:grey_notNil()]; | 62 assertWithMatcher:grey_notNil()]; |
| 64 [[EarlGrey selectElementWithMatcher:web::WebViewContainingText(response1)] | 63 [ShellEarlGrey waitForWebViewContainingText:response1]; |
| 65 assertWithMatcher:grey_notNil()]; | |
| 66 | 64 |
| 67 [ShellEarlGrey loadURL:URL2]; | 65 [ShellEarlGrey loadURL:URL2]; |
| 68 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] | 66 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] |
| 69 assertWithMatcher:grey_notNil()]; | 67 assertWithMatcher:grey_notNil()]; |
| 70 [[EarlGrey selectElementWithMatcher:web::WebViewContainingText(response2)] | 68 [ShellEarlGrey waitForWebViewContainingText:response2]; |
| 71 assertWithMatcher:grey_notNil()]; | |
| 72 | 69 |
| 73 [[EarlGrey selectElementWithMatcher:web::BackButton()] | 70 [[EarlGrey selectElementWithMatcher:web::BackButton()] |
| 74 performAction:grey_tap()]; | 71 performAction:grey_tap()]; |
| 75 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL1.spec())] | 72 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL1.spec())] |
| 76 assertWithMatcher:grey_notNil()]; | 73 assertWithMatcher:grey_notNil()]; |
| 77 [[EarlGrey selectElementWithMatcher:web::WebViewContainingText(response1)] | 74 [ShellEarlGrey waitForWebViewContainingText:response1]; |
| 78 assertWithMatcher:grey_notNil()]; | |
| 79 | 75 |
| 80 [[EarlGrey selectElementWithMatcher:web::ForwardButton()] | 76 [[EarlGrey selectElementWithMatcher:web::ForwardButton()] |
| 81 performAction:grey_tap()]; | 77 performAction:grey_tap()]; |
| 82 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] | 78 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] |
| 83 assertWithMatcher:grey_notNil()]; | 79 assertWithMatcher:grey_notNil()]; |
| 84 [[EarlGrey selectElementWithMatcher:web::WebViewContainingText(response2)] | 80 [ShellEarlGrey waitForWebViewContainingText:response2]; |
| 85 assertWithMatcher:grey_notNil()]; | |
| 86 } | 81 } |
| 87 | 82 |
| 88 // Tests back and forward navigation where a fragment link is tapped. | 83 // Tests back and forward navigation where a fragment link is tapped. |
| 89 - (void)testNavigationBackAndForwardAfterFragmentLink { | 84 - (void)testNavigationBackAndForwardAfterFragmentLink { |
| 90 // Create map of canned responses and set up the test HTML server. | 85 // Create map of canned responses and set up the test HTML server. |
| 91 std::map<GURL, std::string> responses; | 86 std::map<GURL, std::string> responses; |
| 92 const GURL URL1 = web::test::HttpServer::MakeUrl("http://fragmentLink"); | 87 const GURL URL1 = web::test::HttpServer::MakeUrl("http://fragmentLink"); |
| 93 const std::string response = "<a href='#hash' id='link'>link</a>"; | 88 const std::string response = "<a href='#hash' id='link'>link</a>"; |
| 94 responses[URL1] = response; | 89 responses[URL1] = response; |
| 95 | 90 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 web::test::SetUpSimpleHttpServer(responses); | 131 web::test::SetUpSimpleHttpServer(responses); |
| 137 | 132 |
| 138 [ShellEarlGrey loadURL:URL]; | 133 [ShellEarlGrey loadURL:URL]; |
| 139 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 134 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 140 assertWithMatcher:grey_notNil()]; | 135 assertWithMatcher:grey_notNil()]; |
| 141 | 136 |
| 142 web::shell_test_util::TapWebViewElementWithId("overrides-href"); | 137 web::shell_test_util::TapWebViewElementWithId("overrides-href"); |
| 143 | 138 |
| 144 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 139 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 145 assertWithMatcher:grey_notNil()]; | 140 assertWithMatcher:grey_notNil()]; |
| 146 [[EarlGrey | 141 [ShellEarlGrey waitForWebViewContainingText:"Default prevented!"]; |
| 147 selectElementWithMatcher:web::WebViewContainingText("Default prevented!")] | |
| 148 assertWithMatcher:grey_notNil()]; | |
| 149 } | 142 } |
| 150 | 143 |
| 151 // Tests tapping on a link with unsupported URL scheme. | 144 // Tests tapping on a link with unsupported URL scheme. |
| 152 - (void)testNavigationUnsupportedSchema { | 145 - (void)testNavigationUnsupportedSchema { |
| 153 // Create map of canned responses and set up the test HTML server. | 146 // Create map of canned responses and set up the test HTML server. |
| 154 std::map<GURL, std::string> responses; | 147 std::map<GURL, std::string> responses; |
| 155 const GURL URL = | 148 const GURL URL = |
| 156 web::test::HttpServer::MakeUrl("http://urlWithUnsupportedSchemeLink"); | 149 web::test::HttpServer::MakeUrl("http://urlWithUnsupportedSchemeLink"); |
| 157 const char pageHTML[] = | 150 const char pageHTML[] = |
| 158 "<script>" | 151 "<script>" |
| 159 " function printMsg() {" | 152 " function printMsg() {" |
| 160 " document.body.appendChild(document.createTextNode(" | 153 " document.body.appendChild(document.createTextNode(" |
| 161 " 'No navigation!'));" | 154 " 'No navigation!'));" |
| 162 " }" | 155 " }" |
| 163 "</script>" | 156 "</script>" |
| 164 "<a href='aaa://unsupported' id='link' " | 157 "<a href='aaa://unsupported' id='link' " |
| 165 "onclick='printMsg();'>unsupportedScheme</a>"; | 158 "onclick='printMsg();'>unsupportedScheme</a>"; |
| 166 responses[URL] = pageHTML; | 159 responses[URL] = pageHTML; |
| 167 | 160 |
| 168 web::test::SetUpSimpleHttpServer(responses); | 161 web::test::SetUpSimpleHttpServer(responses); |
| 169 | 162 |
| 170 [ShellEarlGrey loadURL:URL]; | 163 [ShellEarlGrey loadURL:URL]; |
| 171 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 164 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 172 assertWithMatcher:grey_notNil()]; | 165 assertWithMatcher:grey_notNil()]; |
| 173 | 166 |
| 174 web::shell_test_util::TapWebViewElementWithId("link"); | 167 web::shell_test_util::TapWebViewElementWithId("link"); |
| 175 | 168 |
| 176 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 169 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 177 assertWithMatcher:grey_notNil()]; | 170 assertWithMatcher:grey_notNil()]; |
| 178 [[EarlGrey | 171 [ShellEarlGrey waitForWebViewContainingText:"No navigation!"]; |
| 179 selectElementWithMatcher:web::WebViewContainingText("No navigation!")] | |
| 180 assertWithMatcher:grey_notNil()]; | |
| 181 } | 172 } |
| 182 | 173 |
| 183 @end | 174 @end |
| OLD | NEW |