| 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 #include "ios/web/public/web_state/url_verification_constants.h" | 11 #include "ios/web/public/web_state/url_verification_constants.h" |
| 11 #include "ios/web/public/web_state/web_state_observer.h" | 12 #include "ios/web/public/web_state/web_state_observer.h" |
| 12 #import "ios/web/web_state/ui/crw_web_controller.h" | 13 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 13 #import "ios/web/web_state/web_state_impl.h" | 14 #import "ios/web/web_state/web_state_impl.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 // Returns CRWWebController for the given |web_state|. | 17 // Returns CRWWebController for the given |web_state|. |
| 17 CRWWebController* GetWebController(web::WebState* web_state) { | 18 CRWWebController* GetWebController(web::WebState* web_state) { |
| 18 web::WebStateImpl* web_state_impl = | 19 web::WebStateImpl* web_state_impl = |
| 19 static_cast<web::WebStateImpl*>(web_state); | 20 static_cast<web::WebStateImpl*>(web_state); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 // Force generation of child views; necessary for some tests. | 37 // Force generation of child views; necessary for some tests. |
| 37 [GetWebController(web_state()) triggerPendingLoad]; | 38 [GetWebController(web_state()) triggerPendingLoad]; |
| 38 } | 39 } |
| 39 | 40 |
| 40 void WebTestWithWebState::TearDown() { | 41 void WebTestWithWebState::TearDown() { |
| 41 DestroyWebState(); | 42 DestroyWebState(); |
| 42 WebTest::TearDown(); | 43 WebTest::TearDown(); |
| 43 } | 44 } |
| 44 | 45 |
| 46 void WebTestWithWebState::AddPendingItem(const GURL& url, |
| 47 ui::PageTransition transition) { |
| 48 GetWebController(web_state()) |
| 49 .webStateImpl->GetNavigationManagerImpl() |
| 50 .AddPendingItem(url, Referrer(), transition, |
| 51 web::NavigationInitiationType::USER_INITIATED, |
| 52 web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| 53 } |
| 54 |
| 45 void WebTestWithWebState::LoadHtml(NSString* html, const GURL& url) { | 55 void WebTestWithWebState::LoadHtml(NSString* html, const GURL& url) { |
| 46 // Sets MIME type to "text/html" once navigation is committed. | 56 // Sets MIME type to "text/html" once navigation is committed. |
| 47 class MimeTypeUpdater : public WebStateObserver { | 57 class MimeTypeUpdater : public WebStateObserver { |
| 48 public: | 58 public: |
| 49 explicit MimeTypeUpdater(WebState* web_state) | 59 explicit MimeTypeUpdater(WebState* web_state) |
| 50 : WebStateObserver(web_state) {} | 60 : WebStateObserver(web_state) {} |
| 51 // WebStateObserver overrides: | 61 // WebStateObserver overrides: |
| 52 void NavigationItemCommitted(const LoadCommittedDetails&) override { | 62 void NavigationItemCommitted(const LoadCommittedDetails&) override { |
| 53 // loadHTML:forURL: does not notify web view delegate about received | 63 // loadHTML:forURL: does not notify web view delegate about received |
| 54 // response, so web controller does not get a chance to properly update | 64 // response, so web controller does not get a chance to properly update |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 160 |
| 151 void WebTestWithWebState::WillProcessTask(const base::PendingTask&) { | 161 void WebTestWithWebState::WillProcessTask(const base::PendingTask&) { |
| 152 // Nothing to do. | 162 // Nothing to do. |
| 153 } | 163 } |
| 154 | 164 |
| 155 void WebTestWithWebState::DidProcessTask(const base::PendingTask&) { | 165 void WebTestWithWebState::DidProcessTask(const base::PendingTask&) { |
| 156 processed_a_task_ = true; | 166 processed_a_task_ = true; |
| 157 } | 167 } |
| 158 | 168 |
| 159 } // namespace web | 169 } // namespace web |
| OLD | NEW |