| 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 #include "components/sessions/ios/ios_serialized_navigation_builder.h" | 5 #include "components/sessions/ios/ios_serialized_navigation_builder.h" |
| 6 | 6 |
| 7 #include "components/sessions/core/serialized_navigation_entry.h" | 7 #include "components/sessions/core/serialized_navigation_entry.h" |
| 8 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" | 8 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" |
| 9 #include "ios/web/public/favicon_status.h" | 9 #include "ios/web/public/favicon_status.h" |
| 10 #include "ios/web/public/navigation_item.h" | 10 #include "ios/web/public/navigation_item.h" |
| 11 #include "ios/web/public/referrer.h" | 11 #include "ios/web/public/referrer.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace sessions { | 14 namespace sessions { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 // Creates a NavigationItem from the test_data constants in | 17 // Creates a NavigationItem from the test_data constants in |
| 18 // serialized_navigation_entry_test_helper.h. | 18 // serialized_navigation_entry_test_helper.h. |
| 19 scoped_ptr<web::NavigationItem> MakeNavigationItemForTest() { | 19 std::unique_ptr<web::NavigationItem> MakeNavigationItemForTest() { |
| 20 scoped_ptr<web::NavigationItem> navigation_item( | 20 std::unique_ptr<web::NavigationItem> navigation_item( |
| 21 web::NavigationItem::Create()); | 21 web::NavigationItem::Create()); |
| 22 navigation_item->SetReferrer(web::Referrer( | 22 navigation_item->SetReferrer(web::Referrer( |
| 23 test_data::kReferrerURL, | 23 test_data::kReferrerURL, |
| 24 static_cast<web::ReferrerPolicy>(test_data::kReferrerPolicy))); | 24 static_cast<web::ReferrerPolicy>(test_data::kReferrerPolicy))); |
| 25 navigation_item->SetURL(test_data::kVirtualURL); | 25 navigation_item->SetURL(test_data::kVirtualURL); |
| 26 navigation_item->SetTitle(test_data::kTitle); | 26 navigation_item->SetTitle(test_data::kTitle); |
| 27 navigation_item->SetTransitionType(test_data::kTransitionType); | 27 navigation_item->SetTransitionType(test_data::kTransitionType); |
| 28 navigation_item->SetTimestamp(test_data::kTimestamp); | 28 navigation_item->SetTimestamp(test_data::kTimestamp); |
| 29 navigation_item->GetFavicon().valid = true; | 29 navigation_item->GetFavicon().valid = true; |
| 30 navigation_item->GetFavicon().url = test_data::kFaviconURL; | 30 navigation_item->GetFavicon().url = test_data::kFaviconURL; |
| 31 return navigation_item; | 31 return navigation_item; |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 | 36 |
| 37 // Create a SerializedNavigationEntry from a NavigationItem. All its fields | 37 // Create a SerializedNavigationEntry from a NavigationItem. All its fields |
| 38 // should match the NavigationItem's. | 38 // should match the NavigationItem's. |
| 39 TEST(IOSSerializedNavigationBuilderTest, FromNavigationItem) { | 39 TEST(IOSSerializedNavigationBuilderTest, FromNavigationItem) { |
| 40 const scoped_ptr<web::NavigationItem> navigation_item( | 40 const std::unique_ptr<web::NavigationItem> navigation_item( |
| 41 MakeNavigationItemForTest()); | 41 MakeNavigationItemForTest()); |
| 42 | 42 |
| 43 const SerializedNavigationEntry& navigation = | 43 const SerializedNavigationEntry& navigation = |
| 44 IOSSerializedNavigationBuilder::FromNavigationItem( | 44 IOSSerializedNavigationBuilder::FromNavigationItem( |
| 45 test_data::kIndex, *navigation_item); | 45 test_data::kIndex, *navigation_item); |
| 46 | 46 |
| 47 EXPECT_EQ(test_data::kIndex, navigation.index()); | 47 EXPECT_EQ(test_data::kIndex, navigation.index()); |
| 48 | 48 |
| 49 EXPECT_EQ(navigation_item->GetUniqueID(), navigation.unique_id()); | 49 EXPECT_EQ(navigation_item->GetUniqueID(), navigation.unique_id()); |
| 50 EXPECT_EQ(test_data::kReferrerURL, navigation.referrer_url()); | 50 EXPECT_EQ(test_data::kReferrerURL, navigation.referrer_url()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 EXPECT_EQ(default_navigation.http_status_code(), | 68 EXPECT_EQ(default_navigation.http_status_code(), |
| 69 navigation.http_status_code()); | 69 navigation.http_status_code()); |
| 70 ASSERT_EQ(0U, navigation.redirect_chain().size()); | 70 ASSERT_EQ(0U, navigation.redirect_chain().size()); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Create a NavigationItem, then create another one by converting to | 73 // Create a NavigationItem, then create another one by converting to |
| 74 // a SerializedNavigationEntry and back. The new one should match the old one | 74 // a SerializedNavigationEntry and back. The new one should match the old one |
| 75 // except for fields that aren't preserved, which should be set to | 75 // except for fields that aren't preserved, which should be set to |
| 76 // expected values. | 76 // expected values. |
| 77 TEST(IOSSerializedNavigationBuilderTest, ToNavigationItem) { | 77 TEST(IOSSerializedNavigationBuilderTest, ToNavigationItem) { |
| 78 const scoped_ptr<web::NavigationItem> old_navigation_item( | 78 const std::unique_ptr<web::NavigationItem> old_navigation_item( |
| 79 MakeNavigationItemForTest()); | 79 MakeNavigationItemForTest()); |
| 80 | 80 |
| 81 const SerializedNavigationEntry& navigation = | 81 const SerializedNavigationEntry& navigation = |
| 82 IOSSerializedNavigationBuilder::FromNavigationItem( | 82 IOSSerializedNavigationBuilder::FromNavigationItem( |
| 83 test_data::kIndex, *old_navigation_item); | 83 test_data::kIndex, *old_navigation_item); |
| 84 | 84 |
| 85 const scoped_ptr<web::NavigationItem> new_navigation_item( | 85 const std::unique_ptr<web::NavigationItem> new_navigation_item( |
| 86 IOSSerializedNavigationBuilder::ToNavigationItem(&navigation)); | 86 IOSSerializedNavigationBuilder::ToNavigationItem(&navigation)); |
| 87 | 87 |
| 88 EXPECT_EQ(old_navigation_item->GetURL(), | 88 EXPECT_EQ(old_navigation_item->GetURL(), |
| 89 new_navigation_item->GetURL()); | 89 new_navigation_item->GetURL()); |
| 90 EXPECT_EQ(old_navigation_item->GetReferrer().url, | 90 EXPECT_EQ(old_navigation_item->GetReferrer().url, |
| 91 new_navigation_item->GetReferrer().url); | 91 new_navigation_item->GetReferrer().url); |
| 92 EXPECT_EQ(old_navigation_item->GetReferrer().policy, | 92 EXPECT_EQ(old_navigation_item->GetReferrer().policy, |
| 93 new_navigation_item->GetReferrer().policy); | 93 new_navigation_item->GetReferrer().policy); |
| 94 EXPECT_EQ(old_navigation_item->GetVirtualURL(), | 94 EXPECT_EQ(old_navigation_item->GetVirtualURL(), |
| 95 new_navigation_item->GetVirtualURL()); | 95 new_navigation_item->GetVirtualURL()); |
| 96 EXPECT_EQ(old_navigation_item->GetTitle(), | 96 EXPECT_EQ(old_navigation_item->GetTitle(), |
| 97 new_navigation_item->GetTitle()); | 97 new_navigation_item->GetTitle()); |
| 98 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, | 98 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD, |
| 99 new_navigation_item->GetTransitionType()); | 99 new_navigation_item->GetTransitionType()); |
| 100 EXPECT_EQ(old_navigation_item->GetTimestamp(), | 100 EXPECT_EQ(old_navigation_item->GetTimestamp(), |
| 101 new_navigation_item->GetTimestamp()); | 101 new_navigation_item->GetTimestamp()); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace sessions | 104 } // namespace sessions |
| OLD | NEW |