| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/web_state/web_state_observer_bridge.h" | 5 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "ios/web/public/favicon_url.h" | 9 #include "ios/web/public/favicon_url.h" |
| 10 #import "ios/web/public/test/fakes/crw_test_web_state_observer.h" | 10 #import "ios/web/public/test/fakes/crw_test_web_state_observer.h" |
| 11 #import "ios/web/public/test/fakes/test_web_state.h" | 11 #import "ios/web/public/test/fakes/test_web_state.h" |
| 12 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 12 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 13 #include "ios/web/web_state/navigation_context_impl.h" | 13 #import "ios/web/web_state/navigation_context_impl.h" |
| 14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 16 | 16 |
| 17 namespace web { | 17 namespace web { |
| 18 namespace { | 18 namespace { |
| 19 const char kRawResponseHeaders[] = | 19 const char kRawResponseHeaders[] = |
| 20 "HTTP/1.1 200 OK\0" | 20 "HTTP/1.1 200 OK\0" |
| 21 "Content-Length: 450\0" | 21 "Content-Length: 450\0" |
| 22 "Connection: keep-alive\0"; | 22 "Connection: keep-alive\0"; |
| 23 } // namespace | 23 } // namespace |
| (...skipping 24 matching lines...) Expand all Loading... |
| 48 url); | 48 url); |
| 49 bridge_->DidStartNavigation(context.get()); | 49 bridge_->DidStartNavigation(context.get()); |
| 50 | 50 |
| 51 ASSERT_TRUE([observer_ didStartNavigationInfo]); | 51 ASSERT_TRUE([observer_ didStartNavigationInfo]); |
| 52 EXPECT_EQ(&test_web_state_, [observer_ didStartNavigationInfo]->web_state); | 52 EXPECT_EQ(&test_web_state_, [observer_ didStartNavigationInfo]->web_state); |
| 53 web::NavigationContext* actual_context = | 53 web::NavigationContext* actual_context = |
| 54 [observer_ didStartNavigationInfo]->context.get(); | 54 [observer_ didStartNavigationInfo]->context.get(); |
| 55 ASSERT_TRUE(actual_context); | 55 ASSERT_TRUE(actual_context); |
| 56 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); | 56 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); |
| 57 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); | 57 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); |
| 58 EXPECT_EQ(context->IsErrorPage(), actual_context->IsErrorPage()); | 58 EXPECT_EQ(context->GetError(), actual_context->GetError()); |
| 59 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); | 59 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); |
| 60 EXPECT_EQ(context->GetResponseHeaders(), | 60 EXPECT_EQ(context->GetResponseHeaders(), |
| 61 actual_context->GetResponseHeaders()); | 61 actual_context->GetResponseHeaders()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Tests |webState:didFinishNavigation:| forwarding. | 64 // Tests |webState:didFinishNavigation:| forwarding. |
| 65 TEST_F(WebStateObserverBridgeTest, DidFinishNavigation) { | 65 TEST_F(WebStateObserverBridgeTest, DidFinishNavigation) { |
| 66 ASSERT_FALSE([observer_ didFinishNavigationInfo]); | 66 ASSERT_FALSE([observer_ didFinishNavigationInfo]); |
| 67 | 67 |
| 68 GURL url("https://chromium.test/"); | 68 GURL url("https://chromium.test/"); |
| 69 std::unique_ptr<web::NavigationContext> context = | 69 std::unique_ptr<web::NavigationContext> context = |
| 70 web::NavigationContextImpl::CreateNavigationContext(&test_web_state_, | 70 web::NavigationContextImpl::CreateNavigationContext(&test_web_state_, |
| 71 url); | 71 url); |
| 72 bridge_->DidFinishNavigation(context.get()); | 72 bridge_->DidFinishNavigation(context.get()); |
| 73 | 73 |
| 74 ASSERT_TRUE([observer_ didFinishNavigationInfo]); | 74 ASSERT_TRUE([observer_ didFinishNavigationInfo]); |
| 75 EXPECT_EQ(&test_web_state_, [observer_ didFinishNavigationInfo]->web_state); | 75 EXPECT_EQ(&test_web_state_, [observer_ didFinishNavigationInfo]->web_state); |
| 76 web::NavigationContext* actual_context = | 76 web::NavigationContext* actual_context = |
| 77 [observer_ didFinishNavigationInfo]->context.get(); | 77 [observer_ didFinishNavigationInfo]->context.get(); |
| 78 ASSERT_TRUE(actual_context); | 78 ASSERT_TRUE(actual_context); |
| 79 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); | 79 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); |
| 80 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); | 80 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); |
| 81 EXPECT_EQ(context->IsErrorPage(), actual_context->IsErrorPage()); | 81 EXPECT_EQ(context->GetError(), actual_context->GetError()); |
| 82 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); | 82 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); |
| 83 EXPECT_EQ(context->GetResponseHeaders(), | 83 EXPECT_EQ(context->GetResponseHeaders(), |
| 84 actual_context->GetResponseHeaders()); | 84 actual_context->GetResponseHeaders()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 // Tests |webState:didCommitNavigationWithDetails:| forwarding. | 87 // Tests |webState:didCommitNavigationWithDetails:| forwarding. |
| 88 TEST_F(WebStateObserverBridgeTest, NavigationItemCommitted) { | 88 TEST_F(WebStateObserverBridgeTest, NavigationItemCommitted) { |
| 89 ASSERT_FALSE([observer_ commitNavigationInfo]); | 89 ASSERT_FALSE([observer_ commitNavigationInfo]); |
| 90 | 90 |
| 91 LoadCommittedDetails load_details; | 91 LoadCommittedDetails load_details; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Tests |webState:webStateDidStartLoading:| forwarding. | 256 // Tests |webState:webStateDidStartLoading:| forwarding. |
| 257 TEST_F(WebStateObserverBridgeTest, DidStartLoading) { | 257 TEST_F(WebStateObserverBridgeTest, DidStartLoading) { |
| 258 ASSERT_FALSE([observer_ startLoadingInfo]); | 258 ASSERT_FALSE([observer_ startLoadingInfo]); |
| 259 | 259 |
| 260 bridge_->DidStartLoading(); | 260 bridge_->DidStartLoading(); |
| 261 ASSERT_TRUE([observer_ startLoadingInfo]); | 261 ASSERT_TRUE([observer_ startLoadingInfo]); |
| 262 EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state); | 262 EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state); |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace web | 265 } // namespace web |
| OLD | NEW |