| 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 #include "ios/web/public/web_state/url_verification_constants.h" | 10 #include "ios/web/public/web_state/url_verification_constants.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 std::unique_ptr<WebStateImpl> web_state(new WebStateImpl(GetBrowserState())); | 32 std::unique_ptr<WebStateImpl> web_state(new WebStateImpl(GetBrowserState())); |
| 33 web_state->GetNavigationManagerImpl().InitializeSession(NO); | 33 web_state->GetNavigationManagerImpl().InitializeSession(NO); |
| 34 web_state->SetWebUsageEnabled(true); | 34 web_state->SetWebUsageEnabled(true); |
| 35 web_state_.reset(web_state.release()); | 35 web_state_.reset(web_state.release()); |
| 36 | 36 |
| 37 // Force generation of child views; necessary for some tests. | 37 // Force generation of child views; necessary for some tests. |
| 38 [GetWebController(web_state_.get()) triggerPendingLoad]; | 38 [GetWebController(web_state_.get()) triggerPendingLoad]; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void WebTestWithWebState::TearDown() { | 41 void WebTestWithWebState::TearDown() { |
| 42 web_state_.reset(); | 42 DestroyWebState(); |
| 43 WebTest::TearDown(); | 43 WebTest::TearDown(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void WebTestWithWebState::LoadHtml(NSString* html, const GURL& url) { | 46 void WebTestWithWebState::LoadHtml(NSString* html, const GURL& url) { |
| 47 // Sets MIME type to "text/html" once navigation is committed. | 47 // Sets MIME type to "text/html" once navigation is committed. |
| 48 class MimeTypeUpdater : public WebStateObserver { | 48 class MimeTypeUpdater : public WebStateObserver { |
| 49 public: | 49 public: |
| 50 explicit MimeTypeUpdater(WebState* web_state) | 50 explicit MimeTypeUpdater(WebState* web_state) |
| 51 : WebStateObserver(web_state) {} | 51 : WebStateObserver(web_state) {} |
| 52 // WebStateObserver overrides: | 52 // WebStateObserver overrides: |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 completionHandler:^(id result, NSError* error) { | 125 completionHandler:^(id result, NSError* error) { |
| 126 executionResult.reset([result copy]); | 126 executionResult.reset([result copy]); |
| 127 executionCompleted = true; | 127 executionCompleted = true; |
| 128 }]; | 128 }]; |
| 129 base::test::ios::WaitUntilCondition(^{ | 129 base::test::ios::WaitUntilCondition(^{ |
| 130 return executionCompleted; | 130 return executionCompleted; |
| 131 }); | 131 }); |
| 132 return [[executionResult retain] autorelease]; | 132 return [[executionResult retain] autorelease]; |
| 133 } | 133 } |
| 134 | 134 |
| 135 void WebTestWithWebState::DestroyWebState() { |
| 136 web_state_.reset(); |
| 137 } |
| 138 |
| 135 std::string WebTestWithWebState::BaseUrl() const { | 139 std::string WebTestWithWebState::BaseUrl() const { |
| 136 web::URLVerificationTrustLevel unused_level; | 140 web::URLVerificationTrustLevel unused_level; |
| 137 return web_state()->GetCurrentURL(&unused_level).spec(); | 141 return web_state()->GetCurrentURL(&unused_level).spec(); |
| 138 } | 142 } |
| 139 | 143 |
| 140 web::WebState* WebTestWithWebState::web_state() { | 144 web::WebState* WebTestWithWebState::web_state() { |
| 141 return web_state_.get(); | 145 return web_state_.get(); |
| 142 } | 146 } |
| 143 | 147 |
| 144 const web::WebState* WebTestWithWebState::web_state() const { | 148 const web::WebState* WebTestWithWebState::web_state() const { |
| 145 return web_state_.get(); | 149 return web_state_.get(); |
| 146 } | 150 } |
| 147 | 151 |
| 148 void WebTestWithWebState::WillProcessTask(const base::PendingTask&) { | 152 void WebTestWithWebState::WillProcessTask(const base::PendingTask&) { |
| 149 // Nothing to do. | 153 // Nothing to do. |
| 150 } | 154 } |
| 151 | 155 |
| 152 void WebTestWithWebState::DidProcessTask(const base::PendingTask&) { | 156 void WebTestWithWebState::DidProcessTask(const base::PendingTask&) { |
| 153 processed_a_task_ = true; | 157 processed_a_task_ = true; |
| 154 } | 158 } |
| 155 | 159 |
| 156 } // namespace web | 160 } // namespace web |
| OLD | NEW |