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

Side by Side Diff: ios/chrome/browser/ui/browser_view_controller_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 #include <map> 5 #include <map>
6 6
7 #import <EarlGrey/EarlGrey.h> 7 #import <EarlGrey/EarlGrey.h>
8 #import <WebKit/WebKit.h> 8 #import <WebKit/WebKit.h>
9 #import <XCTest/XCTest.h> 9 #import <XCTest/XCTest.h>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 const GURL destinationURL = 46 const GURL destinationURL =
47 web::test::HttpServer::MakeUrl("http://destination"); 47 web::test::HttpServer::MakeUrl("http://destination");
48 responses[startURL] = "Start"; 48 responses[startURL] = "Start";
49 responses[destinationURL] = "You've arrived!"; 49 responses[destinationURL] = "You've arrived!";
50 web::test::SetUpSimpleHttpServer(responses); 50 web::test::SetUpSimpleHttpServer(responses);
51 51
52 // Just load the first URL. 52 // Just load the first URL.
53 [ChromeEarlGrey loadURL:startURL]; 53 [ChromeEarlGrey loadURL:startURL];
54 54
55 // Waits for the page to load and check it is the expected content. 55 // Waits for the page to load and check it is the expected content.
56 id<GREYMatcher> responseMatcher = 56 NSString* startResponse = base::SysUTF8ToNSString(responses[startURL]);
57 chrome_test_util::WebViewContainingText(responses[startURL]); 57 [ChromeEarlGrey waitForWebViewContainingText:startResponse];
58 [[EarlGrey selectElementWithMatcher:responseMatcher]
59 assertWithMatcher:grey_notNil()];
60 58
61 // In the omnibox, the URL should be present, without the http:// prefix. 59 // In the omnibox, the URL should be present, without the http:// prefix.
62 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 60 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
63 assertWithMatcher:chrome_test_util::OmniboxText(startURL.GetContent())]; 61 assertWithMatcher:chrome_test_util::OmniboxText(startURL.GetContent())];
64 62
65 // Types some javascript in the omnibox to trigger a navigation. 63 // Types some javascript in the omnibox to trigger a navigation.
66 NSString* script = 64 NSString* script =
67 [NSString stringWithFormat:@"javascript:location.href='%s'\n", 65 [NSString stringWithFormat:@"javascript:location.href='%s'\n",
68 destinationURL.spec().c_str()]; 66 destinationURL.spec().c_str()];
69 67
70 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 68 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
71 performAction:grey_typeText(script)]; 69 performAction:grey_typeText(script)];
72 70
73 // In the omnibox, the new URL should be present, without the http:// prefix. 71 // In the omnibox, the new URL should be present, without the http:// prefix.
74 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()] 72 [[EarlGrey selectElementWithMatcher:chrome_test_util::Omnibox()]
75 assertWithMatcher:chrome_test_util::OmniboxText( 73 assertWithMatcher:chrome_test_util::OmniboxText(
76 destinationURL.GetContent())]; 74 destinationURL.GetContent())];
77 75
78 // Verifies that the navigation to the destination page happened. 76 // Verifies that the navigation to the destination page happened.
79 GREYAssertEqual(destinationURL, 77 GREYAssertEqual(destinationURL,
80 chrome_test_util::GetCurrentWebState()->GetVisibleURL(), 78 chrome_test_util::GetCurrentWebState()->GetVisibleURL(),
81 @"Did not navigate to the destination url."); 79 @"Did not navigate to the destination url.");
82 80
83 // Verifies that the destination page is shown. 81 // Verifies that the destination page is shown.
84 id<GREYMatcher> navigationMatcher = 82 NSString* destinationResponse =
85 chrome_test_util::WebViewContainingText(responses[destinationURL]); 83 base::SysUTF8ToNSString(responses[destinationURL]);
86 [[EarlGrey selectElementWithMatcher:grey_kindOfClass([WKWebView class])] 84 [ChromeEarlGrey waitForWebViewContainingText:destinationResponse];
87 assertWithMatcher:navigationMatcher];
88 } 85 }
89 86
90 @end 87 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698