| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/web/public/test/test_web_state.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "base/callback.h" | |
| 10 #include "ios/web/public/web_state/web_state_observer.h" | |
| 11 | |
| 12 namespace web { | |
| 13 | |
| 14 void TestWebState::AddObserver(WebStateObserver* observer) { | |
| 15 observers_.AddObserver(observer); | |
| 16 } | |
| 17 | |
| 18 void TestWebState::RemoveObserver(WebStateObserver* observer) { | |
| 19 observers_.RemoveObserver(observer); | |
| 20 } | |
| 21 | |
| 22 TestWebState::TestWebState() | |
| 23 : web_usage_enabled_(false), | |
| 24 is_loading_(false), | |
| 25 trust_level_(kAbsolute), | |
| 26 content_is_html_(true) {} | |
| 27 | |
| 28 TestWebState::~TestWebState() { | |
| 29 for (auto& observer : observers_) | |
| 30 observer.WebStateDestroyed(); | |
| 31 for (auto& observer : observers_) | |
| 32 observer.ResetWebState(); | |
| 33 }; | |
| 34 | |
| 35 WebStateDelegate* TestWebState::GetDelegate() { | |
| 36 return nil; | |
| 37 } | |
| 38 | |
| 39 void TestWebState::SetDelegate(WebStateDelegate* delegate) {} | |
| 40 | |
| 41 BrowserState* TestWebState::GetBrowserState() const { | |
| 42 return nullptr; | |
| 43 } | |
| 44 | |
| 45 bool TestWebState::IsWebUsageEnabled() const { | |
| 46 return web_usage_enabled_; | |
| 47 } | |
| 48 | |
| 49 void TestWebState::SetWebUsageEnabled(bool enabled) { | |
| 50 web_usage_enabled_ = enabled; | |
| 51 } | |
| 52 | |
| 53 bool TestWebState::ShouldSuppressDialogs() const { | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 void TestWebState::SetShouldSuppressDialogs(bool should_suppress) {} | |
| 58 | |
| 59 UIView* TestWebState::GetView() { | |
| 60 return nullptr; | |
| 61 } | |
| 62 | |
| 63 const NavigationManager* TestWebState::GetNavigationManager() const { | |
| 64 return navigation_manager_.get(); | |
| 65 } | |
| 66 | |
| 67 NavigationManager* TestWebState::GetNavigationManager() { | |
| 68 return navigation_manager_.get(); | |
| 69 } | |
| 70 | |
| 71 void TestWebState::SetNavigationManager( | |
| 72 std::unique_ptr<NavigationManager> navigation_manager) { | |
| 73 navigation_manager_ = std::move(navigation_manager); | |
| 74 } | |
| 75 | |
| 76 CRWJSInjectionReceiver* TestWebState::GetJSInjectionReceiver() const { | |
| 77 return nullptr; | |
| 78 } | |
| 79 | |
| 80 void TestWebState::ExecuteJavaScript(const base::string16& javascript) {} | |
| 81 | |
| 82 void TestWebState::ExecuteJavaScript(const base::string16& javascript, | |
| 83 const JavaScriptResultCallback& callback) { | |
| 84 callback.Run(nullptr); | |
| 85 } | |
| 86 | |
| 87 const std::string& TestWebState::GetContentsMimeType() const { | |
| 88 return mime_type_; | |
| 89 } | |
| 90 | |
| 91 const std::string& TestWebState::GetContentLanguageHeader() const { | |
| 92 return content_language_; | |
| 93 } | |
| 94 | |
| 95 bool TestWebState::ContentIsHTML() const { | |
| 96 return content_is_html_; | |
| 97 } | |
| 98 | |
| 99 const GURL& TestWebState::GetVisibleURL() const { | |
| 100 return url_; | |
| 101 } | |
| 102 | |
| 103 const GURL& TestWebState::GetLastCommittedURL() const { | |
| 104 return url_; | |
| 105 } | |
| 106 | |
| 107 GURL TestWebState::GetCurrentURL(URLVerificationTrustLevel* trust_level) const { | |
| 108 *trust_level = trust_level_; | |
| 109 return url_; | |
| 110 } | |
| 111 | |
| 112 bool TestWebState::IsShowingWebInterstitial() const { | |
| 113 return false; | |
| 114 } | |
| 115 | |
| 116 WebInterstitial* TestWebState::GetWebInterstitial() const { | |
| 117 return nullptr; | |
| 118 } | |
| 119 | |
| 120 void TestWebState::SetContentIsHTML(bool content_is_html) { | |
| 121 content_is_html_ = content_is_html; | |
| 122 } | |
| 123 | |
| 124 const base::string16& TestWebState::GetTitle() const { | |
| 125 return title_; | |
| 126 } | |
| 127 | |
| 128 bool TestWebState::IsLoading() const { | |
| 129 return is_loading_; | |
| 130 } | |
| 131 | |
| 132 double TestWebState::GetLoadingProgress() const { | |
| 133 return 0.0; | |
| 134 } | |
| 135 | |
| 136 bool TestWebState::IsBeingDestroyed() const { | |
| 137 return false; | |
| 138 } | |
| 139 | |
| 140 void TestWebState::SetLoading(bool is_loading) { | |
| 141 if (is_loading == is_loading_) | |
| 142 return; | |
| 143 | |
| 144 is_loading_ = is_loading; | |
| 145 | |
| 146 if (is_loading) { | |
| 147 for (auto& observer : observers_) | |
| 148 observer.DidStartLoading(); | |
| 149 } else { | |
| 150 for (auto& observer : observers_) | |
| 151 observer.DidStopLoading(); | |
| 152 } | |
| 153 } | |
| 154 | |
| 155 void TestWebState::OnPageLoaded( | |
| 156 PageLoadCompletionStatus load_completion_status) { | |
| 157 for (auto& observer : observers_) | |
| 158 observer.PageLoaded(load_completion_status); | |
| 159 } | |
| 160 | |
| 161 void TestWebState::SetCurrentURL(const GURL& url) { | |
| 162 url_ = url; | |
| 163 } | |
| 164 | |
| 165 void TestWebState::SetTrustLevel(URLVerificationTrustLevel trust_level) { | |
| 166 trust_level_ = trust_level; | |
| 167 } | |
| 168 | |
| 169 CRWWebViewProxyType TestWebState::GetWebViewProxy() const { | |
| 170 return nullptr; | |
| 171 } | |
| 172 | |
| 173 int TestWebState::DownloadImage(const GURL& url, | |
| 174 bool is_favicon, | |
| 175 uint32_t max_bitmap_size, | |
| 176 bool bypass_cache, | |
| 177 const ImageDownloadCallback& callback) { | |
| 178 return 0; | |
| 179 } | |
| 180 | |
| 181 service_manager::InterfaceRegistry* TestWebState::GetMojoInterfaceRegistry() { | |
| 182 return nullptr; | |
| 183 } | |
| 184 | |
| 185 base::WeakPtr<WebState> TestWebState::AsWeakPtr() { | |
| 186 NOTREACHED(); | |
| 187 return base::WeakPtr<WebState>(); | |
| 188 } | |
| 189 | |
| 190 } // namespace web | |
| OLD | NEW |