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

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

Issue 2384403005: Fix flaky test ContentSerializedNavigationBuilderTest.ToNavigationEntry (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/ptr_util.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/sessions/content/content_record_password_state.h" 9 #include "components/sessions/content/content_record_password_state.h"
10 #include "components/sessions/content/content_serialized_navigation_driver.h" 10 #include "components/sessions/content/content_serialized_navigation_driver.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 redirect_chain.push_back(test_data::kVirtualURL); 80 redirect_chain.push_back(test_data::kVirtualURL);
81 navigation_entry->SetRedirectChain(redirect_chain); 81 navigation_entry->SetRedirectChain(redirect_chain);
82 return navigation_entry; 82 return navigation_entry;
83 } 83 }
84 84
85 void SetExtendedInfoForTest(content::NavigationEntry* entry) { 85 void SetExtendedInfoForTest(content::NavigationEntry* entry) {
86 entry->SetExtraData(kExtendedInfoKey1, 86 entry->SetExtraData(kExtendedInfoKey1,
87 base::ASCIIToUTF16(kExtendedInfoValue1)); 87 base::ASCIIToUTF16(kExtendedInfoValue1));
88 entry->SetExtraData(kExtendedInfoKey2, 88 entry->SetExtraData(kExtendedInfoKey2,
89 base::ASCIIToUTF16(kExtendedInfoValue2)); 89 base::ASCIIToUTF16(kExtendedInfoValue2));
90 ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
91 kExtendedInfoKey1, base::WrapUnique<ExtendedInfoHandler>(
92 new TestExtendedInfoHandler(kExtendedInfoKey1)));
93 ContentSerializedNavigationDriver::GetInstance()->RegisterExtendedInfoHandler(
94 kExtendedInfoKey2, base::WrapUnique<ExtendedInfoHandler>(
95 new TestExtendedInfoHandler(kExtendedInfoKey2)));
96 } 90 }
97 91
98 } // namespace 92 } // namespace
99 93
94 class ContentSerializedNavigationBuilderTest : public testing::Test {
95 public:
96 ContentSerializedNavigationBuilderTest() {}
97 ~ContentSerializedNavigationBuilderTest() override {}
98
99 static void SetUpTestCase() {
100 ContentSerializedNavigationDriver::GetInstance()->
sky 2016/10/06 17:01:47 While this works for your test, it means any other
jianli 2016/10/06 23:54:50 Done.
101 RegisterExtendedInfoHandler(
102 kExtendedInfoKey1,
103 base::WrapUnique<ExtendedInfoHandler>(
104 new TestExtendedInfoHandler(kExtendedInfoKey1)));
105 ContentSerializedNavigationDriver::GetInstance()->
106 RegisterExtendedInfoHandler(
107 kExtendedInfoKey2,
108 base::WrapUnique<ExtendedInfoHandler>(
109 new TestExtendedInfoHandler(kExtendedInfoKey2)));
110 }
111 };
100 112
101 // Create a SerializedNavigationEntry from a NavigationEntry. All its fields 113 // Create a SerializedNavigationEntry from a NavigationEntry. All its fields
102 // should match the NavigationEntry's. 114 // should match the NavigationEntry's.
103 TEST(ContentSerializedNavigationBuilderTest, FromNavigationEntry) { 115 TEST_F(ContentSerializedNavigationBuilderTest, FromNavigationEntry) {
104 const std::unique_ptr<content::NavigationEntry> navigation_entry( 116 const std::unique_ptr<content::NavigationEntry> navigation_entry(
105 MakeNavigationEntryForTest()); 117 MakeNavigationEntryForTest());
106 SetExtendedInfoForTest(navigation_entry.get()); 118 SetExtendedInfoForTest(navigation_entry.get());
107 119
108 const SerializedNavigationEntry& navigation = 120 const SerializedNavigationEntry& navigation =
109 ContentSerializedNavigationBuilder::FromNavigationEntry( 121 ContentSerializedNavigationBuilder::FromNavigationEntry(
110 test_data::kIndex, *navigation_entry); 122 test_data::kIndex, *navigation_entry);
111 123
112 EXPECT_EQ(test_data::kIndex, navigation.index()); 124 EXPECT_EQ(test_data::kIndex, navigation.index());
113 125
(...skipping 25 matching lines...) Expand all
139 navigation.extended_info_map().at(kExtendedInfoKey1)); 151 navigation.extended_info_map().at(kExtendedInfoKey1));
140 ASSERT_EQ(1U, navigation.extended_info_map().count(kExtendedInfoKey2)); 152 ASSERT_EQ(1U, navigation.extended_info_map().count(kExtendedInfoKey2));
141 EXPECT_EQ(kExtendedInfoValue2, 153 EXPECT_EQ(kExtendedInfoValue2,
142 navigation.extended_info_map().at(kExtendedInfoKey2)); 154 navigation.extended_info_map().at(kExtendedInfoKey2));
143 } 155 }
144 156
145 // Create a NavigationEntry, then create another one by converting to 157 // Create a NavigationEntry, then create another one by converting to
146 // a SerializedNavigationEntry and back. The new one should match the old one 158 // a SerializedNavigationEntry and back. The new one should match the old one
147 // except for fields that aren't preserved, which should be set to 159 // except for fields that aren't preserved, which should be set to
148 // expected values. 160 // expected values.
149 TEST(ContentSerializedNavigationBuilderTest, ToNavigationEntry) { 161 TEST_F(ContentSerializedNavigationBuilderTest, ToNavigationEntry) {
150 const std::unique_ptr<content::NavigationEntry> old_navigation_entry( 162 const std::unique_ptr<content::NavigationEntry> old_navigation_entry(
151 MakeNavigationEntryForTest()); 163 MakeNavigationEntryForTest());
152 SetExtendedInfoForTest(old_navigation_entry.get()); 164 SetExtendedInfoForTest(old_navigation_entry.get());
153 165
154 const SerializedNavigationEntry& navigation = 166 const SerializedNavigationEntry& navigation =
155 ContentSerializedNavigationBuilder::FromNavigationEntry( 167 ContentSerializedNavigationBuilder::FromNavigationEntry(
156 test_data::kIndex, *old_navigation_entry); 168 test_data::kIndex, *old_navigation_entry);
157 169
158 const std::unique_ptr<content::NavigationEntry> new_navigation_entry( 170 const std::unique_ptr<content::NavigationEntry> new_navigation_entry(
159 ContentSerializedNavigationBuilder::ToNavigationEntry( 171 ContentSerializedNavigationBuilder::ToNavigationEntry(
(...skipping 30 matching lines...) Expand all
190 202
191 base::string16 extra_data; 203 base::string16 extra_data;
192 EXPECT_TRUE( 204 EXPECT_TRUE(
193 new_navigation_entry->GetExtraData(kExtendedInfoKey1, &extra_data)); 205 new_navigation_entry->GetExtraData(kExtendedInfoKey1, &extra_data));
194 EXPECT_EQ(kExtendedInfoValue1, base::UTF16ToASCII(extra_data)); 206 EXPECT_EQ(kExtendedInfoValue1, base::UTF16ToASCII(extra_data));
195 EXPECT_TRUE( 207 EXPECT_TRUE(
196 new_navigation_entry->GetExtraData(kExtendedInfoKey2, &extra_data)); 208 new_navigation_entry->GetExtraData(kExtendedInfoKey2, &extra_data));
197 EXPECT_EQ(kExtendedInfoValue2, base::UTF16ToASCII(extra_data)); 209 EXPECT_EQ(kExtendedInfoValue2, base::UTF16ToASCII(extra_data));
198 } 210 }
199 211
200 TEST(ContentSerializedNavigationBuilderTest, SetPasswordState) { 212 TEST_F(ContentSerializedNavigationBuilderTest, SetPasswordState) {
201 std::unique_ptr<content::NavigationEntry> entry( 213 std::unique_ptr<content::NavigationEntry> entry(
202 content::NavigationEntry::Create()); 214 content::NavigationEntry::Create());
203 215
204 EXPECT_EQ(SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN, 216 EXPECT_EQ(SerializedNavigationEntry::PASSWORD_STATE_UNKNOWN,
205 GetPasswordStateFromNavigation(*entry)); 217 GetPasswordStateFromNavigation(*entry));
206 SetPasswordStateInNavigation(SerializedNavigationEntry::NO_PASSWORD_FIELD, 218 SetPasswordStateInNavigation(SerializedNavigationEntry::NO_PASSWORD_FIELD,
207 entry.get()); 219 entry.get());
208 EXPECT_EQ(SerializedNavigationEntry::NO_PASSWORD_FIELD, 220 EXPECT_EQ(SerializedNavigationEntry::NO_PASSWORD_FIELD,
209 GetPasswordStateFromNavigation(*entry)); 221 GetPasswordStateFromNavigation(*entry));
210 } 222 }
211 223
212 } // namespace sessions 224 } // namespace sessions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698