Port Android relocation packer to chromium build
[chromium-blink-merge.git] / components / sessions / ios / ios_serialized_navigation_builder_unittest.cc
bloba437c3d5d9754e5dc90cc8559e84deadfd377860
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
3 // found in the LICENSE file.
5 #include "components/sessions/ios/ios_serialized_navigation_builder.h"
7 #include "components/sessions/serialized_navigation_entry.h"
8 #include "components/sessions/serialized_navigation_entry_test_helper.h"
9 #include "ios/web/public/favicon_status.h"
10 #include "ios/web/public/navigation_item.h"
11 #include "ios/web/public/referrer.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace sessions {
16 namespace {
17 // Creates a NavigationItem from the test_data constants in
18 // serialized_navigation_entry_test_helper.h.
19 scoped_ptr<web::NavigationItem> MakeNavigationItemForTest() {
20 scoped_ptr<web::NavigationItem> navigation_item(
21 web::NavigationItem::Create());
22 navigation_item->SetReferrer(web::Referrer(
23 test_data::kReferrerURL,
24 static_cast<web::ReferrerPolicy>(test_data::kReferrerPolicy)));
25 navigation_item->SetURL(test_data::kVirtualURL);
26 navigation_item->SetTitle(test_data::kTitle);
27 navigation_item->SetTransitionType(test_data::kTransitionType);
28 navigation_item->SetTimestamp(test_data::kTimestamp);
29 navigation_item->GetFavicon().valid = true;
30 navigation_item->GetFavicon().url = test_data::kFaviconURL;
31 return navigation_item.Pass();
34 } // namespace
37 // Create a SerializedNavigationEntry from a NavigationItem. All its fields
38 // should match the NavigationItem's.
39 TEST(IOSSerializedNavigationBuilderTest, FromNavigationItem) {
40 const scoped_ptr<web::NavigationItem> navigation_item(
41 MakeNavigationItemForTest());
43 const SerializedNavigationEntry& navigation =
44 IOSSerializedNavigationBuilder::FromNavigationItem(
45 test_data::kIndex, *navigation_item);
47 EXPECT_EQ(test_data::kIndex, navigation.index());
49 EXPECT_EQ(navigation_item->GetUniqueID(), navigation.unique_id());
50 EXPECT_EQ(test_data::kReferrerURL, navigation.referrer_url());
51 EXPECT_EQ(test_data::kReferrerPolicy, navigation.referrer_policy());
52 EXPECT_EQ(test_data::kVirtualURL, navigation.virtual_url());
53 EXPECT_EQ(test_data::kTitle, navigation.title());
54 EXPECT_EQ(test_data::kTransitionType, navigation.transition_type());
55 EXPECT_EQ(test_data::kTimestamp, navigation.timestamp());
56 EXPECT_EQ(test_data::kFaviconURL, navigation.favicon_url());
58 // The following fields should be left at their default values.
59 SerializedNavigationEntry default_navigation;
60 EXPECT_EQ(default_navigation.encoded_page_state(),
61 navigation.encoded_page_state());
62 EXPECT_EQ(default_navigation.has_post_data(), navigation.has_post_data());
63 EXPECT_EQ(default_navigation.post_id(), navigation.post_id());
64 EXPECT_EQ(default_navigation.original_request_url(),
65 navigation.original_request_url());
66 EXPECT_EQ(default_navigation.is_overriding_user_agent(),
67 navigation.is_overriding_user_agent());
68 EXPECT_EQ(default_navigation.http_status_code(),
69 navigation.http_status_code());
70 ASSERT_EQ(0U, navigation.redirect_chain().size());
73 // Create a NavigationItem, then create another one by converting to
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
76 // expected values.
77 TEST(IOSSerializedNavigationBuilderTest, ToNavigationItem) {
78 const scoped_ptr<web::NavigationItem> old_navigation_item(
79 MakeNavigationItemForTest());
81 const SerializedNavigationEntry& navigation =
82 IOSSerializedNavigationBuilder::FromNavigationItem(
83 test_data::kIndex, *old_navigation_item);
85 const scoped_ptr<web::NavigationItem> new_navigation_item(
86 IOSSerializedNavigationBuilder::ToNavigationItem(
87 &navigation, test_data::kPageID));
89 EXPECT_EQ(old_navigation_item->GetURL(),
90 new_navigation_item->GetURL());
91 EXPECT_EQ(old_navigation_item->GetReferrer().url,
92 new_navigation_item->GetReferrer().url);
93 EXPECT_EQ(old_navigation_item->GetReferrer().policy,
94 new_navigation_item->GetReferrer().policy);
95 EXPECT_EQ(old_navigation_item->GetVirtualURL(),
96 new_navigation_item->GetVirtualURL());
97 EXPECT_EQ(old_navigation_item->GetTitle(),
98 new_navigation_item->GetTitle());
99 EXPECT_EQ(test_data::kPageID, new_navigation_item->GetPageID());
100 EXPECT_EQ(ui::PAGE_TRANSITION_RELOAD,
101 new_navigation_item->GetTransitionType());
102 EXPECT_EQ(old_navigation_item->GetTimestamp(),
103 new_navigation_item->GetTimestamp());
106 } // namespace sessions