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_service.h" 10 #include "chrome/browser/tabs/pinned_tab_test_utils.h" 11 #include "chrome/browser/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/browser.h" 13 #include "chrome/test/browser_with_test_window_test.h" 14 #include "chrome/test/testing_profile.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 17 class PinnedTabServiceTest : public BrowserWithTestWindowTest { 18 public: 19 PinnedTabServiceTest() {} 20 21 protected: 22 virtual TestingProfile* CreateProfile() OVERRIDE { 23 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); 24 pinned_tab_service_.reset(new PinnedTabService(profile)); 25 return profile; 26 } 27 28 private: 29 scoped_ptr<PinnedTabService> pinned_tab_service_; 30 31 DISALLOW_COPY_AND_ASSIGN(PinnedTabServiceTest); 32 }; 33 34 // Makes sure closing a popup triggers writing pinned tabs. 35 TEST_F(PinnedTabServiceTest, Popup) { 36 GURL url("http://www.google.com"); 37 AddTab(browser(), url); 38 browser()->tabstrip_model()->SetTabPinned(0, true); 39 40 // Create a popup. 41 scoped_ptr<Browser> popup(new Browser(Browser::TYPE_POPUP, profile())); 42 scoped_ptr<TestBrowserWindow> popup_window( 43 new TestBrowserWindow(popup.get())); 44 popup->set_window(popup_window.get()); 45 46 // Close the browser. This should trigger saving the tabs. 47 browser()->OnWindowClosing(); 48 DestroyBrowser(); 49 std::string result = PinnedTabTestUtils::TabsToString( 50 PinnedTabCodec::ReadPinnedTabs(profile())); 51 EXPECT_EQ("http://www.google.com/::pinned:", result); 52 53 // Close the popup. This shouldn't reset the saved state. 54 popup->CloseAllTabs(); 55 popup.reset(NULL); 56 popup_window.reset(NULL); 57 58 // Check the state to make sure it hasn't changed. 59 result = PinnedTabTestUtils::TabsToString( 60 PinnedTabCodec::ReadPinnedTabs(profile())); 61 EXPECT_EQ("http://www.google.com/::pinned:", result); 62 } 63 64