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

Side by Side Diff: android_webview/native/state_serializer_unittest.cc

Issue 1687853002: Make AW state_serializer handle restoring also legacy format (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tweaks according to review suggestions Created 4 years, 10 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 | « android_webview/native/state_serializer.cc ('k') | 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 "android_webview/native/state_serializer.h" 5 #include "android_webview/native/state_serializer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h" 12 #include "base/time/time.h"
13 #include "content/public/browser/content_browser_client.h" 13 #include "content/public/browser/content_browser_client.h"
14 #include "content/public/browser/navigation_entry.h" 14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/common/content_client.h" 15 #include "content/public/common/content_client.h"
16 #include "content/public/common/page_state.h" 16 #include "content/public/common/page_state.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "url/gurl.h" 18 #include "url/gurl.h"
19 19
20 using std::string; 20 using std::string;
21 21
22 namespace android_webview { 22 namespace android_webview {
23 23
24 TEST(AndroidWebViewStateSerializerTest, TestHeaderSerialization) { 24 namespace {
mnaganov (inactive) 2016/02/11 17:21:48 nit: please put a blank line after "namespace {"
25 base::Pickle pickle; 25 static scoped_ptr<content::NavigationEntry> CreateNavigationEntry() {
26 bool result = internal::WriteHeaderToPickle(&pickle);
27 EXPECT_TRUE(result);
28
29 base::PickleIterator iterator(pickle);
30 result = internal::RestoreHeaderFromPickle(&iterator);
31 EXPECT_TRUE(result);
32 }
33
34 TEST(AndroidWebViewStateSerializerTest, TestNavigationEntrySerialization) {
35 // This is required for NavigationEntry::Create. 26 // This is required for NavigationEntry::Create.
36 content::ContentClient content_client; 27 content::ContentClient content_client;
37 content::SetContentClient(&content_client); 28 content::SetContentClient(&content_client);
38 content::ContentBrowserClient browser_client; 29 content::ContentBrowserClient browser_client;
39 content::SetBrowserClientForTesting(&browser_client); 30 content::SetBrowserClientForTesting(&browser_client);
40 31
41 scoped_ptr<content::NavigationEntry> entry( 32 scoped_ptr<content::NavigationEntry> entry(
42 content::NavigationEntry::Create()); 33 content::NavigationEntry::Create());
43 34
44 const GURL url("http://url"); 35 const GURL url("http://url");
(...skipping 21 matching lines...) Expand all
66 entry->SetOriginalRequestURL(original_request_url); 57 entry->SetOriginalRequestURL(original_request_url);
67 entry->SetBaseURLForDataURL(base_url_for_data_url); 58 entry->SetBaseURLForDataURL(base_url_for_data_url);
68 { 59 {
69 scoped_refptr<base::RefCountedString> s = new base::RefCountedString(); 60 scoped_refptr<base::RefCountedString> s = new base::RefCountedString();
70 s->data().assign(data_url_as_string); 61 s->data().assign(data_url_as_string);
71 entry->SetDataURLAsString(s); 62 entry->SetDataURLAsString(s);
72 } 63 }
73 entry->SetIsOverridingUserAgent(is_overriding_user_agent); 64 entry->SetIsOverridingUserAgent(is_overriding_user_agent);
74 entry->SetTimestamp(timestamp); 65 entry->SetTimestamp(timestamp);
75 entry->SetHttpStatusCode(http_status_code); 66 entry->SetHttpStatusCode(http_status_code);
67 return entry;
mnaganov (inactive) 2016/02/11 17:21:48 I guess you need to return std::move(entry) here.
sbergner 2016/02/12 13:00:10 Changed it at first but on second thought I don't
mnaganov (inactive) 2016/02/12 16:22:47 I was thinking that the unit tests were crashing b
68 }
69
70 } // namespace
71
72 TEST(AndroidWebViewStateSerializerTest, TestHeaderSerialization) {
73 base::Pickle pickle;
74 bool result = internal::WriteHeaderToPickle(&pickle);
75 EXPECT_TRUE(result);
76
77 base::PickleIterator iterator(pickle);
78 uint32_t version = internal::RestoreHeaderFromPickle(&iterator);
79 EXPECT_GT(version, 0U);
80 }
81
82 TEST(AndroidWebViewStateSerializerTest, TestNavigationEntrySerialization) {
83 scoped_ptr<content::NavigationEntry> entry(CreateNavigationEntry());
76 84
77 base::Pickle pickle; 85 base::Pickle pickle;
78 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle); 86 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle);
79 EXPECT_TRUE(result); 87 EXPECT_TRUE(result);
80 88
81 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create()); 89 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create());
82 base::PickleIterator iterator(pickle); 90 base::PickleIterator iterator(pickle);
83 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get()); 91 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get());
84 EXPECT_TRUE(result); 92 EXPECT_TRUE(result);
85 93
86 EXPECT_EQ(url, copy->GetURL()); 94 EXPECT_EQ(entry->GetURL(), copy->GetURL());
87 EXPECT_EQ(virtual_url, copy->GetVirtualURL()); 95 EXPECT_EQ(entry->GetVirtualURL(), copy->GetVirtualURL());
88 EXPECT_EQ(referrer.url, copy->GetReferrer().url); 96 EXPECT_EQ(entry->GetReferrer().url, copy->GetReferrer().url);
89 EXPECT_EQ(referrer.policy, copy->GetReferrer().policy); 97 EXPECT_EQ(entry->GetReferrer().policy, copy->GetReferrer().policy);
90 EXPECT_EQ(title, copy->GetTitle()); 98 EXPECT_EQ(entry->GetTitle(), copy->GetTitle());
91 EXPECT_EQ(page_state, copy->GetPageState()); 99 EXPECT_EQ(entry->GetPageState(), copy->GetPageState());
92 EXPECT_EQ(has_post_data, copy->GetHasPostData()); 100 EXPECT_EQ(entry->GetHasPostData(), copy->GetHasPostData());
93 EXPECT_EQ(original_request_url, copy->GetOriginalRequestURL()); 101 EXPECT_EQ(entry->GetOriginalRequestURL(), copy->GetOriginalRequestURL());
94 EXPECT_EQ(base_url_for_data_url, copy->GetBaseURLForDataURL()); 102 EXPECT_EQ(entry->GetBaseURLForDataURL(), copy->GetBaseURLForDataURL());
95 EXPECT_EQ(data_url_as_string, copy->GetDataURLAsString()->data()); 103 EXPECT_EQ(entry->GetDataURLAsString()->data(),
96 EXPECT_EQ(is_overriding_user_agent, copy->GetIsOverridingUserAgent()); 104 copy->GetDataURLAsString()->data());
97 EXPECT_EQ(timestamp, copy->GetTimestamp()); 105 EXPECT_EQ(entry->GetIsOverridingUserAgent(),
98 EXPECT_EQ(http_status_code, copy->GetHttpStatusCode()); 106 copy->GetIsOverridingUserAgent());
107 EXPECT_EQ(entry->GetTimestamp(), copy->GetTimestamp());
108 EXPECT_EQ(entry->GetHttpStatusCode(), copy->GetHttpStatusCode());
109 }
110
111 TEST(AndroidWebViewStateSerializerTest,
112 TestLegacyNavigationEntrySerialization) {
113 scoped_ptr<content::NavigationEntry> entry(CreateNavigationEntry());
114
115 base::Pickle pickle;
116 bool result =
117 internal::WriteNavigationEntryToPickle(20130814, *entry, &pickle);
118 EXPECT_TRUE(result);
119
120 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create());
121 base::PickleIterator iterator(pickle);
122 result = internal::RestoreNavigationEntryFromPickle(20130814, &iterator,
123 copy.get());
124 EXPECT_TRUE(result);
125
126 EXPECT_EQ(entry->GetURL(), copy->GetURL());
127 EXPECT_EQ(entry->GetVirtualURL(), copy->GetVirtualURL());
128 EXPECT_EQ(entry->GetReferrer().url, copy->GetReferrer().url);
129 EXPECT_EQ(entry->GetReferrer().policy, copy->GetReferrer().policy);
130 EXPECT_EQ(entry->GetTitle(), copy->GetTitle());
131 EXPECT_EQ(entry->GetPageState(), copy->GetPageState());
132 EXPECT_EQ(entry->GetHasPostData(), copy->GetHasPostData());
133 EXPECT_EQ(entry->GetOriginalRequestURL(), copy->GetOriginalRequestURL());
134 EXPECT_EQ(entry->GetBaseURLForDataURL(), copy->GetBaseURLForDataURL());
135 // DataURL not supported by 20130814 format
136 EXPECT_FALSE(copy->GetDataURLAsString());
137 EXPECT_EQ(entry->GetIsOverridingUserAgent(),
138 copy->GetIsOverridingUserAgent());
139 EXPECT_EQ(entry->GetTimestamp(), copy->GetTimestamp());
140 EXPECT_EQ(entry->GetHttpStatusCode(), copy->GetHttpStatusCode());
99 } 141 }
100 142
101 TEST(AndroidWebViewStateSerializerTest, TestEmptyDataURLSerialization) { 143 TEST(AndroidWebViewStateSerializerTest, TestEmptyDataURLSerialization) {
102 // This is required for NavigationEntry::Create. 144 // This is required for NavigationEntry::Create.
103 content::ContentClient content_client; 145 content::ContentClient content_client;
104 content::SetContentClient(&content_client); 146 content::SetContentClient(&content_client);
105 content::ContentBrowserClient browser_client; 147 content::ContentBrowserClient browser_client;
106 content::SetBrowserClientForTesting(&browser_client); 148 content::SetBrowserClientForTesting(&browser_client);
107 149
108 scoped_ptr<content::NavigationEntry> entry( 150 scoped_ptr<content::NavigationEntry> entry(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 EXPECT_TRUE(result); 184 EXPECT_TRUE(result);
143 185
144 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create()); 186 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create());
145 base::PickleIterator iterator(pickle); 187 base::PickleIterator iterator(pickle);
146 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get()); 188 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get());
147 EXPECT_TRUE(result); 189 EXPECT_TRUE(result);
148 EXPECT_EQ(huge_data_url, copy->GetDataURLAsString()->data()); 190 EXPECT_EQ(huge_data_url, copy->GetDataURLAsString()->data());
149 } 191 }
150 192
151 } // namespace android_webview 193 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/state_serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698