| OLD | NEW |
| 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 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #import "base/test/ios/wait_util.h" | 9 #import "base/test/ios/wait_util.h" |
| 10 #import "ios/web/navigation/navigation_manager_impl.h" | 10 #import "ios/web/navigation/navigation_manager_impl.h" |
| 11 #include "ios/web/public/web_state/url_verification_constants.h" | 11 #include "ios/web/public/web_state/url_verification_constants.h" |
| 12 #include "ios/web/public/web_state/web_state_observer.h" | 12 #include "ios/web/public/web_state/web_state_observer.h" |
| 13 #import "ios/web/web_state/ui/crw_web_controller.h" | 13 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 14 #import "ios/web/web_state/web_state_impl.h" | 14 #import "ios/web/web_state/web_state_impl.h" |
| 15 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
| 16 namespace { | 20 namespace { |
| 17 // Returns CRWWebController for the given |web_state|. | 21 // Returns CRWWebController for the given |web_state|. |
| 18 CRWWebController* GetWebController(web::WebState* web_state) { | 22 CRWWebController* GetWebController(web::WebState* web_state) { |
| 19 web::WebStateImpl* web_state_impl = | 23 web::WebStateImpl* web_state_impl = |
| 20 static_cast<web::WebStateImpl*>(web_state); | 24 static_cast<web::WebStateImpl*>(web_state); |
| 21 return web_state_impl->GetWebController(); | 25 return web_state_impl->GetWebController(); |
| 22 } | 26 } |
| 23 } // namespace | 27 } // namespace |
| 24 | 28 |
| 25 namespace web { | 29 namespace web { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } while (activitySeen); | 124 } while (activitySeen); |
| 121 messageLoop->RemoveTaskObserver(this); | 125 messageLoop->RemoveTaskObserver(this); |
| 122 } | 126 } |
| 123 | 127 |
| 124 void WebTestWithWebState::WaitForCondition(ConditionBlock condition) { | 128 void WebTestWithWebState::WaitForCondition(ConditionBlock condition) { |
| 125 base::test::ios::WaitUntilCondition(condition, true, | 129 base::test::ios::WaitUntilCondition(condition, true, |
| 126 base::TimeDelta::FromSeconds(10)); | 130 base::TimeDelta::FromSeconds(10)); |
| 127 } | 131 } |
| 128 | 132 |
| 129 id WebTestWithWebState::ExecuteJavaScript(NSString* script) { | 133 id WebTestWithWebState::ExecuteJavaScript(NSString* script) { |
| 130 __block base::scoped_nsprotocol<id> executionResult; | 134 __block id executionResult; |
| 131 __block bool executionCompleted = false; | 135 __block bool executionCompleted = false; |
| 132 [GetWebController(web_state()) | 136 [GetWebController(web_state()) |
| 133 executeJavaScript:script | 137 executeJavaScript:script |
| 134 completionHandler:^(id result, NSError* error) { | 138 completionHandler:^(id result, NSError* error) { |
| 135 executionResult.reset([result copy]); | 139 executionResult = [result copy]; |
| 136 executionCompleted = true; | 140 executionCompleted = true; |
| 137 }]; | 141 }]; |
| 138 base::test::ios::WaitUntilCondition(^{ | 142 base::test::ios::WaitUntilCondition(^{ |
| 139 return executionCompleted; | 143 return executionCompleted; |
| 140 }); | 144 }); |
| 141 return [[executionResult retain] autorelease]; | 145 return executionResult; |
| 142 } | 146 } |
| 143 | 147 |
| 144 void WebTestWithWebState::DestroyWebState() { | 148 void WebTestWithWebState::DestroyWebState() { |
| 145 web_state_.reset(); | 149 web_state_.reset(); |
| 146 } | 150 } |
| 147 | 151 |
| 148 std::string WebTestWithWebState::BaseUrl() const { | 152 std::string WebTestWithWebState::BaseUrl() const { |
| 149 web::URLVerificationTrustLevel unused_level; | 153 web::URLVerificationTrustLevel unused_level; |
| 150 return web_state()->GetCurrentURL(&unused_level).spec(); | 154 return web_state()->GetCurrentURL(&unused_level).spec(); |
| 151 } | 155 } |
| 152 | 156 |
| 153 web::WebState* WebTestWithWebState::web_state() { | 157 web::WebState* WebTestWithWebState::web_state() { |
| 154 return web_state_.get(); | 158 return web_state_.get(); |
| 155 } | 159 } |
| 156 | 160 |
| 157 const web::WebState* WebTestWithWebState::web_state() const { | 161 const web::WebState* WebTestWithWebState::web_state() const { |
| 158 return web_state_.get(); | 162 return web_state_.get(); |
| 159 } | 163 } |
| 160 | 164 |
| 161 void WebTestWithWebState::WillProcessTask(const base::PendingTask&) { | 165 void WebTestWithWebState::WillProcessTask(const base::PendingTask&) { |
| 162 // Nothing to do. | 166 // Nothing to do. |
| 163 } | 167 } |
| 164 | 168 |
| 165 void WebTestWithWebState::DidProcessTask(const base::PendingTask&) { | 169 void WebTestWithWebState::DidProcessTask(const base::PendingTask&) { |
| 166 processed_a_task_ = true; | 170 processed_a_task_ = true; |
| 167 } | 171 } |
| 168 | 172 |
| 169 } // namespace web | 173 } // namespace web |
| OLD | NEW |