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
3 // found in the LICENSE file.
5 #include "android_webview/native/state_serializer.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/pickle.h"
11 #include "base/time.h"
12 #include "base/utf_string_conversions.h"
13 #include "content/public/browser/content_browser_client.h"
14 #include "content/public/browser/navigation_entry.h"
15 #include "content/public/common/content_client.h"
16 #include "googleurl/src/gurl.h"
17 #include "testing/gtest/include/gtest/gtest.h"
21 namespace android_webview
{
23 TEST(AndroidWebViewStateSerializerTest
, TestHeaderSerialization
) {
25 bool result
= internal::WriteHeaderToPickle(&pickle
);
28 PickleIterator
iterator(pickle
);
29 result
= internal::RestoreHeaderFromPickle(&iterator
);
33 TEST(AndroidWebViewStateSerializerTest
, TestNavigationEntrySerialization
) {
34 // This is required for NavigationEntry::Create.
35 content::ContentClient content_client
;
36 content::SetContentClient(&content_client
);
37 content::ContentBrowserClient browser_client
;
38 content::SetBrowserClientForTesting(&browser_client
);
40 scoped_ptr
<content::NavigationEntry
> entry(
41 content::NavigationEntry::Create());
43 const GURL
url("http://url");
44 const GURL
virtual_url("http://virtual_url");
45 content::Referrer referrer
;
46 referrer
.url
= GURL("http://referrer_url");
47 referrer
.policy
= WebKit::WebReferrerPolicyOrigin
;
48 const string16
title(UTF8ToUTF16("title"));
49 const string
content_state("completely bogus state");
50 const bool has_post_data
= true;
51 const GURL
original_request_url("http://original_request_url");
52 const GURL
base_url_for_data_url("http://base_url");
53 const bool is_overriding_user_agent
= true;
54 const base::Time timestamp
= base::Time::FromInternalValue(12345);
57 entry
->SetVirtualURL(virtual_url
);
58 entry
->SetReferrer(referrer
);
59 entry
->SetTitle(title
);
60 entry
->SetContentState(content_state
);
61 entry
->SetHasPostData(has_post_data
);
62 entry
->SetOriginalRequestURL(original_request_url
);
63 entry
->SetBaseURLForDataURL(base_url_for_data_url
);
64 entry
->SetIsOverridingUserAgent(is_overriding_user_agent
);
65 entry
->SetTimestamp(timestamp
);
68 bool result
= internal::WriteNavigationEntryToPickle(*entry
, &pickle
);
71 scoped_ptr
<content::NavigationEntry
> copy(content::NavigationEntry::Create());
72 PickleIterator
iterator(pickle
);
73 result
= internal::RestoreNavigationEntryFromPickle(&iterator
, copy
.get());
76 EXPECT_EQ(url
, copy
->GetURL());
77 EXPECT_EQ(virtual_url
, copy
->GetVirtualURL());
78 EXPECT_EQ(referrer
.url
, copy
->GetReferrer().url
);
79 EXPECT_EQ(referrer
.policy
, copy
->GetReferrer().policy
);
80 EXPECT_EQ(title
, copy
->GetTitle());
81 EXPECT_EQ(content_state
, copy
->GetContentState());
82 EXPECT_EQ(has_post_data
, copy
->GetHasPostData());
83 EXPECT_EQ(original_request_url
, copy
->GetOriginalRequestURL());
84 EXPECT_EQ(base_url_for_data_url
, copy
->GetBaseURLForDataURL());
85 EXPECT_EQ(is_overriding_user_agent
, copy
->GetIsOverridingUserAgent());
86 EXPECT_EQ(timestamp
, copy
->GetTimestamp());
89 } // namespace android_webview