OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.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 "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 | 19 |
19 using std::string; | 20 using std::string; |
20 | 21 |
21 namespace android_webview { | 22 namespace android_webview { |
22 | 23 |
23 TEST(AndroidWebViewStateSerializerTest, TestHeaderSerialization) { | 24 TEST(AndroidWebViewStateSerializerTest, TestHeaderSerialization) { |
24 Pickle pickle; | 25 Pickle pickle; |
25 bool result = internal::WriteHeaderToPickle(&pickle); | 26 bool result = internal::WriteHeaderToPickle(&pickle); |
(...skipping 13 matching lines...) Expand all Loading... |
39 | 40 |
40 scoped_ptr<content::NavigationEntry> entry( | 41 scoped_ptr<content::NavigationEntry> entry( |
41 content::NavigationEntry::Create()); | 42 content::NavigationEntry::Create()); |
42 | 43 |
43 const GURL url("http://url"); | 44 const GURL url("http://url"); |
44 const GURL virtual_url("http://virtual_url"); | 45 const GURL virtual_url("http://virtual_url"); |
45 content::Referrer referrer; | 46 content::Referrer referrer; |
46 referrer.url = GURL("http://referrer_url"); | 47 referrer.url = GURL("http://referrer_url"); |
47 referrer.policy = WebKit::WebReferrerPolicyOrigin; | 48 referrer.policy = WebKit::WebReferrerPolicyOrigin; |
48 const string16 title(UTF8ToUTF16("title")); | 49 const string16 title(UTF8ToUTF16("title")); |
49 const string content_state("completely bogus state"); | 50 const content::PageState page_state = |
| 51 content::PageState::CreateFromEncodedData("completely bogus state"); |
50 const bool has_post_data = true; | 52 const bool has_post_data = true; |
51 const GURL original_request_url("http://original_request_url"); | 53 const GURL original_request_url("http://original_request_url"); |
52 const GURL base_url_for_data_url("http://base_url"); | 54 const GURL base_url_for_data_url("http://base_url"); |
53 const bool is_overriding_user_agent = true; | 55 const bool is_overriding_user_agent = true; |
54 const base::Time timestamp = base::Time::FromInternalValue(12345); | 56 const base::Time timestamp = base::Time::FromInternalValue(12345); |
55 | 57 |
56 entry->SetURL(url); | 58 entry->SetURL(url); |
57 entry->SetVirtualURL(virtual_url); | 59 entry->SetVirtualURL(virtual_url); |
58 entry->SetReferrer(referrer); | 60 entry->SetReferrer(referrer); |
59 entry->SetTitle(title); | 61 entry->SetTitle(title); |
60 entry->SetContentState(content_state); | 62 entry->SetPageState(page_state); |
61 entry->SetHasPostData(has_post_data); | 63 entry->SetHasPostData(has_post_data); |
62 entry->SetOriginalRequestURL(original_request_url); | 64 entry->SetOriginalRequestURL(original_request_url); |
63 entry->SetBaseURLForDataURL(base_url_for_data_url); | 65 entry->SetBaseURLForDataURL(base_url_for_data_url); |
64 entry->SetIsOverridingUserAgent(is_overriding_user_agent); | 66 entry->SetIsOverridingUserAgent(is_overriding_user_agent); |
65 entry->SetTimestamp(timestamp); | 67 entry->SetTimestamp(timestamp); |
66 | 68 |
67 Pickle pickle; | 69 Pickle pickle; |
68 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle); | 70 bool result = internal::WriteNavigationEntryToPickle(*entry, &pickle); |
69 EXPECT_TRUE(result); | 71 EXPECT_TRUE(result); |
70 | 72 |
71 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create()); | 73 scoped_ptr<content::NavigationEntry> copy(content::NavigationEntry::Create()); |
72 PickleIterator iterator(pickle); | 74 PickleIterator iterator(pickle); |
73 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get()); | 75 result = internal::RestoreNavigationEntryFromPickle(&iterator, copy.get()); |
74 EXPECT_TRUE(result); | 76 EXPECT_TRUE(result); |
75 | 77 |
76 EXPECT_EQ(url, copy->GetURL()); | 78 EXPECT_EQ(url, copy->GetURL()); |
77 EXPECT_EQ(virtual_url, copy->GetVirtualURL()); | 79 EXPECT_EQ(virtual_url, copy->GetVirtualURL()); |
78 EXPECT_EQ(referrer.url, copy->GetReferrer().url); | 80 EXPECT_EQ(referrer.url, copy->GetReferrer().url); |
79 EXPECT_EQ(referrer.policy, copy->GetReferrer().policy); | 81 EXPECT_EQ(referrer.policy, copy->GetReferrer().policy); |
80 EXPECT_EQ(title, copy->GetTitle()); | 82 EXPECT_EQ(title, copy->GetTitle()); |
81 EXPECT_EQ(content_state, copy->GetContentState()); | 83 EXPECT_EQ(page_state, copy->GetPageState()); |
82 EXPECT_EQ(has_post_data, copy->GetHasPostData()); | 84 EXPECT_EQ(has_post_data, copy->GetHasPostData()); |
83 EXPECT_EQ(original_request_url, copy->GetOriginalRequestURL()); | 85 EXPECT_EQ(original_request_url, copy->GetOriginalRequestURL()); |
84 EXPECT_EQ(base_url_for_data_url, copy->GetBaseURLForDataURL()); | 86 EXPECT_EQ(base_url_for_data_url, copy->GetBaseURLForDataURL()); |
85 EXPECT_EQ(is_overriding_user_agent, copy->GetIsOverridingUserAgent()); | 87 EXPECT_EQ(is_overriding_user_agent, copy->GetIsOverridingUserAgent()); |
86 EXPECT_EQ(timestamp, copy->GetTimestamp()); | 88 EXPECT_EQ(timestamp, copy->GetTimestamp()); |
87 } | 89 } |
88 | 90 |
89 } // namespace android_webview | 91 } // namespace android_webview |
OLD | NEW |