| 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 #include "ios/web/web_state/navigation_context_impl.h" | 5 #include "ios/web/web_state/navigation_context_impl.h" |
| 6 | 6 |
| 7 #import "ios/web/public/test/fakes/test_web_state.h" | 7 #import "ios/web/public/test/fakes/test_web_state.h" |
| 8 #include "net/http/http_response_headers.h" | 8 #include "net/http/http_response_headers.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 NavigationContextImplTest() | 23 NavigationContextImplTest() |
| 24 : url_("https://chromium.test"), | 24 : url_("https://chromium.test"), |
| 25 response_headers_(new net::HttpResponseHeaders( | 25 response_headers_(new net::HttpResponseHeaders( |
| 26 std::string(kRawResponseHeaders, sizeof(kRawResponseHeaders)))) {} | 26 std::string(kRawResponseHeaders, sizeof(kRawResponseHeaders)))) {} |
| 27 | 27 |
| 28 TestWebState web_state_; | 28 TestWebState web_state_; |
| 29 GURL url_; | 29 GURL url_; |
| 30 scoped_refptr<net::HttpResponseHeaders> response_headers_; | 30 scoped_refptr<net::HttpResponseHeaders> response_headers_; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 // Tests CreateNavigationContext factory method. | 33 // Tests legacy CreateNavigationContext factory method. |
| 34 TEST_F(NavigationContextImplTest, NavigationContext) { | 34 TEST_F(NavigationContextImplTest, LegacyNavigationContext) { |
| 35 std::unique_ptr<NavigationContext> context = | 35 std::unique_ptr<NavigationContext> context = |
| 36 NavigationContextImpl::CreateNavigationContext(&web_state_, url_, | 36 NavigationContextImpl::CreateNavigationContext(&web_state_, url_, |
| 37 response_headers_); | 37 response_headers_); |
| 38 ASSERT_TRUE(context); | 38 ASSERT_TRUE(context); |
| 39 | 39 |
| 40 EXPECT_EQ(&web_state_, context->GetWebState()); | 40 EXPECT_EQ(&web_state_, context->GetWebState()); |
| 41 EXPECT_EQ(url_, context->GetUrl()); | 41 EXPECT_EQ(url_, context->GetUrl()); |
| 42 EXPECT_FALSE(context->IsSameDocument()); | 42 EXPECT_FALSE(context->IsSameDocument()); |
| 43 EXPECT_FALSE(context->IsErrorPage()); | 43 EXPECT_FALSE(context->IsErrorPage()); |
| 44 EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders()); | 44 EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Tests CreateNavigationContext factory method. |
| 48 TEST_F(NavigationContextImplTest, NavigationContext) { |
| 49 std::unique_ptr<NavigationContext> context = |
| 50 NavigationContextImpl::CreateNavigationContext(&web_state_, url_); |
| 51 ASSERT_TRUE(context); |
| 52 |
| 53 EXPECT_EQ(&web_state_, context->GetWebState()); |
| 54 EXPECT_EQ(url_, context->GetUrl()); |
| 55 EXPECT_FALSE(context->IsSameDocument()); |
| 56 EXPECT_FALSE(context->IsErrorPage()); |
| 57 EXPECT_FALSE(context->GetResponseHeaders()); |
| 58 } |
| 59 |
| 47 // Tests CreateSameDocumentNavigationContext factory method. | 60 // Tests CreateSameDocumentNavigationContext factory method. |
| 48 TEST_F(NavigationContextImplTest, SameDocumentNavigationContext) { | 61 TEST_F(NavigationContextImplTest, SameDocumentNavigationContext) { |
| 49 std::unique_ptr<NavigationContext> context = | 62 std::unique_ptr<NavigationContext> context = |
| 50 NavigationContextImpl::CreateSameDocumentNavigationContext(&web_state_, | 63 NavigationContextImpl::CreateSameDocumentNavigationContext(&web_state_, |
| 51 url_); | 64 url_); |
| 52 ASSERT_TRUE(context); | 65 ASSERT_TRUE(context); |
| 53 | 66 |
| 54 EXPECT_EQ(&web_state_, context->GetWebState()); | 67 EXPECT_EQ(&web_state_, context->GetWebState()); |
| 55 EXPECT_EQ(url_, context->GetUrl()); | 68 EXPECT_EQ(url_, context->GetUrl()); |
| 56 EXPECT_TRUE(context->IsSameDocument()); | 69 EXPECT_TRUE(context->IsSameDocument()); |
| 57 EXPECT_FALSE(context->IsErrorPage()); | 70 EXPECT_FALSE(context->IsErrorPage()); |
| 58 EXPECT_FALSE(context->GetResponseHeaders()); | 71 EXPECT_FALSE(context->GetResponseHeaders()); |
| 59 } | 72 } |
| 60 | 73 |
| 61 // Tests CreateErrorPageNavigationContext factory method. | 74 // Tests CreateErrorPageNavigationContext factory method. |
| 62 TEST_F(NavigationContextImplTest, ErrorPageNavigationContext) { | 75 TEST_F(NavigationContextImplTest, ErrorPageNavigationContext) { |
| 63 std::unique_ptr<NavigationContext> context = | 76 std::unique_ptr<NavigationContext> context = |
| 64 NavigationContextImpl::CreateErrorPageNavigationContext( | 77 NavigationContextImpl::CreateErrorPageNavigationContext( |
| 65 &web_state_, url_, response_headers_); | 78 &web_state_, url_, response_headers_); |
| 66 ASSERT_TRUE(context); | 79 ASSERT_TRUE(context); |
| 67 | 80 |
| 68 EXPECT_EQ(&web_state_, context->GetWebState()); | 81 EXPECT_EQ(&web_state_, context->GetWebState()); |
| 69 EXPECT_EQ(url_, context->GetUrl()); | 82 EXPECT_EQ(url_, context->GetUrl()); |
| 70 EXPECT_FALSE(context->IsSameDocument()); | 83 EXPECT_FALSE(context->IsSameDocument()); |
| 71 EXPECT_TRUE(context->IsErrorPage()); | 84 EXPECT_TRUE(context->IsErrorPage()); |
| 72 EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders()); | 85 EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders()); |
| 73 } | 86 } |
| 74 | 87 |
| 88 // Tests NavigationContextImpl Setters. |
| 89 TEST_F(NavigationContextImplTest, Setters) { |
| 90 std::unique_ptr<NavigationContextImpl> context = |
| 91 NavigationContextImpl::CreateNavigationContext(&web_state_, url_); |
| 92 ASSERT_TRUE(context); |
| 93 |
| 94 ASSERT_FALSE(context->IsSameDocument()); |
| 95 ASSERT_FALSE(context->IsErrorPage()); |
| 96 ASSERT_NE(response_headers_.get(), context->GetResponseHeaders()); |
| 97 |
| 98 // SetSameDocument |
| 99 context->SetIsSameDocument(true); |
| 100 EXPECT_TRUE(context->IsSameDocument()); |
| 101 EXPECT_FALSE(context->IsErrorPage()); |
| 102 EXPECT_NE(response_headers_.get(), context->GetResponseHeaders()); |
| 103 |
| 104 // SetErrorPage |
| 105 context->SetIsErrorPage(true); |
| 106 EXPECT_TRUE(context->IsSameDocument()); |
| 107 EXPECT_TRUE(context->IsErrorPage()); |
| 108 EXPECT_NE(response_headers_.get(), context->GetResponseHeaders()); |
| 109 |
| 110 // SetResponseHeaders |
| 111 context->SetResponseHeaders(response_headers_); |
| 112 EXPECT_TRUE(context->IsSameDocument()); |
| 113 EXPECT_TRUE(context->IsErrorPage()); |
| 114 EXPECT_EQ(response_headers_.get(), context->GetResponseHeaders()); |
| 115 } |
| 116 |
| 75 } // namespace web | 117 } // namespace web |
| OLD | NEW |