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

Side by Side Diff: ios/web/public/test/web_test_with_web_state.mm

Issue 2254553003: [ios] Fixed Resetting the page for unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed DCHECK Created 4 years, 4 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 | « no previous file | no next file » | 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 "ios/web/public/test/web_test_with_web_state.h" 5 #import "ios/web/public/test/web_test_with_web_state.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/strings/sys_string_conversions.h" 10 #include "base/strings/sys_string_conversions.h"
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 base::test::ios::WaitUntilCondition(condition, messageLoop, 148 base::test::ios::WaitUntilCondition(condition, messageLoop,
149 base::TimeDelta::FromSeconds(10)); 149 base::TimeDelta::FromSeconds(10));
150 } 150 }
151 151
152 id WebTestWithWebState::ExecuteJavaScript(NSString* script) { 152 id WebTestWithWebState::ExecuteJavaScript(NSString* script) {
153 __block base::scoped_nsprotocol<id> executionResult; 153 __block base::scoped_nsprotocol<id> executionResult;
154 __block bool executionCompleted = false; 154 __block bool executionCompleted = false;
155 [GetWebController(web_state()) 155 [GetWebController(web_state())
156 executeJavaScript:script 156 executeJavaScript:script
157 completionHandler:^(id result, NSError* error) { 157 completionHandler:^(id result, NSError* error) {
158 if (error && error.code != WKErrorJavaScriptResultTypeIsUnsupported) {
159 NOTREACHED() << " error: " << error.code
160 << " for script: " << base::SysNSStringToUTF8(script);
161 }
162 executionResult.reset([result copy]); 158 executionResult.reset([result copy]);
163 executionCompleted = true; 159 executionCompleted = true;
164 }]; 160 }];
165 base::test::ios::WaitUntilCondition(^{ 161 base::test::ios::WaitUntilCondition(^{
166 return executionCompleted; 162 return executionCompleted;
167 }); 163 });
168 return [[executionResult retain] autorelease]; 164 return [[executionResult retain] autorelease];
169 } 165 }
170 166
171 std::string WebTestWithWebState::BaseUrl() const { 167 std::string WebTestWithWebState::BaseUrl() const {
172 web::URLVerificationTrustLevel unused_level; 168 web::URLVerificationTrustLevel unused_level;
173 return web_state()->GetCurrentURL(&unused_level).spec(); 169 return web_state()->GetCurrentURL(&unused_level).spec();
174 } 170 }
175 171
176 web::WebState* WebTestWithWebState::web_state() { 172 web::WebState* WebTestWithWebState::web_state() {
177 return web_state_.get(); 173 return web_state_.get();
178 } 174 }
179 175
180 const web::WebState* WebTestWithWebState::web_state() const { 176 const web::WebState* WebTestWithWebState::web_state() const {
181 return web_state_.get(); 177 return web_state_.get();
182 } 178 }
183 179
184 bool WebTestWithWebState::ResetPageIfNavigationStalled(NSString* load_check) { 180 bool WebTestWithWebState::ResetPageIfNavigationStalled(NSString* load_check) {
185 id inner_html = ExecuteJavaScript( 181 id inner_html = ExecuteJavaScript(
186 @"(document && document.body && document.body.innerHTML) || 'undefined'"); 182 @"(document && document.body && document.body.innerHTML) || 'undefined'");
187 if ([inner_html rangeOfString:load_check].location == NSNotFound) { 183 if (![inner_html rangeOfString:load_check].length) {
188 web_state_->SetWebUsageEnabled(false); 184 web_state_->SetWebUsageEnabled(false);
189 web_state_->SetWebUsageEnabled(true); 185 web_state_->SetWebUsageEnabled(true);
190 [GetWebController(web_state()) triggerPendingLoad]; 186 [GetWebController(web_state()) triggerPendingLoad];
191 return true; 187 return true;
192 } 188 }
193 return false; 189 return false;
194 } 190 }
195 191
196 NSString* WebTestWithWebState::CreateLoadCheck() { 192 NSString* WebTestWithWebState::CreateLoadCheck() {
197 return [NSString stringWithFormat:@"<p style=\"display: none;\">%d</p>", 193 return [NSString stringWithFormat:@"<p style=\"display: none;\">%d</p>",
198 s_html_load_count++]; 194 s_html_load_count++];
199 } 195 }
200 196
201 } // namespace web 197 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698