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

Side by Side Diff: ios/chrome/browser/ui/fullscreen_egtest.mm

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: better formatting Created 3 years, 8 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
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 <EarlGrey/EarlGrey.h> 5 #import <EarlGrey/EarlGrey.h>
6 #import <UIKit/UIKit.h> 6 #import <UIKit/UIKit.h>
7 #import <XCTest/XCTest.h> 7 #import <XCTest/XCTest.h>
8 8
9 #include "base/ios/ios_util.h" 9 #include "base/ios/ios_util.h"
10 #include "base/mac/bind_objc_block.h" 10 #include "base/mac/bind_objc_block.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 NSError* error = nil; 70 NSError* error = nil;
71 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( 71 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
72 expectedURL.GetContent())] 72 expectedURL.GetContent())]
73 assertWithMatcher:grey_notNil() 73 assertWithMatcher:grey_notNil()
74 error:&error]; 74 error:&error];
75 return (error == nil); 75 return (error == nil);
76 }; 76 };
77 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, condition), description); 77 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, condition), description);
78 } 78 }
79 79
80 // Asserts that the current web view containers contains |text|.
81 void AssertStringIsPresentOnPage(const std::string& text) {
82 id<GREYMatcher> response_matcher =
83 chrome_test_util::WebViewContainingText(text);
84 [[EarlGrey selectElementWithMatcher:response_matcher]
85 assertWithMatcher:grey_notNil()];
86 }
87
88 } // namespace 80 } // namespace
89 81
90 #pragma mark - Tests 82 #pragma mark - Tests
91 83
92 // Fullscreens tests for Chrome. 84 // Fullscreens tests for Chrome.
93 @interface FullscreenTestCase : ChromeTestCase 85 @interface FullscreenTestCase : ChromeTestCase
94 86
95 @end 87 @end
96 88
97 @implementation FullscreenTestCase 89 @implementation FullscreenTestCase
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 // Test that the toolbar is hidden after a user swipes up. 150 // Test that the toolbar is hidden after a user swipes up.
159 HideToolbarUsingUI(); 151 HideToolbarUsingUI();
160 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 152 [ChromeEarlGreyUI waitForToolbarVisible:NO];
161 } 153 }
162 154
163 // Tests that link clicks from a chrome:// to chrome:// link result in the 155 // Tests that link clicks from a chrome:// to chrome:// link result in the
164 // header being shown even if was not previously shown. 156 // header being shown even if was not previously shown.
165 - (void)testChromeToChromeURLKeepsHeaderOnScreen { 157 - (void)testChromeToChromeURLKeepsHeaderOnScreen {
166 const GURL kChromeAboutURL("chrome://chrome-urls"); 158 const GURL kChromeAboutURL("chrome://chrome-urls");
167 [ChromeEarlGrey loadURL:kChromeAboutURL]; 159 [ChromeEarlGrey loadURL:kChromeAboutURL];
168 160 [ChromeEarlGrey waitForWebViewContainingText:@"chrome://version"];
169 AssertStringIsPresentOnPage("chrome://version");
170 161
171 // Hide the toolbar. The page is not long enough to dismiss the toolbar using 162 // Hide the toolbar. The page is not long enough to dismiss the toolbar using
172 // the UI so we have to zoom in. 163 // the UI so we have to zoom in.
173 const char script[] = 164 const char script[] =
174 "(function(){" 165 "(function(){"
175 "var metas = document.getElementsByTagName('meta');" 166 "var metas = document.getElementsByTagName('meta');"
176 "for (var i=0; i<metas.length; i++) {" 167 "for (var i=0; i<metas.length; i++) {"
177 " if (metas[i].getAttribute('name') == 'viewport') {" 168 " if (metas[i].getAttribute('name') == 'viewport') {"
178 " metas[i].setAttribute('content', 'width=10');" 169 " metas[i].setAttribute('content', 'width=10');"
179 " return;" 170 " return;"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 std::map<GURL, std::string> responses; 229 std::map<GURL, std::string> responses;
239 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); 230 const GURL URL = web::test::HttpServer::MakeUrl("http://origin");
240 // This is a tall page -- necessary to make sure scrolling can hide away the 231 // This is a tall page -- necessary to make sure scrolling can hide away the
241 // toolbar safely-- and with a link to reload itself. 232 // toolbar safely-- and with a link to reload itself.
242 responses[URL] = 233 responses[URL] =
243 "<p style='height:200em'>Tall page</p>" 234 "<p style='height:200em'>Tall page</p>"
244 "<a onclick='window.location.reload();' id='link'>link</a>"; 235 "<a onclick='window.location.reload();' id='link'>link</a>";
245 web::test::SetUpSimpleHttpServer(responses); 236 web::test::SetUpSimpleHttpServer(responses);
246 237
247 [ChromeEarlGrey loadURL:URL]; 238 [ChromeEarlGrey loadURL:URL];
248 AssertStringIsPresentOnPage("Tall page"); 239 [ChromeEarlGrey waitForWebViewContainingText:@"Tall page"];
249 240
250 // Hide the toolbar. 241 // Hide the toolbar.
251 HideToolbarUsingUI(); 242 HideToolbarUsingUI();
252 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 243 [ChromeEarlGreyUI waitForToolbarVisible:NO];
253 244
254 chrome_test_util::TapWebViewElementWithId("link"); 245 chrome_test_util::TapWebViewElementWithId("link");
255 246
256 // Main test is here: Make sure the header is still visible! 247 // Main test is here: Make sure the header is still visible!
257 [ChromeEarlGreyUI waitForToolbarVisible:YES]; 248 [ChromeEarlGreyUI waitForToolbarVisible:YES];
258 } 249 }
(...skipping 19 matching lines...) Expand all
278 javaScript = "window.close()"; 269 javaScript = "window.close()";
279 responses[destinationURL] = base::StringPrintf( 270 responses[destinationURL] = base::StringPrintf(
280 "<p style='height:200em'>whatever</p><a onclick='%s' " 271 "<p style='height:200em'>whatever</p><a onclick='%s' "
281 "id='link2'>link2</a>", 272 "id='link2'>link2</a>",
282 javaScript.c_str()); 273 javaScript.c_str());
283 274
284 web::test::SetUpSimpleHttpServer(responses); 275 web::test::SetUpSimpleHttpServer(responses);
285 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW); 276 chrome_test_util::SetContentSettingsBlockPopups(CONTENT_SETTING_ALLOW);
286 277
287 [ChromeEarlGrey loadURL:URL]; 278 [ChromeEarlGrey loadURL:URL];
288 AssertStringIsPresentOnPage("link1"); 279 [ChromeEarlGrey waitForWebViewContainingText:@"link1"];
289 chrome_test_util::AssertMainTabCount(1); 280 chrome_test_util::AssertMainTabCount(1);
290 281
291 // Hide the toolbar. 282 // Hide the toolbar.
292 HideToolbarUsingUI(); 283 HideToolbarUsingUI();
293 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 284 [ChromeEarlGreyUI waitForToolbarVisible:NO];
294 285
295 // Open new window. 286 // Open new window.
296 chrome_test_util::TapWebViewElementWithId("link1"); 287 chrome_test_util::TapWebViewElementWithId("link1");
297 288
298 // Check that a new Tab was created. 289 // Check that a new Tab was created.
299 AssertStringIsPresentOnPage("link2"); 290 [ChromeEarlGrey waitForWebViewContainingText:@"link2"];
300 chrome_test_util::AssertMainTabCount(2); 291 chrome_test_util::AssertMainTabCount(2);
301 292
302 AssertURLIs(destinationURL); 293 AssertURLIs(destinationURL);
303 294
304 // Hide the toolbar. 295 // Hide the toolbar.
305 HideToolbarUsingUI(); 296 HideToolbarUsingUI();
306 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 297 [ChromeEarlGreyUI waitForToolbarVisible:NO];
307 298
308 // Close the tab. 299 // Close the tab.
309 chrome_test_util::TapWebViewElementWithId("link2"); 300 chrome_test_util::TapWebViewElementWithId("link2");
310 AssertStringIsPresentOnPage("link1"); 301 [ChromeEarlGrey waitForWebViewContainingText:@"link1"];
311 302
312 // Make sure the toolbar is on the screen. 303 // Make sure the toolbar is on the screen.
313 chrome_test_util::AssertMainTabCount(1); 304 chrome_test_util::AssertMainTabCount(1);
314 [ChromeEarlGreyUI waitForToolbarVisible:YES]; 305 [ChromeEarlGreyUI waitForToolbarVisible:YES];
315 } 306 }
316 307
317 // Tests that the header is shown when a regular page (non-native page) is 308 // Tests that the header is shown when a regular page (non-native page) is
318 // loaded from a page where the header was not see before. 309 // loaded from a page where the header was not see before.
319 // Also tests that auto-hide works correctly on new page loads. 310 // Also tests that auto-hide works correctly on new page loads.
320 - (void)testShowHeaderOnRegularPageLoad { 311 - (void)testShowHeaderOnRegularPageLoad {
(...skipping 10 matching lines...) Expand all
331 "' id='link1'>link1</a>"; 322 "' id='link1'>link1</a>";
332 // A long page representing many lines and a link to go back. 323 // A long page representing many lines and a link to go back.
333 responses[destinationURL] = manyLines + 324 responses[destinationURL] = manyLines +
334 "<a href='javascript:void(0)' " 325 "<a href='javascript:void(0)' "
335 "onclick='window.history.back()' " 326 "onclick='window.history.back()' "
336 "id='link2'>link2</a>"; 327 "id='link2'>link2</a>";
337 web::test::SetUpSimpleHttpServer(responses); 328 web::test::SetUpSimpleHttpServer(responses);
338 329
339 [ChromeEarlGrey loadURL:originURL]; 330 [ChromeEarlGrey loadURL:originURL];
340 331
341 AssertStringIsPresentOnPage("link1"); 332 [ChromeEarlGrey waitForWebViewContainingText:@"link1"];
342 // Dismiss the toolbar. 333 // Dismiss the toolbar.
343 HideToolbarUsingUI(); 334 HideToolbarUsingUI();
344 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 335 [ChromeEarlGreyUI waitForToolbarVisible:NO];
345 336
346 // Navigate to the other page. 337 // Navigate to the other page.
347 chrome_test_util::TapWebViewElementWithId("link1"); 338 chrome_test_util::TapWebViewElementWithId("link1");
348 AssertStringIsPresentOnPage("link2"); 339 [ChromeEarlGrey waitForWebViewContainingText:@"link2"];
349 340
350 // Make sure toolbar is shown since a new load has started. 341 // Make sure toolbar is shown since a new load has started.
351 [ChromeEarlGreyUI waitForToolbarVisible:YES]; 342 [ChromeEarlGreyUI waitForToolbarVisible:YES];
352 343
353 // Dismiss the toolbar. 344 // Dismiss the toolbar.
354 HideToolbarUsingUI(); 345 HideToolbarUsingUI();
355 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 346 [ChromeEarlGreyUI waitForToolbarVisible:NO];
356 347
357 // Go back. 348 // Go back.
358 chrome_test_util::TapWebViewElementWithId("link2"); 349 chrome_test_util::TapWebViewElementWithId("link2");
359 350
360 // Make sure the toolbar has loaded now that a new page has loaded. 351 // Make sure the toolbar has loaded now that a new page has loaded.
361 [ChromeEarlGreyUI waitForToolbarVisible:YES]; 352 [ChromeEarlGreyUI waitForToolbarVisible:YES];
362 } 353 }
363 354
364 // Tests that the header is shown when a native page is loaded from a page where 355 // Tests that the header is shown when a native page is loaded from a page where
365 // the header was not seen before. 356 // the header was not seen before.
366 - (void)testShowHeaderOnNativePageLoad { 357 - (void)testShowHeaderOnNativePageLoad {
367 std::map<GURL, std::string> responses; 358 std::map<GURL, std::string> responses;
368 const GURL URL = web::test::HttpServer::MakeUrl("http://origin"); 359 const GURL URL = web::test::HttpServer::MakeUrl("http://origin");
369 360
370 // A long page representing many lines and a link to go back. 361 // A long page representing many lines and a link to go back.
371 std::string manyLines = 362 std::string manyLines =
372 "<p style='height:100em'>a</p>" 363 "<p style='height:100em'>a</p>"
373 "<a onclick='window.history.back()' id='link'>link</a>"; 364 "<a onclick='window.history.back()' id='link'>link</a>";
374 responses[URL] = manyLines; 365 responses[URL] = manyLines;
375 web::test::SetUpSimpleHttpServer(responses); 366 web::test::SetUpSimpleHttpServer(responses);
376 367
377 [ChromeEarlGrey loadURL:URL]; 368 [ChromeEarlGrey loadURL:URL];
378 AssertStringIsPresentOnPage("link"); 369 [ChromeEarlGrey waitForWebViewContainingText:@"link"];
379 370
380 // Dismiss the toolbar. 371 // Dismiss the toolbar.
381 HideToolbarUsingUI(); 372 HideToolbarUsingUI();
382 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 373 [ChromeEarlGreyUI waitForToolbarVisible:NO];
383 374
384 // Go back to NTP, which is a native view. 375 // Go back to NTP, which is a native view.
385 chrome_test_util::TapWebViewElementWithId("link"); 376 chrome_test_util::TapWebViewElementWithId("link");
386 377
387 // Make sure the toolbar is visible now that a new page has loaded. 378 // Make sure the toolbar is visible now that a new page has loaded.
388 [ChromeEarlGreyUI waitForToolbarVisible:YES]; 379 [ChromeEarlGreyUI waitForToolbarVisible:YES];
(...skipping 17 matching lines...) Expand all
406 [ChromeEarlGrey loadURL:URL]; 397 [ChromeEarlGrey loadURL:URL];
407 HideToolbarUsingUI(); 398 HideToolbarUsingUI();
408 [ChromeEarlGreyUI waitForToolbarVisible:NO]; 399 [ChromeEarlGreyUI waitForToolbarVisible:NO];
409 400
410 chrome_test_util::TapWebViewElementWithId("link"); 401 chrome_test_util::TapWebViewElementWithId("link");
411 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl()); 402 AssertURLIs(ErrorPageResponseProvider::GetDnsFailureUrl());
412 [ChromeEarlGreyUI waitForToolbarVisible:YES]; 403 [ChromeEarlGreyUI waitForToolbarVisible:YES];
413 } 404 }
414 405
415 @end 406 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698