| 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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 std::unique_ptr<WebStateObserverBridge> bridge_; | 37 std::unique_ptr<WebStateObserverBridge> bridge_; |
| 38 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 38 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 // Tests |webState:didStartNavigation:| forwarding. | 41 // Tests |webState:didStartNavigation:| forwarding. |
| 42 TEST_F(WebStateObserverBridgeTest, DidStartNavigation) { | 42 TEST_F(WebStateObserverBridgeTest, DidStartNavigation) { |
| 43 ASSERT_FALSE([observer_ didStartNavigationInfo]); | 43 ASSERT_FALSE([observer_ didStartNavigationInfo]); |
| 44 | 44 |
| 45 GURL url("https://chromium.test/"); | 45 GURL url("https://chromium.test/"); |
| 46 std::unique_ptr<web::NavigationContext> context = | 46 std::unique_ptr<web::NavigationContext> context = |
| 47 web::NavigationContextImpl::CreateNavigationContext(&test_web_state_, | 47 web::NavigationContextImpl::CreateNavigationContext( |
| 48 url); | 48 &test_web_state_, url, |
| 49 ui::PageTransition::PAGE_TRANSITION_FORWARD_BACK); |
| 49 bridge_->DidStartNavigation(context.get()); | 50 bridge_->DidStartNavigation(context.get()); |
| 50 | 51 |
| 51 ASSERT_TRUE([observer_ didStartNavigationInfo]); | 52 ASSERT_TRUE([observer_ didStartNavigationInfo]); |
| 52 EXPECT_EQ(&test_web_state_, [observer_ didStartNavigationInfo]->web_state); | 53 EXPECT_EQ(&test_web_state_, [observer_ didStartNavigationInfo]->web_state); |
| 53 web::NavigationContext* actual_context = | 54 web::NavigationContext* actual_context = |
| 54 [observer_ didStartNavigationInfo]->context.get(); | 55 [observer_ didStartNavigationInfo]->context.get(); |
| 55 ASSERT_TRUE(actual_context); | 56 ASSERT_TRUE(actual_context); |
| 56 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); | 57 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); |
| 57 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); | 58 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); |
| 58 EXPECT_EQ(context->GetError(), actual_context->GetError()); | 59 EXPECT_EQ(context->GetError(), actual_context->GetError()); |
| 59 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); | 60 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); |
| 61 EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs( |
| 62 ui::PageTransition::PAGE_TRANSITION_FORWARD_BACK, |
| 63 actual_context->GetPageTransition())); |
| 60 EXPECT_EQ(context->GetResponseHeaders(), | 64 EXPECT_EQ(context->GetResponseHeaders(), |
| 61 actual_context->GetResponseHeaders()); | 65 actual_context->GetResponseHeaders()); |
| 62 } | 66 } |
| 63 | 67 |
| 64 // Tests |webState:didFinishNavigation:| forwarding. | 68 // Tests |webState:didFinishNavigation:| forwarding. |
| 65 TEST_F(WebStateObserverBridgeTest, DidFinishNavigation) { | 69 TEST_F(WebStateObserverBridgeTest, DidFinishNavigation) { |
| 66 ASSERT_FALSE([observer_ didFinishNavigationInfo]); | 70 ASSERT_FALSE([observer_ didFinishNavigationInfo]); |
| 67 | 71 |
| 68 GURL url("https://chromium.test/"); | 72 GURL url("https://chromium.test/"); |
| 69 std::unique_ptr<web::NavigationContext> context = | 73 std::unique_ptr<web::NavigationContext> context = |
| 70 web::NavigationContextImpl::CreateNavigationContext(&test_web_state_, | 74 web::NavigationContextImpl::CreateNavigationContext( |
| 71 url); | 75 &test_web_state_, url, |
| 76 ui::PageTransition::PAGE_TRANSITION_FROM_ADDRESS_BAR); |
| 72 bridge_->DidFinishNavigation(context.get()); | 77 bridge_->DidFinishNavigation(context.get()); |
| 73 | 78 |
| 74 ASSERT_TRUE([observer_ didFinishNavigationInfo]); | 79 ASSERT_TRUE([observer_ didFinishNavigationInfo]); |
| 75 EXPECT_EQ(&test_web_state_, [observer_ didFinishNavigationInfo]->web_state); | 80 EXPECT_EQ(&test_web_state_, [observer_ didFinishNavigationInfo]->web_state); |
| 76 web::NavigationContext* actual_context = | 81 web::NavigationContext* actual_context = |
| 77 [observer_ didFinishNavigationInfo]->context.get(); | 82 [observer_ didFinishNavigationInfo]->context.get(); |
| 78 ASSERT_TRUE(actual_context); | 83 ASSERT_TRUE(actual_context); |
| 79 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); | 84 EXPECT_EQ(&test_web_state_, actual_context->GetWebState()); |
| 80 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); | 85 EXPECT_EQ(context->IsSameDocument(), actual_context->IsSameDocument()); |
| 81 EXPECT_EQ(context->GetError(), actual_context->GetError()); | 86 EXPECT_EQ(context->GetError(), actual_context->GetError()); |
| 82 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); | 87 EXPECT_EQ(context->GetUrl(), actual_context->GetUrl()); |
| 88 EXPECT_TRUE(PageTransitionTypeIncludingQualifiersIs( |
| 89 ui::PageTransition::PAGE_TRANSITION_FROM_ADDRESS_BAR, |
| 90 actual_context->GetPageTransition())); |
| 83 EXPECT_EQ(context->GetResponseHeaders(), | 91 EXPECT_EQ(context->GetResponseHeaders(), |
| 84 actual_context->GetResponseHeaders()); | 92 actual_context->GetResponseHeaders()); |
| 85 } | 93 } |
| 86 | 94 |
| 87 // Tests |webState:didCommitNavigationWithDetails:| forwarding. | 95 // Tests |webState:didCommitNavigationWithDetails:| forwarding. |
| 88 TEST_F(WebStateObserverBridgeTest, NavigationItemCommitted) { | 96 TEST_F(WebStateObserverBridgeTest, NavigationItemCommitted) { |
| 89 ASSERT_FALSE([observer_ commitNavigationInfo]); | 97 ASSERT_FALSE([observer_ commitNavigationInfo]); |
| 90 | 98 |
| 91 LoadCommittedDetails load_details; | 99 LoadCommittedDetails load_details; |
| 92 load_details.item = reinterpret_cast<web::NavigationItem*>(1); | 100 load_details.item = reinterpret_cast<web::NavigationItem*>(1); |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Tests |webState:webStateDidStartLoading:| forwarding. | 264 // Tests |webState:webStateDidStartLoading:| forwarding. |
| 257 TEST_F(WebStateObserverBridgeTest, DidStartLoading) { | 265 TEST_F(WebStateObserverBridgeTest, DidStartLoading) { |
| 258 ASSERT_FALSE([observer_ startLoadingInfo]); | 266 ASSERT_FALSE([observer_ startLoadingInfo]); |
| 259 | 267 |
| 260 bridge_->DidStartLoading(); | 268 bridge_->DidStartLoading(); |
| 261 ASSERT_TRUE([observer_ startLoadingInfo]); | 269 ASSERT_TRUE([observer_ startLoadingInfo]); |
| 262 EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state); | 270 EXPECT_EQ(&test_web_state_, [observer_ startLoadingInfo]->web_state); |
| 263 } | 271 } |
| 264 | 272 |
| 265 } // namespace web | 273 } // namespace web |
| OLD | NEW |