| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 NSString* response1 = @"Test Page 1"; |
| 53 responses[URL1] = response1; | 53 responses[URL1] = base::SysNSStringToUTF8(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 NSString* response2 = @"Test Page 2"; |
| 57 responses[URL2] = response2; | 57 responses[URL2] = base::SysNSStringToUTF8(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 [ShellEarlGrey waitForWebViewContainingText:response1]; |
| 65 assertWithMatcher:grey_notNil()]; | |
| 66 | 65 |
| 67 [ShellEarlGrey loadURL:URL2]; | 66 [ShellEarlGrey loadURL:URL2]; |
| 68 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] | 67 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] |
| 69 assertWithMatcher:grey_notNil()]; | 68 assertWithMatcher:grey_notNil()]; |
| 70 [[EarlGrey selectElementWithMatcher:web::WebViewContainingText(response2)] | 69 [ShellEarlGrey waitForWebViewContainingText:response2]; |
| 71 assertWithMatcher:grey_notNil()]; | |
| 72 | 70 |
| 73 [[EarlGrey selectElementWithMatcher:web::BackButton()] | 71 [[EarlGrey selectElementWithMatcher:web::BackButton()] |
| 74 performAction:grey_tap()]; | 72 performAction:grey_tap()]; |
| 75 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL1.spec())] | 73 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL1.spec())] |
| 76 assertWithMatcher:grey_notNil()]; | 74 assertWithMatcher:grey_notNil()]; |
| 77 [[EarlGrey selectElementWithMatcher:web::WebViewContainingText(response1)] | 75 [ShellEarlGrey waitForWebViewContainingText:response1]; |
| 78 assertWithMatcher:grey_notNil()]; | |
| 79 | 76 |
| 80 [[EarlGrey selectElementWithMatcher:web::ForwardButton()] | 77 [[EarlGrey selectElementWithMatcher:web::ForwardButton()] |
| 81 performAction:grey_tap()]; | 78 performAction:grey_tap()]; |
| 82 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] | 79 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL2.spec())] |
| 83 assertWithMatcher:grey_notNil()]; | 80 assertWithMatcher:grey_notNil()]; |
| 84 [[EarlGrey selectElementWithMatcher:web::WebViewContainingText(response2)] | 81 [ShellEarlGrey waitForWebViewContainingText:response2]; |
| 85 assertWithMatcher:grey_notNil()]; | |
| 86 } | 82 } |
| 87 | 83 |
| 88 // Tests back and forward navigation where a fragment link is tapped. | 84 // Tests back and forward navigation where a fragment link is tapped. |
| 89 - (void)testNavigationBackAndForwardAfterFragmentLink { | 85 - (void)testNavigationBackAndForwardAfterFragmentLink { |
| 90 // Create map of canned responses and set up the test HTML server. | 86 // Create map of canned responses and set up the test HTML server. |
| 91 std::map<GURL, std::string> responses; | 87 std::map<GURL, std::string> responses; |
| 92 const GURL URL1 = web::test::HttpServer::MakeUrl("http://fragmentLink"); | 88 const GURL URL1 = web::test::HttpServer::MakeUrl("http://fragmentLink"); |
| 93 const std::string response = "<a href='#hash' id='link'>link</a>"; | 89 const std::string response = "<a href='#hash' id='link'>link</a>"; |
| 94 responses[URL1] = response; | 90 responses[URL1] = response; |
| 95 | 91 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 web::test::SetUpSimpleHttpServer(responses); | 132 web::test::SetUpSimpleHttpServer(responses); |
| 137 | 133 |
| 138 [ShellEarlGrey loadURL:URL]; | 134 [ShellEarlGrey loadURL:URL]; |
| 139 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 135 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 140 assertWithMatcher:grey_notNil()]; | 136 assertWithMatcher:grey_notNil()]; |
| 141 | 137 |
| 142 web::shell_test_util::TapWebViewElementWithId("overrides-href"); | 138 web::shell_test_util::TapWebViewElementWithId("overrides-href"); |
| 143 | 139 |
| 144 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 140 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 145 assertWithMatcher:grey_notNil()]; | 141 assertWithMatcher:grey_notNil()]; |
| 146 [[EarlGrey | 142 [ShellEarlGrey waitForWebViewContainingText:@"Default prevented!"]; |
| 147 selectElementWithMatcher:web::WebViewContainingText("Default prevented!")] | |
| 148 assertWithMatcher:grey_notNil()]; | |
| 149 } | 143 } |
| 150 | 144 |
| 151 // Tests tapping on a link with unsupported URL scheme. | 145 // Tests tapping on a link with unsupported URL scheme. |
| 152 - (void)testNavigationUnsupportedSchema { | 146 - (void)testNavigationUnsupportedSchema { |
| 153 // Create map of canned responses and set up the test HTML server. | 147 // Create map of canned responses and set up the test HTML server. |
| 154 std::map<GURL, std::string> responses; | 148 std::map<GURL, std::string> responses; |
| 155 const GURL URL = | 149 const GURL URL = |
| 156 web::test::HttpServer::MakeUrl("http://urlWithUnsupportedSchemeLink"); | 150 web::test::HttpServer::MakeUrl("http://urlWithUnsupportedSchemeLink"); |
| 157 const char pageHTML[] = | 151 const char pageHTML[] = |
| 158 "<script>" | 152 "<script>" |
| 159 " function printMsg() {" | 153 " function printMsg() {" |
| 160 " document.body.appendChild(document.createTextNode(" | 154 " document.body.appendChild(document.createTextNode(" |
| 161 " 'No navigation!'));" | 155 " 'No navigation!'));" |
| 162 " }" | 156 " }" |
| 163 "</script>" | 157 "</script>" |
| 164 "<a href='aaa://unsupported' id='link' " | 158 "<a href='aaa://unsupported' id='link' " |
| 165 "onclick='printMsg();'>unsupportedScheme</a>"; | 159 "onclick='printMsg();'>unsupportedScheme</a>"; |
| 166 responses[URL] = pageHTML; | 160 responses[URL] = pageHTML; |
| 167 | 161 |
| 168 web::test::SetUpSimpleHttpServer(responses); | 162 web::test::SetUpSimpleHttpServer(responses); |
| 169 | 163 |
| 170 [ShellEarlGrey loadURL:URL]; | 164 [ShellEarlGrey loadURL:URL]; |
| 171 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 165 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 172 assertWithMatcher:grey_notNil()]; | 166 assertWithMatcher:grey_notNil()]; |
| 173 | 167 |
| 174 web::shell_test_util::TapWebViewElementWithId("link"); | 168 web::shell_test_util::TapWebViewElementWithId("link"); |
| 175 | 169 |
| 176 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] | 170 [[EarlGrey selectElementWithMatcher:web::AddressFieldText(URL.spec())] |
| 177 assertWithMatcher:grey_notNil()]; | 171 assertWithMatcher:grey_notNil()]; |
| 178 [[EarlGrey | 172 [ShellEarlGrey waitForWebViewContainingText:@"No navigation!"]; |
| 179 selectElementWithMatcher:web::WebViewContainingText("No navigation!")] | |
| 180 assertWithMatcher:grey_notNil()]; | |
| 181 } | 173 } |
| 182 | 174 |
| 183 @end | 175 @end |
| OLD | NEW |