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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
Index: components/sessions/content/content_serialized_navigation_builder_unittest.cc
diff --git a/components/sessions/content/content_serialized_navigation_builder_unittest.cc b/components/sessions/content/content_serialized_navigation_builder_unittest.cc
index 54270250af811acff3a4d3c92bcd5901ca12c9cf..ea0ec63aa1a56d4a0f09183a5e2b21a561cd7c6f 100644
--- a/components/sessions/content/content_serialized_navigation_builder_unittest.cc
+++ b/components/sessions/content/content_serialized_navigation_builder_unittest.cc
@@ -4,7 +4,10 @@
#include "components/sessions/content/content_serialized_navigation_builder.h"
+#include "base/memory/ptr_util.h"
#include "components/sessions/content/content_record_password_state.h"
+#include "components/sessions/content/content_serialized_navigation_driver.h"
+#include "components/sessions/content/extended_info_handler.h"
#include "components/sessions/core/serialized_navigation_entry.h"
#include "components/sessions/core/serialized_navigation_entry_test_helper.h"
#include "content/public/browser/favicon_status.h"
@@ -16,6 +19,30 @@
namespace sessions {
namespace {
+
+const char kExtendedInfoKey1[] = "Key 1";
+const char kExtendedInfoValue1[] = "Value 1";
+const char kExtendedInfoKey2[] = "Key 2";
+const char kExtendedInfoValue2[] = "Value 2";
+
+class TestExtendedInfoHandler : public ExtendedInfoHandler {
+ public:
+ explicit TestExtendedInfoHandler(const std::string& value) : value_(value) {}
+ ~TestExtendedInfoHandler() override {}
+
+ std::string GetExtendedInfo(
+ const content::NavigationEntry& entry) const override {
+ return value_;
+ }
+
+ void RestoreExtendedInfo(
+ 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.
+ }
+
+ private:
+ std::string value_;
+};
sky 2016/09/29 03:08:19 DISALLOW. Also, run git cl format as your spacing
jianli 2016/09/29 22:02:29 Done.
+
// Create a NavigationEntry from the test_data constants in
// serialized_navigation_entry_test_helper.h.
std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() {
@@ -55,6 +82,15 @@ std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() {
// Create a SerializedNavigationEntry from a NavigationEntry. All its fields
// should match the NavigationEntry's.
TEST(ContentSerializedNavigationBuilderTest, FromNavigationEntry) {
+ ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
+ kExtendedInfoKey1,
+ base::WrapUnique<ExtendedInfoHandler>(
+ new TestExtendedInfoHandler(kExtendedInfoValue1)));
+ ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
+ kExtendedInfoKey2,
+ base::WrapUnique<ExtendedInfoHandler>(
+ new TestExtendedInfoHandler(kExtendedInfoValue2)));
+
const std::unique_ptr<content::NavigationEntry> navigation_entry(
MakeNavigationEntryForTest());
@@ -85,6 +121,14 @@ TEST(ContentSerializedNavigationBuilderTest, FromNavigationEntry) {
EXPECT_EQ(test_data::kRedirectURL1, navigation.redirect_chain()[1]);
EXPECT_EQ(test_data::kVirtualURL, navigation.redirect_chain()[2]);
EXPECT_EQ(test_data::kPasswordState, navigation.password_state());
+
+ ASSERT_EQ(2U, navigation.extended_info_map().size());
+ ASSERT_EQ(1U, navigation.extended_info_map().count(kExtendedInfoKey1));
+ EXPECT_EQ(kExtendedInfoValue1,
+ navigation.extended_info_map().at(kExtendedInfoKey1));
+ ASSERT_EQ(1U, navigation.extended_info_map().count(kExtendedInfoKey2));
+ EXPECT_EQ(kExtendedInfoValue2,
+ navigation.extended_info_map().at(kExtendedInfoKey2));
}
// Create a NavigationEntry, then create another one by converting to

Powered by Google App Engine
This is Rietveld 408576698