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

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

Issue 1497743005: Allow huge data: URIs only via WebView.loadDataWithBaseUrl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the test Created 5 years 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 "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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 const GURL virtual_url("http://virtual_url"); 45 const GURL virtual_url("http://virtual_url");
46 content::Referrer referrer; 46 content::Referrer referrer;
47 referrer.url = GURL("http://referrer_url"); 47 referrer.url = GURL("http://referrer_url");
48 referrer.policy = blink::WebReferrerPolicyOrigin; 48 referrer.policy = blink::WebReferrerPolicyOrigin;
49 const base::string16 title(base::UTF8ToUTF16("title")); 49 const base::string16 title(base::UTF8ToUTF16("title"));
50 const content::PageState page_state = 50 const content::PageState page_state =
51 content::PageState::CreateFromEncodedData("completely bogus state"); 51 content::PageState::CreateFromEncodedData("completely bogus state");
52 const bool has_post_data = true; 52 const bool has_post_data = true;
53 const GURL original_request_url("http://original_request_url"); 53 const GURL original_request_url("http://original_request_url");
54 const GURL base_url_for_data_url("http://base_url"); 54 const GURL base_url_for_data_url("http://base_url");
55 const string data_url_as_string("data:text/html;charset=utf-8;base64,");
55 const bool is_overriding_user_agent = true; 56 const bool is_overriding_user_agent = true;
56 const base::Time timestamp = base::Time::FromInternalValue(12345); 57 const base::Time timestamp = base::Time::FromInternalValue(12345);
57 const int http_status_code = 404; 58 const int http_status_code = 404;
58 59
59 entry->SetURL(url); 60 entry->SetURL(url);
60 entry->SetVirtualURL(virtual_url); 61 entry->SetVirtualURL(virtual_url);
61 entry->SetReferrer(referrer); 62 entry->SetReferrer(referrer);
62 entry->SetTitle(title); 63 entry->SetTitle(title);
63 entry->SetPageState(page_state); 64 entry->SetPageState(page_state);
64 entry->SetHasPostData(has_post_data); 65 entry->SetHasPostData(has_post_data);
65 entry->SetOriginalRequestURL(original_request_url); 66 entry->SetOriginalRequestURL(original_request_url);
66 entry->SetBaseURLForDataURL(base_url_for_data_url); 67 entry->SetBaseURLForDataURL(base_url_for_data_url);
68 {
69 scoped_refptr<base::RefCountedString> s = new base::RefCountedString();
70 s->data().assign(data_url_as_string);
71 entry->SetDataURLAsString(s);
72 }
67 entry->SetIsOverridingUserAgent(is_overriding_user_agent); 73 entry->SetIsOverridingUserAgent(is_overriding_user_agent);
68 entry->SetTimestamp(timestamp); 74 entry->SetTimestamp(timestamp);
69 entry->SetHttpStatusCode(http_status_code); 75 entry->SetHttpStatusCode(http_status_code);
70 76
71 base::Pickle pickle; 77 base::Pickle pickle;
72 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle); 78 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle);
73 EXPECT_TRUE(result); 79 EXPECT_TRUE(result);
74 80
75 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create()); 81 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create());
76 base::PickleIterator iterator(pickle); 82 base::PickleIterator iterator(pickle);
77 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get()); 83 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get());
78 EXPECT_TRUE(result); 84 EXPECT_TRUE(result);
79 85
80 EXPECT_EQ(url, copy->GetURL()); 86 EXPECT_EQ(url, copy->GetURL());
81 EXPECT_EQ(virtual_url, copy->GetVirtualURL()); 87 EXPECT_EQ(virtual_url, copy->GetVirtualURL());
82 EXPECT_EQ(referrer.url, copy->GetReferrer().url); 88 EXPECT_EQ(referrer.url, copy->GetReferrer().url);
83 EXPECT_EQ(referrer.policy, copy->GetReferrer().policy); 89 EXPECT_EQ(referrer.policy, copy->GetReferrer().policy);
84 EXPECT_EQ(title, copy->GetTitle()); 90 EXPECT_EQ(title, copy->GetTitle());
85 EXPECT_EQ(page_state, copy->GetPageState()); 91 EXPECT_EQ(page_state, copy->GetPageState());
86 EXPECT_EQ(has_post_data, copy->GetHasPostData()); 92 EXPECT_EQ(has_post_data, copy->GetHasPostData());
87 EXPECT_EQ(original_request_url, copy->GetOriginalRequestURL()); 93 EXPECT_EQ(original_request_url, copy->GetOriginalRequestURL());
88 EXPECT_EQ(base_url_for_data_url, copy->GetBaseURLForDataURL()); 94 EXPECT_EQ(base_url_for_data_url, copy->GetBaseURLForDataURL());
95 EXPECT_EQ(data_url_as_string, copy->GetDataURLAsString()->data());
89 EXPECT_EQ(is_overriding_user_agent, copy->GetIsOverridingUserAgent()); 96 EXPECT_EQ(is_overriding_user_agent, copy->GetIsOverridingUserAgent());
90 EXPECT_EQ(timestamp, copy->GetTimestamp()); 97 EXPECT_EQ(timestamp, copy->GetTimestamp());
91 EXPECT_EQ(http_status_code, copy->GetHttpStatusCode()); 98 EXPECT_EQ(http_status_code, copy->GetHttpStatusCode());
92 } 99 }
93 100
101 TEST(AndroidWebViewStateSerializerTest, TestEmptyDataURLSerialization) {
102 // This is required for NavigationEntry::Create.
103 content::ContentClient content_client;
104 content::SetContentClient(&content_client);
105 content::ContentBrowserClient browser_client;
106 content::SetBrowserClientForTesting(&browser_client);
107
108 scoped_ptr<content::NavigationEntry> entry(
109 content::NavigationEntry::Create());
110 EXPECT_FALSE(entry->GetDataURLAsString());
111
112 base::Pickle pickle;
113 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle);
114 EXPECT_TRUE(result);
115
116 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create());
117 base::PickleIterator iterator(pickle);
118 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get());
119 EXPECT_TRUE(result);
120 EXPECT_FALSE(entry->GetDataURLAsString());
121 }
122
123 TEST(AndroidWebViewStateSerializerTest, TestHugeDataURLSerialization) {
124 // This is required for NavigationEntry::Create.
125 content::ContentClient content_client;
126 content::SetContentClient(&content_client);
127 content::ContentBrowserClient browser_client;
128 content::SetBrowserClientForTesting(&browser_client);
129
130 scoped_ptr<content::NavigationEntry> entry(
131 content::NavigationEntry::Create());
132 string huge_data_url(1024 * 1024 * 20 - 1, 'd');
133 huge_data_url.replace(0, strlen(url::kDataScheme), url::kDataScheme);
134 {
135 scoped_refptr<base::RefCountedString> s = new base::RefCountedString();
136 s->data().assign(huge_data_url);
137 entry->SetDataURLAsString(s);
138 }
139
140 base::Pickle pickle;
141 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle);
142 EXPECT_TRUE(result);
143
144 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create());
145 base::PickleIterator iterator(pickle);
146 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get());
147 EXPECT_TRUE(result);
148 EXPECT_EQ(huge_data_url, copy->GetDataURLAsString()->data());
149 }
150
94 } // namespace android_webview 151 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/native/state_serializer.cc ('k') | content/browser/frame_host/navigation_controller_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698