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

Side by Side Diff: ios/web/test/web_test.mm

Issue 1874903003: Reversed WebState <-> CRWWebController ownership. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged with origin/master Created 4 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
« no previous file with comments | « ios/web/test/web_test.h ('k') | ios/web/web_state/ui/crw_web_controller.h » ('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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/test/web_test.h" 5 #import "ios/web/test/web_test.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #pragma mark - 61 #pragma mark -
62 62
63 WebTestWithWebController::WebTestWithWebController() {} 63 WebTestWithWebController::WebTestWithWebController() {}
64 64
65 WebTestWithWebController::~WebTestWithWebController() {} 65 WebTestWithWebController::~WebTestWithWebController() {}
66 66
67 static int s_html_load_count; 67 static int s_html_load_count;
68 68
69 void WebTestWithWebController::SetUp() { 69 void WebTestWithWebController::SetUp() {
70 WebTest::SetUp(); 70 WebTest::SetUp();
71 webController_.reset(this->CreateWebController()); 71 web_state_impl_.reset(new WebStateImpl(GetBrowserState()));
72 web_state_impl_->GetNavigationManagerImpl().InitializeSession(nil, nil, NO,
73 0);
74 webController_.reset(web_state_impl_->GetWebController());
72 75
73 [webController_ setWebUsageEnabled:YES]; 76 [webController_ setWebUsageEnabled:YES];
74 // Force generation of child views; necessary for some tests. 77 // Force generation of child views; necessary for some tests.
75 [webController_ triggerPendingLoad]; 78 [webController_ triggerPendingLoad];
76 s_html_load_count = 0; 79 s_html_load_count = 0;
77 } 80 }
78 81
79 void WebTestWithWebController::TearDown() { 82 void WebTestWithWebController::TearDown() {
80 [webController_ close]; 83 web_state_impl_.reset();
81 WebTest::TearDown(); 84 WebTest::TearDown();
82 } 85 }
83 86
84 void WebTestWithWebController::LoadHtml(NSString* html) { 87 void WebTestWithWebController::LoadHtml(NSString* html) {
85 LoadHtml([html UTF8String]); 88 LoadHtml([html UTF8String]);
86 } 89 }
87 90
88 void WebTestWithWebController::LoadHtml(const std::string& html) { 91 void WebTestWithWebController::LoadHtml(const std::string& html) {
89 NSString* load_check = CreateLoadCheck(); 92 NSString* load_check = CreateLoadCheck();
90 std::string marked_html = html + [load_check UTF8String]; 93 std::string marked_html = html + [load_check UTF8String];
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 stringResultHandler:^(NSString* result, NSError*) { 172 stringResultHandler:^(NSString* result, NSError*) {
170 DCHECK([result isKindOfClass:[NSString class]]); 173 DCHECK([result isKindOfClass:[NSString class]]);
171 evaluationResult.reset([result copy]); 174 evaluationResult.reset([result copy]);
172 }]; 175 }];
173 base::test::ios::WaitUntilCondition(^bool() { 176 base::test::ios::WaitUntilCondition(^bool() {
174 return evaluationResult; 177 return evaluationResult;
175 }); 178 });
176 return [[evaluationResult retain] autorelease]; 179 return [[evaluationResult retain] autorelease];
177 } 180 }
178 181
179 CRWWebController* WebTestWithWebController::CreateWebController() {
180 std::unique_ptr<WebStateImpl> web_state_impl(
181 new WebStateImpl(GetBrowserState()));
182 return [[CRWWKWebViewWebController alloc]
183 initWithWebState:std::move(web_state_impl)];
184 }
185
186 void WebTestWithWebController::WillProcessTask( 182 void WebTestWithWebController::WillProcessTask(
187 const base::PendingTask& pending_task) { 183 const base::PendingTask& pending_task) {
188 // Nothing to do. 184 // Nothing to do.
189 } 185 }
190 186
191 void WebTestWithWebController::DidProcessTask( 187 void WebTestWithWebController::DidProcessTask(
192 const base::PendingTask& pending_task) { 188 const base::PendingTask& pending_task) {
193 processed_a_task_ = true; 189 processed_a_task_ = true;
194 } 190 }
195 191
196 bool WebTestWithWebController::ResetPageIfNavigationStalled( 192 bool WebTestWithWebController::ResetPageIfNavigationStalled(
197 NSString* load_check) { 193 NSString* load_check) {
198 NSString* inner_html = RunJavaScript( 194 NSString* inner_html = RunJavaScript(
199 @"(document && document.body && document.body.innerHTML) || 'undefined'"); 195 @"(document && document.body && document.body.innerHTML) || 'undefined'");
200 if ([inner_html rangeOfString:load_check].location == NSNotFound) { 196 if ([inner_html rangeOfString:load_check].location == NSNotFound) {
201 [webController_ setWebUsageEnabled:NO]; 197 [webController_ setWebUsageEnabled:NO];
202 [webController_ setWebUsageEnabled:YES]; 198 [webController_ setWebUsageEnabled:YES];
203 [webController_ triggerPendingLoad]; 199 [webController_ triggerPendingLoad];
204 return true; 200 return true;
205 } 201 }
206 return false; 202 return false;
207 } 203 }
208 204
209 NSString* WebTestWithWebController::CreateLoadCheck() { 205 NSString* WebTestWithWebController::CreateLoadCheck() {
210 return [NSString stringWithFormat:@"<p style=\"display: none;\">%d</p>", 206 return [NSString stringWithFormat:@"<p style=\"display: none;\">%d</p>",
211 s_html_load_count++]; 207 s_html_load_count++];
212 } 208 }
213 209
214 } // namespace web 210 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/test/web_test.h ('k') | ios/web/web_state/ui/crw_web_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698