Home | History | Annotate | Download | only in tabs
      1 // Copyright (c) 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.
      4 
      5 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
      6 
      7 #include <string>
      8 #include <vector>
      9 
     10 #include "chrome/browser/ui/browser.h"
     11 #include "chrome/browser/ui/startup/startup_tab.h"
     12 #include "chrome/browser/ui/tabs/pinned_tab_test_utils.h"
     13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
     14 #include "chrome/test/base/browser_with_test_window_test.h"
     15 #include "chrome/test/base/testing_profile.h"
     16 #include "testing/gtest/include/gtest/gtest.h"
     17 
     18 typedef BrowserWithTestWindowTest PinnedTabCodecTest;
     19 
     20 // Make sure nothing is restored when the browser has no pinned tabs.
     21 TEST_F(PinnedTabCodecTest, NoPinnedTabs) {
     22   GURL url1("http://www.google.com");
     23   AddTab(browser(), url1);
     24 
     25   PinnedTabCodec::WritePinnedTabs(profile());
     26 
     27   std::string result = PinnedTabTestUtils::TabsToString(
     28       PinnedTabCodec::ReadPinnedTabs(profile()));
     29   EXPECT_EQ("", result);
     30 }
     31 
     32 // Creates a browser with one pinned tab and one normal tab, does restore and
     33 // makes sure we get back another pinned tab.
     34 TEST_F(PinnedTabCodecTest, PinnedAndNonPinned) {
     35   GURL url1("http://www.google.com");
     36   GURL url2("http://www.google.com/2");
     37   AddTab(browser(), url2);
     38 
     39   // AddTab inserts at index 0, so order after this is url1, url2.
     40   AddTab(browser(), url1);
     41 
     42   browser()->tab_strip_model()->SetTabPinned(0, true);
     43 
     44   PinnedTabCodec::WritePinnedTabs(profile());
     45 
     46   StartupTabs pinned_tabs = PinnedTabCodec::ReadPinnedTabs(profile());
     47   std::string result = PinnedTabTestUtils::TabsToString(pinned_tabs);
     48   EXPECT_EQ("http://www.google.com/::pinned:", result);
     49 
     50   // Update pinned tabs and restore back the old value directly.
     51   browser()->tab_strip_model()->SetTabPinned(1, true);
     52 
     53   PinnedTabCodec::WritePinnedTabs(profile());
     54   result = PinnedTabTestUtils::TabsToString(
     55       PinnedTabCodec::ReadPinnedTabs(profile()));
     56   EXPECT_EQ("http://www.google.com/::pinned: http://www.google.com/2::pinned:",
     57             result);
     58 
     59   PinnedTabCodec::WritePinnedTabs(profile(), pinned_tabs);
     60   result = PinnedTabTestUtils::TabsToString(
     61       PinnedTabCodec::ReadPinnedTabs(profile()));
     62   EXPECT_EQ("http://www.google.com/::pinned:", result);
     63 }
     64