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