Make the offline login page switch back to the online one after going online.
[chromium-blink-merge.git] / components / sessions / serialized_navigation_entry_test_helper.cc
blob708346bed2d28876f629adfb4547e77e45ece5b3
1 // Copyright (c) 2013 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 "components/sessions/serialized_navigation_entry_test_helper.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/time/time.h"
9 #include "components/sessions/serialized_navigation_entry.h"
10 #include "sync/util/time.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "url/gurl.h"
14 namespace sessions {
16 namespace test_data {
18 const int kIndex = 3;
19 const int kUniqueID = 50;
20 const GURL kReferrerURL = GURL("http://www.referrer.com");
21 const int kReferrerPolicy = 0;
22 const GURL kVirtualURL= GURL("http://www.virtual-url.com");
23 const base::string16 kTitle = base::ASCIIToUTF16("title");
24 const std::string kEncodedPageState = "page state";
25 const ui::PageTransition kTransitionType =
26 ui::PageTransitionFromInt(
27 ui::PAGE_TRANSITION_AUTO_SUBFRAME |
28 ui::PAGE_TRANSITION_HOME_PAGE |
29 ui::PAGE_TRANSITION_CLIENT_REDIRECT);
30 const bool kHasPostData = true;
31 const int64 kPostID = 100;
32 const GURL kOriginalRequestURL = GURL("http://www.original-request.com");
33 const bool kIsOverridingUserAgent = true;
34 const base::Time kTimestamp = syncer::ProtoTimeToTime(100);
35 const base::string16 kSearchTerms = base::ASCIIToUTF16("my search terms");
36 const GURL kFaviconURL = GURL("http://virtual-url.com/favicon.ico");
37 const int kHttpStatusCode = 404;
38 const GURL kRedirectURL0 = GURL("http://go/redirect0");
39 const GURL kRedirectURL1 = GURL("http://go/redirect1");
40 const GURL kOtherURL = GURL("http://other.com");
41 const int kPageID = 10;
43 } // namespace test_data
45 // static
46 void SerializedNavigationEntryTestHelper::ExpectNavigationEquals(
47 const SerializedNavigationEntry& expected,
48 const SerializedNavigationEntry& actual) {
49 EXPECT_EQ(expected.referrer_url_, actual.referrer_url_);
50 EXPECT_EQ(expected.referrer_policy_, actual.referrer_policy_);
51 EXPECT_EQ(expected.virtual_url_, actual.virtual_url_);
52 EXPECT_EQ(expected.title_, actual.title_);
53 EXPECT_EQ(expected.encoded_page_state_, actual.encoded_page_state_);
54 EXPECT_EQ(expected.transition_type_, actual.transition_type_);
55 EXPECT_EQ(expected.has_post_data_, actual.has_post_data_);
56 EXPECT_EQ(expected.original_request_url_, actual.original_request_url_);
57 EXPECT_EQ(expected.is_overriding_user_agent_,
58 actual.is_overriding_user_agent_);
61 // static
62 SerializedNavigationEntry SerializedNavigationEntryTestHelper::CreateNavigation(
63 const std::string& virtual_url,
64 const std::string& title) {
65 SerializedNavigationEntry navigation;
66 navigation.index_ = 0;
67 navigation.referrer_url_ = GURL("http://www.referrer.com");
68 navigation.virtual_url_ = GURL(virtual_url);
69 navigation.title_ = base::UTF8ToUTF16(title);
70 navigation.encoded_page_state_ = "fake state";
71 navigation.timestamp_ = base::Time::Now();
72 navigation.http_status_code_ = 200;
73 return navigation;
76 // static
77 SerializedNavigationEntry
78 SerializedNavigationEntryTestHelper::CreateNavigationForTest() {
79 SerializedNavigationEntry navigation;
80 navigation.index_ = test_data::kIndex;
81 navigation.unique_id_ = test_data::kUniqueID;
82 navigation.referrer_url_ = test_data::kReferrerURL;
83 navigation.referrer_policy_ = test_data::kReferrerPolicy;
84 navigation.virtual_url_ = test_data::kVirtualURL;
85 navigation.title_ = test_data::kTitle;
86 navigation.encoded_page_state_ = test_data::kEncodedPageState;
87 navigation.transition_type_ = test_data::kTransitionType;
88 navigation.has_post_data_ = test_data::kHasPostData;
89 navigation.post_id_ = test_data::kPostID;
90 navigation.original_request_url_ = test_data::kOriginalRequestURL;
91 navigation.is_overriding_user_agent_ = test_data::kIsOverridingUserAgent;
92 navigation.timestamp_ = test_data::kTimestamp;
93 navigation.search_terms_ = test_data::kSearchTerms;
94 navigation.favicon_url_ = test_data::kFaviconURL;
95 navigation.http_status_code_ = test_data::kHttpStatusCode;
97 navigation.redirect_chain_.push_back(test_data::kRedirectURL0);
98 navigation.redirect_chain_.push_back(test_data::kRedirectURL1);
99 navigation.redirect_chain_.push_back(test_data::kVirtualURL);
100 return navigation;
103 // static
104 void SerializedNavigationEntryTestHelper::SetReferrerPolicy(
105 int policy,
106 SerializedNavigationEntry* navigation) {
107 navigation->referrer_policy_ = policy;
110 // static
111 void SerializedNavigationEntryTestHelper::SetVirtualURL(
112 const GURL& virtual_url,
113 SerializedNavigationEntry* navigation) {
114 navigation->virtual_url_ = virtual_url;
117 // static
118 void SerializedNavigationEntryTestHelper::SetEncodedPageState(
119 const std::string& encoded_page_state,
120 SerializedNavigationEntry* navigation) {
121 navigation->encoded_page_state_ = encoded_page_state;
124 // static
125 void SerializedNavigationEntryTestHelper::SetTransitionType(
126 ui::PageTransition transition_type,
127 SerializedNavigationEntry* navigation) {
128 navigation->transition_type_ = transition_type;
131 // static
132 void SerializedNavigationEntryTestHelper::SetHasPostData(
133 bool has_post_data,
134 SerializedNavigationEntry* navigation) {
135 navigation->has_post_data_ = has_post_data;
138 // static
139 void SerializedNavigationEntryTestHelper::SetOriginalRequestURL(
140 const GURL& original_request_url,
141 SerializedNavigationEntry* navigation) {
142 navigation->original_request_url_ = original_request_url;
145 // static
146 void SerializedNavigationEntryTestHelper::SetIsOverridingUserAgent(
147 bool is_overriding_user_agent,
148 SerializedNavigationEntry* navigation) {
149 navigation->is_overriding_user_agent_ = is_overriding_user_agent;
152 // static
153 void SerializedNavigationEntryTestHelper::SetTimestamp(
154 base::Time timestamp,
155 SerializedNavigationEntry* navigation) {
156 navigation->timestamp_ = timestamp;
159 } // namespace sessions