Try to work around that clang/win bug in another file.
[chromium-blink-merge.git] / components / sessions / session_types_unittest.cc
blobaeece6f0c2ad662d1ac1bed17d89a1ffa51c5cfa
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 "chrome/browser/search/search.h"
15 #include "components/sessions/serialized_navigation_entry_test_helper.h"
16 #include "sync/protocol/session_specifics.pb.h"
17 #include "sync/util/time.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "ui/base/page_transition_types.h"
20 #include "url/gurl.h"
22 namespace {
24 // Create a typical SessionTab protocol buffer and set an existing
25 // SessionTab from it. The data from the protocol buffer should
26 // clobber the existing data.
27 TEST(SessionTab, FromSyncData) {
28 sync_pb::SessionTab sync_data;
29 sync_data.set_tab_id(5);
30 sync_data.set_window_id(10);
31 sync_data.set_tab_visual_index(13);
32 sync_data.set_current_navigation_index(3);
33 sync_data.set_pinned(true);
34 sync_data.set_extension_app_id("app_id");
35 for (int i = 0; i < 5; ++i) {
36 sync_pb::TabNavigation* navigation = sync_data.add_navigation();
37 navigation->set_virtual_url("http://foo/" + base::IntToString(i));
38 navigation->set_referrer("referrer");
39 navigation->set_title("title");
40 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED);
42 sync_data.add_variation_id(3312238);
43 sync_data.add_variation_id(3312242);
45 sessions::SessionTab tab;
46 tab.window_id.set_id(100);
47 tab.tab_id.set_id(100);
48 tab.tab_visual_index = 100;
49 tab.current_navigation_index = 1000;
50 tab.pinned = false;
51 tab.extension_app_id = "fake";
52 tab.user_agent_override = "fake";
53 tab.timestamp = base::Time::FromInternalValue(100);
54 tab.navigations.resize(100);
55 tab.session_storage_persistent_id = "fake";
57 tab.SetFromSyncData(sync_data, base::Time::FromInternalValue(5u));
58 EXPECT_EQ(10, tab.window_id.id());
59 EXPECT_EQ(5, tab.tab_id.id());
60 EXPECT_EQ(13, tab.tab_visual_index);
61 EXPECT_EQ(3, tab.current_navigation_index);
62 EXPECT_TRUE(tab.pinned);
63 EXPECT_EQ("app_id", tab.extension_app_id);
64 EXPECT_TRUE(tab.user_agent_override.empty());
65 EXPECT_EQ(5u, tab.timestamp.ToInternalValue());
66 ASSERT_EQ(5u, tab.navigations.size());
67 for (int i = 0; i < 5; ++i) {
68 EXPECT_EQ(i, tab.navigations[i].index());
69 EXPECT_EQ(GURL("referrer"), tab.navigations[i].referrer_url());
70 EXPECT_EQ(base::ASCIIToUTF16("title"),tab.navigations[i].title());
71 EXPECT_EQ(ui::PAGE_TRANSITION_TYPED,
72 tab.navigations[i].transition_type());
73 EXPECT_EQ(GURL("http://foo/" + base::IntToString(i)),
74 tab.navigations[i].virtual_url());
76 ASSERT_EQ(2u, tab.variation_ids.size());
77 EXPECT_EQ(3312238, tab.variation_ids[0]);
78 EXPECT_EQ(3312242, tab.variation_ids[1]);
79 EXPECT_TRUE(tab.session_storage_persistent_id.empty());
82 TEST(SessionTab, ToSyncData) {
83 sessions::SessionTab tab;
84 tab.window_id.set_id(10);
85 tab.tab_id.set_id(5);
86 tab.tab_visual_index = 13;
87 tab.current_navigation_index = 3;
88 tab.pinned = true;
89 tab.extension_app_id = "app_id";
90 tab.user_agent_override = "fake";
91 tab.timestamp = base::Time::FromInternalValue(100);
92 for (int i = 0; i < 5; ++i) {
93 tab.navigations.push_back(
94 sessions::SerializedNavigationEntryTestHelper::CreateNavigation(
95 "http://foo/" + base::IntToString(i), "title"));
97 tab.session_storage_persistent_id = "fake";
98 tab.variation_ids.push_back(3312238);
99 tab.variation_ids.push_back(3312242);
101 const sync_pb::SessionTab& sync_data = tab.ToSyncData();
102 EXPECT_EQ(5, sync_data.tab_id());
103 EXPECT_EQ(10, sync_data.window_id());
104 EXPECT_EQ(13, sync_data.tab_visual_index());
105 EXPECT_EQ(3, sync_data.current_navigation_index());
106 EXPECT_TRUE(sync_data.pinned());
107 EXPECT_EQ("app_id", sync_data.extension_app_id());
108 ASSERT_EQ(5, sync_data.navigation_size());
109 for (int i = 0; i < 5; ++i) {
110 EXPECT_EQ(tab.navigations[i].virtual_url().spec(),
111 sync_data.navigation(i).virtual_url());
112 EXPECT_EQ(base::UTF16ToUTF8(tab.navigations[i].title()),
113 sync_data.navigation(i).title());
115 EXPECT_FALSE(sync_data.has_favicon());
116 EXPECT_FALSE(sync_data.has_favicon_type());
117 EXPECT_FALSE(sync_data.has_favicon_source());
119 ASSERT_EQ(2, sync_data.variation_id_size());
120 EXPECT_EQ(3312238u, sync_data.variation_id(0));
121 EXPECT_EQ(3312242u, sync_data.variation_id(1));
124 } // namespace