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

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: Fix win compiling error due to using unique_ptr map in SESSIONS_EXPORT class 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..5f402982435e72c63e92c029be725b0a11911c3f 100644
--- a/components/sessions/content/content_serialized_navigation_builder_unittest.cc
+++ b/components/sessions/content/content_serialized_navigation_builder_unittest.cc
@@ -4,7 +4,11 @@
#include "components/sessions/content/content_serialized_navigation_builder.h"
+#include "base/memory/ptr_util.h"
+#include "base/strings/utf_string_conversions.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 +20,35 @@
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& key) : key_(key) {}
+ ~TestExtendedInfoHandler() override {}
+
+ std::string GetExtendedInfo(
+ const content::NavigationEntry& entry) const override {
+ base::string16 data;
+ entry.GetExtraData(key_, &data);
+ return base::UTF16ToASCII(data);
+ }
+
+ void RestoreExtendedInfo(const std::string& info,
+ content::NavigationEntry* entry) override {
+ entry->SetExtraData(key_, base::ASCIIToUTF16(info));
+ }
+
+ private:
+ std::string key_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestExtendedInfoHandler);
+};
+
// Create a NavigationEntry from the test_data constants in
// serialized_navigation_entry_test_helper.h.
std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() {
@@ -49,6 +82,19 @@ std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() {
return navigation_entry;
}
+void SetExtendedInfoForTest(content::NavigationEntry* entry) {
+ entry->SetExtraData(kExtendedInfoKey1,
+ base::ASCIIToUTF16(kExtendedInfoValue1));
+ entry->SetExtraData(kExtendedInfoKey2,
+ base::ASCIIToUTF16(kExtendedInfoValue2));
+ ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
+ kExtendedInfoKey1, base::WrapUnique<ExtendedInfoHandler>(
+ new TestExtendedInfoHandler(kExtendedInfoKey1)));
+ ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
+ kExtendedInfoKey2, base::WrapUnique<ExtendedInfoHandler>(
+ new TestExtendedInfoHandler(kExtendedInfoKey2)));
+}
+
} // namespace
@@ -57,6 +103,7 @@ std::unique_ptr<content::NavigationEntry> MakeNavigationEntryForTest() {
TEST(ContentSerializedNavigationBuilderTest, FromNavigationEntry) {
const std::unique_ptr<content::NavigationEntry> navigation_entry(
MakeNavigationEntryForTest());
+ SetExtendedInfoForTest(navigation_entry.get());
const SerializedNavigationEntry& navigation =
ContentSerializedNavigationBuilder::FromNavigationEntry(
@@ -85,6 +132,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
@@ -94,6 +149,7 @@ TEST(ContentSerializedNavigationBuilderTest, FromNavigationEntry) {
TEST(ContentSerializedNavigationBuilderTest, ToNavigationEntry) {
const std::unique_ptr<content::NavigationEntry> old_navigation_entry(
MakeNavigationEntryForTest());
+ SetExtendedInfoForTest(old_navigation_entry.get());
const SerializedNavigationEntry& navigation =
ContentSerializedNavigationBuilder::FromNavigationEntry(
@@ -131,6 +187,14 @@ TEST(ContentSerializedNavigationBuilderTest, ToNavigationEntry) {
new_navigation_entry->GetRedirectChain()[1]);
EXPECT_EQ(test_data::kVirtualURL,
new_navigation_entry->GetRedirectChain()[2]);
+
+ base::string16 extra_data;
+ EXPECT_TRUE(
+ new_navigation_entry->GetExtraData(kExtendedInfoKey1, &extra_data));
+ EXPECT_EQ(kExtendedInfoValue1, base::UTF16ToASCII(extra_data));
+ EXPECT_TRUE(
+ new_navigation_entry->GetExtraData(kExtendedInfoKey2, &extra_data));
+ EXPECT_EQ(kExtendedInfoValue2, base::UTF16ToASCII(extra_data));
}
TEST(ContentSerializedNavigationBuilderTest, SetPasswordState) {

Powered by Google App Engine
This is Rietveld 408576698