Home | History | Annotate | Download | only in sessions
      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.
      4 
      5 #include "components/sessions/serialized_navigation_entry_test_helper.h"
      6 
      7 #include "base/strings/utf_string_conversions.h"
      8 #include "base/time/time.h"
      9 #include "components/sessions/serialized_navigation_entry.h"
     10 #include "testing/gtest/include/gtest/gtest.h"
     11 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
     12 #include "url/gurl.h"
     13 
     14 namespace sessions {
     15 
     16 // static
     17 void SerializedNavigationEntryTestHelper::ExpectNavigationEquals(
     18     const SerializedNavigationEntry& expected,
     19     const SerializedNavigationEntry& actual) {
     20   EXPECT_EQ(expected.referrer_.url, actual.referrer_.url);
     21   EXPECT_EQ(expected.referrer_.policy, actual.referrer_.policy);
     22   EXPECT_EQ(expected.virtual_url_, actual.virtual_url_);
     23   EXPECT_EQ(expected.title_, actual.title_);
     24   EXPECT_EQ(expected.page_state_, actual.page_state_);
     25   EXPECT_EQ(expected.transition_type_, actual.transition_type_);
     26   EXPECT_EQ(expected.has_post_data_, actual.has_post_data_);
     27   EXPECT_EQ(expected.original_request_url_, actual.original_request_url_);
     28   EXPECT_EQ(expected.is_overriding_user_agent_,
     29             actual.is_overriding_user_agent_);
     30 }
     31 
     32 // static
     33 SerializedNavigationEntry SerializedNavigationEntryTestHelper::CreateNavigation(
     34     const std::string& virtual_url,
     35     const std::string& title) {
     36   SerializedNavigationEntry navigation;
     37   navigation.index_ = 0;
     38   navigation.referrer_ =
     39       content::Referrer(GURL("http://www.referrer.com"),
     40                         blink::WebReferrerPolicyDefault);
     41   navigation.virtual_url_ = GURL(virtual_url);
     42   navigation.title_ = UTF8ToUTF16(title);
     43   navigation.page_state_ =
     44       content::PageState::CreateFromEncodedData("fake_state");
     45   navigation.timestamp_ = base::Time::Now();
     46   navigation.http_status_code_ = 200;
     47   return navigation;
     48 }
     49 
     50 // static
     51 void SerializedNavigationEntryTestHelper::SetPageState(
     52     const content::PageState& page_state,
     53     SerializedNavigationEntry* navigation) {
     54   navigation->page_state_ = page_state;
     55 }
     56 
     57 // static
     58 void SerializedNavigationEntryTestHelper::SetHasPostData(
     59     bool has_post_data,
     60     SerializedNavigationEntry* navigation) {
     61   navigation->has_post_data_ = has_post_data;
     62 }
     63 
     64 // static
     65 void SerializedNavigationEntryTestHelper::SetOriginalRequestURL(
     66     const GURL& original_request_url,
     67     SerializedNavigationEntry* navigation) {
     68   navigation->original_request_url_ = original_request_url;
     69 }
     70 
     71 // static
     72 void SerializedNavigationEntryTestHelper::SetIsOverridingUserAgent(
     73     bool is_overriding_user_agent,
     74     SerializedNavigationEntry* navigation) {
     75   navigation->is_overriding_user_agent_ = is_overriding_user_agent;
     76 }
     77 
     78 // static
     79 void SerializedNavigationEntryTestHelper::SetTimestamp(
     80     base::Time timestamp,
     81     SerializedNavigationEntry* navigation) {
     82   navigation->timestamp_ = timestamp;
     83 }
     84 
     85 }  // namespace sessions
     86