1// Copyright (c) 2011 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 <string>
6#include <vector>
7
8#include "chrome/browser/tabs/pinned_tab_codec.h"
9#include "chrome/browser/tabs/pinned_tab_test_utils.h"
10#include "chrome/browser/tabs/tab_strip_model.h"
11#include "chrome/browser/ui/browser.h"
12#include "chrome/test/browser_with_test_window_test.h"
13#include "chrome/test/testing_profile.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
16typedef BrowserWithTestWindowTest PinnedTabCodecTest;
17
18// Make sure nothing is restored when the browser has no pinned tabs.
19TEST_F(PinnedTabCodecTest, NoPinnedTabs) {
20  GURL url1("http://www.google.com");
21  AddTab(browser(), url1);
22
23  PinnedTabCodec::WritePinnedTabs(profile());
24
25  std::string result = PinnedTabTestUtils::TabsToString(
26      PinnedTabCodec::ReadPinnedTabs(profile()));
27  EXPECT_EQ("", result);
28}
29
30// Creates a browser with one pinned tab and one normal tab, does restore and
31// makes sure we get back another pinned tab.
32TEST_F(PinnedTabCodecTest, PinnedAndNonPinned) {
33  GURL url1("http://www.google.com");
34  GURL url2("http://www.google.com/2");
35  AddTab(browser(), url2);
36
37  // AddTab inserts at index 0, so order after this is url1, url2.
38  AddTab(browser(), url1);
39
40  browser()->tabstrip_model()->SetTabPinned(0, true);
41
42  PinnedTabCodec::WritePinnedTabs(profile());
43
44  std::string result = PinnedTabTestUtils::TabsToString(
45      PinnedTabCodec::ReadPinnedTabs(profile()));
46  EXPECT_EQ("http://www.google.com/::pinned:", result);
47}
48