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

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

Issue 2310363002: Persist offline page info in a navigation entry if needed (Closed)
Patch Set: Add extended info support 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_driver.h" 5 #include "components/sessions/content/content_serialized_navigation_driver.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 "content/public/common/page_state.h" 9 #include "content/public/common/page_state.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 11 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
12 #include "ui/base/page_transition_types.h" 12 #include "ui/base/page_transition_types.h"
13 13
14 namespace sessions { 14 namespace sessions {
15 15
16 namespace {
17 const char kExtendedInfoKey[] = "Key 1";
18 const char kExtendedInfoValue[] = "Value 1";
19
20 class TestExtendedInfoHandler :
21 public SerializedNavigationDriver::ExtendedInfoHandler {
22 public:
23 TestExtendedInfoHandler() {}
24 ~TestExtendedInfoHandler() override {}
25
26 std::string GetExtendedInfo(
27 const content::NavigationEntry& entry) const override {
28 return kExtendedInfoValue;
29 }
30
31 void RestoreExtendedInfo(
32 const std::string& info, content::NavigationEntry* entry) override {
33
34 }
35 };
36
37 } // namespace
38
16 // Tests that PageState data is properly sanitized when post data is present. 39 // Tests that PageState data is properly sanitized when post data is present.
17 TEST(ContentSerializedNavigationDriverTest, PickleSanitizationWithPostData) { 40 TEST(ContentSerializedNavigationDriverTest, PickleSanitizationWithPostData) {
18 ContentSerializedNavigationDriver* driver = 41 ContentSerializedNavigationDriver* driver =
19 ContentSerializedNavigationDriver::GetInstance(); 42 ContentSerializedNavigationDriver::GetInstance();
20 SerializedNavigationEntry navigation = 43 SerializedNavigationEntry navigation =
21 SerializedNavigationEntryTestHelper::CreateNavigationForTest(); 44 SerializedNavigationEntryTestHelper::CreateNavigationForTest();
22 ASSERT_TRUE(navigation.has_post_data()); 45 ASSERT_TRUE(navigation.has_post_data());
23 46
24 // When post data is present, the page state should be sanitized. 47 // When post data is present, the page state should be sanitized.
25 std::string sanitized_page_state = 48 std::string sanitized_page_state =
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 EXPECT_EQ(test_data::kSearchTerms, navigation.search_terms()); 133 EXPECT_EQ(test_data::kSearchTerms, navigation.search_terms());
111 EXPECT_EQ(test_data::kFaviconURL, navigation.favicon_url()); 134 EXPECT_EQ(test_data::kFaviconURL, navigation.favicon_url());
112 EXPECT_EQ(test_data::kHttpStatusCode, navigation.http_status_code()); 135 EXPECT_EQ(test_data::kHttpStatusCode, navigation.http_status_code());
113 136
114 // Fields that were sanitized. 137 // Fields that were sanitized.
115 EXPECT_EQ(GURL(), navigation.referrer_url()); 138 EXPECT_EQ(GURL(), navigation.referrer_url());
116 EXPECT_EQ(blink::WebReferrerPolicyDefault, navigation.referrer_policy()); 139 EXPECT_EQ(blink::WebReferrerPolicyDefault, navigation.referrer_policy());
117 EXPECT_EQ(page_state.ToEncodedData(), navigation.encoded_page_state()); 140 EXPECT_EQ(page_state.ToEncodedData(), navigation.encoded_page_state());
118 } 141 }
119 142
143 TEST(ContentSerializedNavigationDriverTest, ExtendedInfoHandler) {
144 ContentSerializedNavigationDriver* driver =
145 ContentSerializedNavigationDriver::GetInstance();
146
147 std::unique_ptr<SerializedNavigationDriver::ExtendedInfoHandler> handler(
148 new TestExtendedInfoHandler);
149 driver->RegisterExtendedInfoHandler(kExtendedInfoKey, std::move(handler));
150 EXPECT_EQ(1U, driver->GetAllExtendedInfoHandlers().size());
151 }
152
120 } // namespace sessions 153 } // namespace sessions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698