Fix layout of the Connection Tab of the Origin Info Bubble.
[chromium-blink-merge.git] / components / sessions / session_types_unittest.cc
blob5c1a44cc1eccf1e1dbc9fb59bba2dc3ac8fcabb0
1 // Copyright 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 "components/sessions/session_types.h"
7 #include <cstddef>
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h"
14 #include "components/sessions/serialized_navigation_entry_test_helper.h"
15 #include "sync/protocol/session_specifics.pb.h"
16 #include "sync/util/time.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/page_transition_types.h"
19 #include "url/gurl.h"
21 namespace {
23 // Create a typical SessionTab protocol buffer and set an existing
24 // SessionTab from it. The data from the protocol buffer should
25 // clobber the existing data.
26 TEST(SessionTab, FromSyncData) {
27 sync_pb::SessionTab sync_data;
28 sync_data.set_tab_id(5);
29 sync_data.set_window_id(10);
30 sync_data.set_tab_visual_index(13);
31 sync_data.set_current_navigation_index(3);
32 sync_data.set_pinned(true);
33 sync_data.set_extension_app_id("app_id");
34 for (int i = 0; i < 5; ++i) {
35 sync_pb::TabNavigation* navigation = sync_data.add_navigation();
36 navigation->set_virtual_url("http://foo/" + base::IntToString(i));
37 navigation->set_referrer("referrer");
38 navigation->set_title("title");
39 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED);
41 sync_data.add_variation_id(3312238);
42 sync_data.add_variation_id(3312242);
44 sessions::SessionTab tab;
45 tab.window_id.set_id(100);
46 tab.tab_id.set_id(100);
47 tab.tab_visual_index = 100;
48 tab.current_navigation_index = 1000;
49 tab.pinned = false;
50 tab.extension_app_id = "fake";
51 tab.user_agent_override = "fake";
52 tab.timestamp = base::Time::FromInternalValue(100);
53 tab.navigations.resize(100);
54 tab.session_storage_persistent_id = "fake";
56 tab.SetFromSyncData(sync_data, base::Time::FromInternalValue(5u));
57 EXPECT_EQ(10, tab.window_id.id());
58 EXPECT_EQ(5, tab.tab_id.id());
59 EXPECT_EQ(13, tab.tab_visual_index);
60 EXPECT_EQ(3, tab.current_navigation_index);
61 EXPECT_TRUE(tab.pinned);
62 EXPECT_EQ("app_id", tab.extension_app_id);
63 EXPECT_TRUE(tab.user_agent_override.empty());
64 EXPECT_EQ(5u, tab.timestamp.ToInternalValue());
65 ASSERT_EQ(5u, tab.navigations.size());
66 for (int i = 0; i < 5; ++i) {
67 EXPECT_EQ(i, tab.navigations[i].index());
68 EXPECT_EQ(GURL("referrer"), tab.navigations[i].referrer_url());
69 EXPECT_EQ(base::ASCIIToUTF16("title"),tab.navigations[i].title());
70 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED,
71 tab.navigations[i].transition_type());
72 EXPECT_EQ(GURL("http://foo/" + base::IntToString(i)),
73 tab.navigations[i].virtual_url());
75 ASSERT_EQ(2u, tab.variation_ids.size());
76 EXPECT_EQ(3312238, tab.variation_ids[0]);
77 EXPECT_EQ(3312242, tab.variation_ids[1]);
78 EXPECT_TRUE(tab.session_storage_persistent_id.empty());
81 TEST(SessionTab, ToSyncData) {
82 sessions::SessionTab tab;
83 tab.window_id.set_id(10);
84 tab.tab_id.set_id(5);
85 tab.tab_visual_index = 13;
86 tab.current_navigation_index = 3;
87 tab.pinned = true;
88 tab.extension_app_id = "app_id";
89 tab.user_agent_override = "fake";
90 tab.timestamp = base::Time::FromInternalValue(100);
91 for (int i = 0; i < 5; ++i) {
92 tab.navigations.push_back(
93 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
94 "http://foo/" + base::IntToString(i), "title"));
96 tab.session_storage_persistent_id = "fake";
97 tab.variation_ids.push_back(3312238);
98 tab.variation_ids.push_back(3312242);
100 const sync_pb::SessionTab& sync_data = tab.ToSyncData();
101 EXPECT_EQ(5, sync_data.tab_id());
102 EXPECT_EQ(10, sync_data.window_id());
103 EXPECT_EQ(13, sync_data.tab_visual_index());
104 EXPECT_EQ(3, sync_data.current_navigation_index());
105 EXPECT_TRUE(sync_data.pinned());
106 EXPECT_EQ("app_id", sync_data.extension_app_id());
107 ASSERT_EQ(5, sync_data.navigation_size());
108 for (int i = 0; i < 5; ++i) {
109 EXPECT_EQ(tab.navigations[i].virtual_url().spec(),
110 sync_data.navigation(i).virtual_url());
111 EXPECT_EQ(base::UTF16ToUTF8(tab.navigations[i].title()),
112 sync_data.navigation(i).title());
114 EXPECT_FALSE(sync_data.has_favicon());
115 EXPECT_FALSE(sync_data.has_favicon_type());
116 EXPECT_FALSE(sync_data.has_favicon_source());
118 ASSERT_EQ(2, sync_data.variation_id_size());
119 EXPECT_EQ(3312238u, sync_data.variation_id(0));
120 EXPECT_EQ(3312242u, sync_data.variation_id(1));
123 } // namespace