Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(663)

Side by Side Diff: components/sessions/content/content_serialized_navigation_builder_unittest.cc

Issue 2310363002: Persist offline page info in a navigation entry if needed (Closed)
Patch Set: Update Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/content/content_serialized_navigation_builder.h" 5 #include "components/sessions/content/content_serialized_navigation_builder.h"
6 6
7 #include "base/memory/ptr_util.h"
7 #include "components/sessions/content/content_record_password_state.h" 8 #include "components/sessions/content/content_record_password_state.h"
9 #include "components/sessions/content/content_serialized_navigation_driver.h"
10 #include "components/sessions/content/extended_info_handler.h"
8 #include "components/sessions/core/serialized_navigation_entry.h" 11 #include "components/sessions/core/serialized_navigation_entry.h"
9 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" 12 #include "components/sessions/core/serialized_navigation_entry_test_helper.h"
10 #include "content/public/browser/favicon_status.h" 13 #include "content/public/browser/favicon_status.h"
11 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/common/page_state.h" 15 #include "content/public/common/page_state.h"
13 #include "content/public/common/referrer.h" 16 #include "content/public/common/referrer.h"
14 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
15 18
16 namespace sessions { 19 namespace sessions {
17 20
18 namespace { 21 namespace {
22
23 const char kExtendedInfoKey1[] = "Key 1";
24 const char kExtendedInfoValue1[] = "Value 1";
25 const char kExtendedInfoKey2[] = "Key 2";
26 const char kExtendedInfoValue2[] = "Value 2";
27
28 class TestExtendedInfoHandler : public ExtendedInfoHandler {
29 public:
30 explicit TestExtendedInfoHandler(const std::string& value) : value_(value) {}
31 ~TestExtendedInfoHandler() override {}
32
33 std::string GetExtendedInfo(
34 const content::NavigationEntry& entry) const override {
35 return value_;
36 }
37
38 void RestoreExtendedInfo(
39 const std::string& info, content::NavigationEntry* entry) override {
sky 2016/09/29 03:08:19 Write test coverage to ensure this is called too.
jianli 2016/09/29 22:02:29 Done.
40 }
41
42 private:
43 std::string value_;
44 };
sky 2016/09/29 03:08:19 DISALLOW. Also, run git cl format as your spacing
jianli 2016/09/29 22:02:29 Done.
45
19 // Create a NavigationEntry from the test_data constants in 46 // Create a NavigationEntry from the test_data constants in
20 // serialized_navigation_entry_test_helper.h. 47 // serialized_navigation_entry_test_helper.h.
21 std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() { 48 std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() {
22 std::unique_ptr<content::NavigationEntry> navigation_entry( 49 std::unique_ptr<content::NavigationEntry> navigation_entry(
23 content::NavigationEntry::Create()); 50 content::NavigationEntry::Create());
24 navigation_entry->SetReferrer(content::Referrer( 51 navigation_entry->SetReferrer(content::Referrer(
25 test_data::kReferrerURL, 52 test_data::kReferrerURL,
26 static_cast<blink::WebReferrerPolicy>(test_data::kReferrerPolicy))); 53 static_cast<blink::WebReferrerPolicy>(test_data::kReferrerPolicy)));
27 navigation_entry->SetVirtualURL(test_data::kVirtualURL); 54 navigation_entry->SetVirtualURL(test_data::kVirtualURL);
28 navigation_entry->SetTitle(test_data::kTitle); 55 navigation_entry->SetTitle(test_data::kTitle);
(...skipping 19 matching lines...) Expand all
48 navigation_entry->SetRedirectChain(redirect_chain); 75 navigation_entry->SetRedirectChain(redirect_chain);
49 return navigation_entry; 76 return navigation_entry;
50 } 77 }
51 78
52 } // namespace 79 } // namespace
53 80
54 81
55 // Create a SerializedNavigationEntry from a NavigationEntry. All its fields 82 // Create a SerializedNavigationEntry from a NavigationEntry. All its fields
56 // should match the NavigationEntry's. 83 // should match the NavigationEntry's.
57 TEST(ContentSerializedNavigationBuilderTest, FromNavigationEntry) { 84 TEST(ContentSerializedNavigationBuilderTest, FromNavigationEntry) {
85 ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
86 kExtendedInfoKey1,
87 base::WrapUnique<ExtendedInfoHandler>(
88 new TestExtendedInfoHandler(kExtendedInfoValue1)));
89 ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
90 kExtendedInfoKey2,
91 base::WrapUnique<ExtendedInfoHandler>(
92 new TestExtendedInfoHandler(kExtendedInfoValue2)));
93
58 const std::unique_ptr<content::NavigationEntry> navigation_entry( 94 const std::unique_ptr<content::NavigationEntry> navigation_entry(
59 MakeNavigationEntryForTest()); 95 MakeNavigationEntryForTest());
60 96
61 const SerializedNavigationEntry& navigation = 97 const SerializedNavigationEntry& navigation =
62 ContentSerializedNavigationBuilder::FromNavigationEntry( 98 ContentSerializedNavigationBuilder::FromNavigationEntry(
63 test_data::kIndex, *navigation_entry); 99 test_data::kIndex, *navigation_entry);
64 100
65 EXPECT_EQ(test_data::kIndex, navigation.index()); 101 EXPECT_EQ(test_data::kIndex, navigation.index());
66 102
67 EXPECT_EQ(navigation_entry->GetUniqueID(), navigation.unique_id()); 103 EXPECT_EQ(navigation_entry->GetUniqueID(), navigation.unique_id());
(...skipping 10 matching lines...) Expand all
78 EXPECT_EQ(test_data::kIsOverridingUserAgent, 114 EXPECT_EQ(test_data::kIsOverridingUserAgent,
79 navigation.is_overriding_user_agent()); 115 navigation.is_overriding_user_agent());
80 EXPECT_EQ(test_data::kTimestamp, navigation.timestamp()); 116 EXPECT_EQ(test_data::kTimestamp, navigation.timestamp());
81 EXPECT_EQ(test_data::kFaviconURL, navigation.favicon_url()); 117 EXPECT_EQ(test_data::kFaviconURL, navigation.favicon_url());
82 EXPECT_EQ(test_data::kHttpStatusCode, navigation.http_status_code()); 118 EXPECT_EQ(test_data::kHttpStatusCode, navigation.http_status_code());
83 ASSERT_EQ(3U, navigation.redirect_chain().size()); 119 ASSERT_EQ(3U, navigation.redirect_chain().size());
84 EXPECT_EQ(test_data::kRedirectURL0, navigation.redirect_chain()[0]); 120 EXPECT_EQ(test_data::kRedirectURL0, navigation.redirect_chain()[0]);
85 EXPECT_EQ(test_data::kRedirectURL1, navigation.redirect_chain()[1]); 121 EXPECT_EQ(test_data::kRedirectURL1, navigation.redirect_chain()[1]);
86 EXPECT_EQ(test_data::kVirtualURL, navigation.redirect_chain()[2]); 122 EXPECT_EQ(test_data::kVirtualURL, navigation.redirect_chain()[2]);
87 EXPECT_EQ(test_data::kPasswordState, navigation.password_state()); 123 EXPECT_EQ(test_data::kPasswordState, navigation.password_state());
124
125 ASSERT_EQ(2U, navigation.extended_info_map().size());
126 ASSERT_EQ(1U, navigation.extended_info_map().count(kExtendedInfoKey1));
127 EXPECT_EQ(kExtendedInfoValue1,
128 navigation.extended_info_map().at(kExtendedInfoKey1));
129 ASSERT_EQ(1U, navigation.extended_info_map().count(kExtendedInfoKey2));
130 EXPECT_EQ(kExtendedInfoValue2,
131 navigation.extended_info_map().at(kExtendedInfoKey2));
88 } 132 }
89 133
90 // Create a NavigationEntry, then create another one by converting to 134 // Create a NavigationEntry, then create another one by converting to
91 // a SerializedNavigationEntry and back. The new one should match the old one 135 // a SerializedNavigationEntry and back. The new one should match the old one
92 // except for fields that aren't preserved, which should be set to 136 // except for fields that aren't preserved, which should be set to
93 // expected values. 137 // expected values.
94 TEST(ContentSerializedNavigationBuilderTest, ToNavigationEntry) { 138 TEST(ContentSerializedNavigationBuilderTest, ToNavigationEntry) {
95 const std::unique_ptr<content::NavigationEntry> old_navigation_entry( 139 const std::unique_ptr<content::NavigationEntry> old_navigation_entry(
96 MakeNavigationEntryForTest()); 140 MakeNavigationEntryForTest());
97 141
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 183
140 EXPECT_EQ(SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN, 184 EXPECT_EQ(SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN,
141 GetPasswordStateFromNavigation(*entry)); 185 GetPasswordStateFromNavigation(*entry));
142 SetPasswordStateInNavigation(SerializedNavigationEntry::NO_PASSWORD_FIELD, 186 SetPasswordStateInNavigation(SerializedNavigationEntry::NO_PASSWORD_FIELD,
143 entry.get()); 187 entry.get());
144 EXPECT_EQ(SerializedNavigationEntry::NO_PASSWORD_FIELD, 188 EXPECT_EQ(SerializedNavigationEntry::NO_PASSWORD_FIELD,
145 GetPasswordStateFromNavigation(*entry)); 189 GetPasswordStateFromNavigation(*entry));
146 } 190 }
147 191
148 } // namespace sessions 192 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698