Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: ios/web/shell/test/navigation_egtest.mm

Issue 2343453002: [ios] Use +[ShellEarlGrey loadURL:] for page loading in EG tests. (Closed)
Patch Set: Rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/web/shell/test/meta_tags_egtest.mm ('k') | ios/web/shell/test/page_state_egtest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 11 #include "base/strings/sys_string_conversions.h"
12 #import "ios/web/public/test/http_server.h" 12 #import "ios/web/public/test/http_server.h"
13 #include "ios/web/public/test/http_server_util.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" 14 #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" 15 #import "ios/web/shell/test/earl_grey/shell_base_test_case.h"
16 #import "ios/web/shell/test/earl_grey/shell_earl_grey.h"
17 #import "ios/web/shell/test/earl_grey/shell_matchers.h" 17 #import "ios/web/shell/test/earl_grey/shell_matchers.h"
18 18
19 #if !defined(__has_feature) || !__has_feature(objc_arc) 19 #if !defined(__has_feature) || !__has_feature(objc_arc)
20 #error "This file requires ARC support." 20 #error "This file requires ARC support."
21 #endif 21 #endif
22 22
23 // Navigation test cases for the web shell. These are Earl Grey integration 23 // Navigation test cases for the web shell. These are Earl Grey integration
24 // tests, which are based on XCTest. 24 // tests, which are based on XCTest.
25 @interface NavigationTestCase : ShellBaseTestCase 25 @interface NavigationTestCase : ShellBaseTestCase
26 @end 26 @end
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 web::shell_test_util::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 web::shell_test_util::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 web::shell_test_util::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)]
(...skipping 12 matching lines...) Expand all
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 web::shell_test_util::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())]
(...skipping 17 matching lines...) Expand all
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 web::shell_test_util::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()];
(...skipping 11 matching lines...) Expand all
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 web::shell_test_util::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
OLDNEW
« no previous file with comments | « ios/web/shell/test/meta_tags_egtest.mm ('k') | ios/web/shell/test/page_state_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698