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

Side by Side Diff: ios/chrome/browser/web/browsing_prevent_default_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/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "components/content_settings/core/browser/host_content_settings_map.h" 10 #include "components/content_settings/core/browser/host_content_settings_map.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW); 86 ScopedBlockPopupsPref scoper(CONTENT_SETTING_ALLOW);
87 web::test::SetUpFileBasedHttpServer(); 87 web::test::SetUpFileBasedHttpServer();
88 88
89 const GURL testURL = GetTestUrl(); 89 const GURL testURL = GetTestUrl();
90 [ChromeEarlGrey loadURL:testURL]; 90 [ChromeEarlGrey loadURL:testURL];
91 chrome_test_util::AssertMainTabCount(1U); 91 chrome_test_util::AssertMainTabCount(1U);
92 92
93 // Tap on the test link and wait for the page to display "Click done", as an 93 // Tap on the test link and wait for the page to display "Click done", as an
94 // indicator that the element was tapped. 94 // indicator that the element was tapped.
95 chrome_test_util::TapWebViewElementWithId(linkID); 95 chrome_test_util::TapWebViewElementWithId(linkID);
96 [[GREYCondition 96 [ChromeEarlGrey waitForWebViewContainingText:@"Click done"];
97 conditionWithName:@"Waiting for webview to display 'Click done'."
98 block:^BOOL {
99 id<GREYMatcher> webViewMatcher =
100 chrome_test_util::WebViewContainingText("Click done");
101 NSError* error = nil;
102 [[EarlGrey selectElementWithMatcher:webViewMatcher]
103 assertWithMatcher:grey_notNil()
104 error:&error];
105 return error == nil;
106 }] waitWithTimeout:kConditionTimeout];
107 97
108 // Check that no navigation occurred and no new tabs were opened. 98 // Check that no navigation occurred and no new tabs were opened.
109 chrome_test_util::AssertMainTabCount(1U); 99 chrome_test_util::AssertMainTabCount(1U);
110 const GURL& currentURL = 100 const GURL& currentURL =
111 chrome_test_util::GetCurrentWebState()->GetVisibleURL(); 101 chrome_test_util::GetCurrentWebState()->GetVisibleURL();
112 GREYAssert(currentURL == testURL, @"Page navigated unexpectedly %s", 102 GREYAssert(currentURL == testURL, @"Page navigated unexpectedly %s",
113 currentURL.spec().c_str()); 103 currentURL.spec().c_str());
114 } 104 }
115 105
116 // Taps a link with onclick="event.preventDefault()" and target="_blank" and 106 // Taps a link with onclick="event.preventDefault()" and target="_blank" and
(...skipping 21 matching lines...) Expand all
138 web::test::SetUpFileBasedHttpServer(); 128 web::test::SetUpFileBasedHttpServer();
139 129
140 const GURL testURL = GetTestUrl(); 130 const GURL testURL = GetTestUrl();
141 [ChromeEarlGrey loadURL:testURL]; 131 [ChromeEarlGrey loadURL:testURL];
142 chrome_test_util::AssertMainTabCount(1U); 132 chrome_test_util::AssertMainTabCount(1U);
143 133
144 // Tap on the test link. 134 // Tap on the test link.
145 const std::string linkID = 135 const std::string linkID =
146 "webScenarioBrowsingLinkPreventDefaultOverridesWindowOpen"; 136 "webScenarioBrowsingLinkPreventDefaultOverridesWindowOpen";
147 chrome_test_util::TapWebViewElementWithId(linkID); 137 chrome_test_util::TapWebViewElementWithId(linkID);
148 138 [ChromeEarlGrey waitForWebViewContainingText:@"Click done"];
149 // Stall a bit to make sure the webview doesn't do anything asynchronously.
150 [[GREYCondition
151 conditionWithName:@"Waiting for webview to display 'Click done'."
152 block:^BOOL {
153 id<GREYMatcher> webViewMatcher =
154 chrome_test_util::WebViewContainingText("Click done");
155 NSError* error = nil;
156 [[EarlGrey selectElementWithMatcher:webViewMatcher]
157 assertWithMatcher:grey_notNil()
158 error:&error];
159 return error == nil;
160 }] waitWithTimeout:kConditionTimeout];
161 139
162 // Check that the tab navigated to about:blank and no new tabs were opened. 140 // Check that the tab navigated to about:blank and no new tabs were opened.
163 [[GREYCondition 141 [[GREYCondition
164 conditionWithName:@"Wait for navigation to about:blank" 142 conditionWithName:@"Wait for navigation to about:blank"
165 block:^BOOL { 143 block:^BOOL {
166 const GURL& currentURL = 144 const GURL& currentURL =
167 chrome_test_util::GetCurrentWebState()->GetVisibleURL(); 145 chrome_test_util::GetCurrentWebState()->GetVisibleURL();
168 return currentURL == GURL(url::kAboutBlankURL); 146 return currentURL == GURL(url::kAboutBlankURL);
169 }] waitWithTimeout:kConditionTimeout]; 147 }] waitWithTimeout:kConditionTimeout];
170 chrome_test_util::AssertMainTabCount(1U); 148 chrome_test_util::AssertMainTabCount(1U);
171 } 149 }
172 150
173 @end 151 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698