| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/web_state/web_state_impl.h" | 5 #import "ios/web/web_state/web_state_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 scoped_refptr<net::HttpResponseHeaders> frame_headers(HeadersFromString( | 205 scoped_refptr<net::HttpResponseHeaders> frame_headers(HeadersFromString( |
| 206 "HTTP/1.1 200 OK\r\n" | 206 "HTTP/1.1 200 OK\r\n" |
| 207 "Content-Type: application/pdf\r\n" | 207 "Content-Type: application/pdf\r\n" |
| 208 "Content-Language: fr\r\n" | 208 "Content-Language: fr\r\n" |
| 209 "X-Should-Not-Be-Here: oops\r\n" | 209 "X-Should-Not-Be-Here: oops\r\n" |
| 210 "\r\n")); | 210 "\r\n")); |
| 211 // Simulate a load of a page with a frame. | 211 // Simulate a load of a page with a frame. |
| 212 web_state_->OnHttpResponseHeadersReceived(real_headers.get(), real_url); | 212 web_state_->OnHttpResponseHeadersReceived(real_headers.get(), real_url); |
| 213 web_state_->OnHttpResponseHeadersReceived(frame_headers.get(), frame_url); | 213 web_state_->OnHttpResponseHeadersReceived(frame_headers.get(), frame_url); |
| 214 // Include a hash to be sure it's handled correctly. | 214 // Include a hash to be sure it's handled correctly. |
| 215 web_state_->OnNavigationCommitted( | 215 web_state_->UpdateHttpResponseHeaders( |
| 216 GURL(real_url.spec() + std::string("#baz"))); | 216 GURL(real_url.spec() + std::string("#baz"))); |
| 217 | 217 |
| 218 // Verify that the right header set was kept. | 218 // Verify that the right header set was kept. |
| 219 ASSERT_TRUE(web_state_->GetHttpResponseHeaders()); |
| 219 EXPECT_TRUE( | 220 EXPECT_TRUE( |
| 220 web_state_->GetHttpResponseHeaders()->HasHeader("X-Should-Be-Here")); | 221 web_state_->GetHttpResponseHeaders()->HasHeader("X-Should-Be-Here")); |
| 221 EXPECT_FALSE( | 222 EXPECT_FALSE( |
| 222 web_state_->GetHttpResponseHeaders()->HasHeader("X-Should-Not-Be-Here")); | 223 web_state_->GetHttpResponseHeaders()->HasHeader("X-Should-Not-Be-Here")); |
| 223 | 224 |
| 224 // And that it was parsed correctly. | 225 // And that it was parsed correctly. |
| 225 EXPECT_EQ("text/html", web_state_->GetContentsMimeType()); | 226 EXPECT_EQ("text/html", web_state_->GetContentsMimeType()); |
| 226 EXPECT_EQ("en", web_state_->GetContentLanguageHeader()); | 227 EXPECT_EQ("en", web_state_->GetContentLanguageHeader()); |
| 227 } | 228 } |
| 228 | 229 |
| 229 TEST_F(WebStateImplTest, ResponseHeaderClearing) { | 230 TEST_F(WebStateImplTest, ResponseHeaderClearing) { |
| 230 GURL url("http://foo.com/"); | 231 GURL url("http://foo.com/"); |
| 231 scoped_refptr<net::HttpResponseHeaders> headers(HeadersFromString( | 232 scoped_refptr<net::HttpResponseHeaders> headers(HeadersFromString( |
| 232 "HTTP/1.1 200 OK\r\n" | 233 "HTTP/1.1 200 OK\r\n" |
| 233 "Content-Type: text/html\r\n" | 234 "Content-Type: text/html\r\n" |
| 234 "Content-Language: en\r\n" | 235 "Content-Language: en\r\n" |
| 235 "\r\n")); | 236 "\r\n")); |
| 236 web_state_->OnHttpResponseHeadersReceived(headers.get(), url); | 237 web_state_->OnHttpResponseHeadersReceived(headers.get(), url); |
| 237 | 238 |
| 238 // There should be no headers before loading. | 239 // There should be no headers before loading. |
| 239 EXPECT_EQ(NULL, web_state_->GetHttpResponseHeaders()); | 240 EXPECT_EQ(NULL, web_state_->GetHttpResponseHeaders()); |
| 240 | 241 |
| 241 // There should be headers and parsed values after loading. | 242 // There should be headers and parsed values after loading. |
| 242 web_state_->OnNavigationCommitted(url); | 243 web_state_->UpdateHttpResponseHeaders(url); |
| 244 ASSERT_TRUE(web_state_->GetHttpResponseHeaders()); |
| 243 EXPECT_TRUE(web_state_->GetHttpResponseHeaders()->HasHeader("Content-Type")); | 245 EXPECT_TRUE(web_state_->GetHttpResponseHeaders()->HasHeader("Content-Type")); |
| 244 EXPECT_NE("", web_state_->GetContentsMimeType()); | 246 EXPECT_NE("", web_state_->GetContentsMimeType()); |
| 245 EXPECT_NE("", web_state_->GetContentLanguageHeader()); | 247 EXPECT_NE("", web_state_->GetContentLanguageHeader()); |
| 246 | 248 |
| 247 // ... but not after loading another page, nor should there be specific | 249 // ... but not after loading another page, nor should there be specific |
| 248 // parsed values. | 250 // parsed values. |
| 249 web_state_->OnNavigationCommitted(GURL("http://elsewhere.com/")); | 251 web_state_->UpdateHttpResponseHeaders(GURL("http://elsewhere.com/")); |
| 250 EXPECT_EQ(NULL, web_state_->GetHttpResponseHeaders()); | 252 EXPECT_EQ(NULL, web_state_->GetHttpResponseHeaders()); |
| 251 EXPECT_EQ("", web_state_->GetContentsMimeType()); | 253 EXPECT_EQ("", web_state_->GetContentsMimeType()); |
| 252 EXPECT_EQ("", web_state_->GetContentLanguageHeader()); | 254 EXPECT_EQ("", web_state_->GetContentLanguageHeader()); |
| 253 } | 255 } |
| 254 | 256 |
| 255 // Tests forwarding to WebStateObserver callbacks. | 257 // Tests forwarding to WebStateObserver callbacks. |
| 256 TEST_F(WebStateImplTest, ObserverTest) { | 258 TEST_F(WebStateImplTest, ObserverTest) { |
| 257 std::unique_ptr<TestWebStateObserver> observer( | 259 std::unique_ptr<TestWebStateObserver> observer( |
| 258 new TestWebStateObserver(web_state_.get())); | 260 new TestWebStateObserver(web_state_.get())); |
| 259 EXPECT_EQ(web_state_.get(), observer->web_state()); | 261 EXPECT_EQ(web_state_.get(), observer->web_state()); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 // Check that a false return value is forwarded correctly. | 623 // Check that a false return value is forwarded correctly. |
| 622 EXPECT_FALSE( | 624 EXPECT_FALSE( |
| 623 web_state_->OnScriptCommandReceived(kCommand2, value_2, kUrl2, false)); | 625 web_state_->OnScriptCommandReceived(kCommand2, value_2, kUrl2, false)); |
| 624 EXPECT_FALSE(is_called_1); | 626 EXPECT_FALSE(is_called_1); |
| 625 EXPECT_TRUE(is_called_2); | 627 EXPECT_TRUE(is_called_2); |
| 626 | 628 |
| 627 web_state_->RemoveScriptCommandCallback(kPrefix2); | 629 web_state_->RemoveScriptCommandCallback(kPrefix2); |
| 628 } | 630 } |
| 629 | 631 |
| 630 } // namespace web | 632 } // namespace web |
| OLD | NEW |