File: ios_serialized_navigation_builder_unittest.mm

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (106 lines) | stat: -rw-r--r-- 4,636 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/sessions/ios/ios_serialized_navigation_builder.h"

#include "components/sessions/core/serialized_navigation_entry.h"
#include "components/sessions/core/serialized_navigation_entry_test_helper.h"
#include "ios/web/public/favicon_status.h"
#include "ios/web/public/navigation_item.h"
#include "ios/web/public/referrer.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace sessions {

namespace {
// Creates a NavigationItem from the test_data constants in
// serialized_navigation_entry_test_helper.h.
std::unique_ptr<web::NavigationItem> MakeNavigationItemForTest() {
  std::unique_ptr<web::NavigationItem> navigation_item(
      web::NavigationItem::Create());
  navigation_item->SetReferrer(web::Referrer(
      test_data::kReferrerURL,
      static_cast<web::ReferrerPolicy>(test_data::kReferrerPolicy)));
  navigation_item->SetURL(test_data::kVirtualURL);
  navigation_item->SetTitle(test_data::kTitle);
  navigation_item->SetTransitionType(test_data::kTransitionType);
  navigation_item->SetTimestamp(test_data::kTimestamp);
  navigation_item->GetFavicon().valid = true;
  navigation_item->GetFavicon().url = test_data::kFaviconURL;
  return navigation_item;
}

}  // namespace


// Create a SerializedNavigationEntry from a NavigationItem.  All its fields
// should match the NavigationItem's.
TEST(IOSSerializedNavigationBuilderTest, FromNavigationItem) {
  const std::unique_ptr<web::NavigationItem> navigation_item(
      MakeNavigationItemForTest());

  const SerializedNavigationEntry& navigation =
      IOSSerializedNavigationBuilder::FromNavigationItem(
          test_data::kIndex, *navigation_item);

  EXPECT_EQ(test_data::kIndex, navigation.index());

  EXPECT_EQ(navigation_item->GetUniqueID(), navigation.unique_id());
  EXPECT_EQ(test_data::kReferrerURL, navigation.referrer_url());
  EXPECT_EQ(test_data::kReferrerPolicy, navigation.referrer_policy());
  EXPECT_EQ(test_data::kVirtualURL, navigation.virtual_url());
  EXPECT_EQ(test_data::kTitle, navigation.title());
  EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
      navigation.transition_type(), test_data::kTransitionType));
  EXPECT_EQ(test_data::kTimestamp, navigation.timestamp());
  EXPECT_EQ(test_data::kFaviconURL, navigation.favicon_url());

  // The following fields should be left at their default values.
  SerializedNavigationEntry default_navigation;
  EXPECT_EQ(default_navigation.encoded_page_state(),
            navigation.encoded_page_state());
  EXPECT_EQ(default_navigation.has_post_data(), navigation.has_post_data());
  EXPECT_EQ(default_navigation.post_id(), navigation.post_id());
  EXPECT_EQ(default_navigation.original_request_url(),
            navigation.original_request_url());
  EXPECT_EQ(default_navigation.is_overriding_user_agent(),
            navigation.is_overriding_user_agent());
  EXPECT_EQ(default_navigation.http_status_code(),
            navigation.http_status_code());
  ASSERT_EQ(0U, navigation.redirect_chain().size());
}

// Create a NavigationItem, then create another one by converting to
// a SerializedNavigationEntry and back.  The new one should match the old one
// except for fields that aren't preserved, which should be set to
// expected values.
TEST(IOSSerializedNavigationBuilderTest, ToNavigationItem) {
  const std::unique_ptr<web::NavigationItem> old_navigation_item(
      MakeNavigationItemForTest());

  const SerializedNavigationEntry& navigation =
      IOSSerializedNavigationBuilder::FromNavigationItem(
          test_data::kIndex, *old_navigation_item);

  const std::unique_ptr<web::NavigationItem> new_navigation_item(
      IOSSerializedNavigationBuilder::ToNavigationItem(&navigation));

  EXPECT_EQ(old_navigation_item->GetURL(),
            new_navigation_item->GetURL());
  EXPECT_EQ(old_navigation_item->GetReferrer().url,
            new_navigation_item->GetReferrer().url);
  EXPECT_EQ(old_navigation_item->GetReferrer().policy,
            new_navigation_item->GetReferrer().policy);
  EXPECT_EQ(old_navigation_item->GetVirtualURL(),
            new_navigation_item->GetVirtualURL());
  EXPECT_EQ(old_navigation_item->GetTitle(),
            new_navigation_item->GetTitle());
  EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
                  new_navigation_item->GetTransitionType(),
                  ui::PAGE_TRANSITION_RELOAD));
  EXPECT_EQ(old_navigation_item->GetTimestamp(),
            new_navigation_item->GetTimestamp());
}

}  // namespace sessions