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.
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
11 #include "chrome/browser/ui/tabs/pinned_tab_service.h"
12 #include "chrome/browser/ui/tabs/pinned_tab_service_factory.h"
13 #include "chrome/browser/ui/tabs/pinned_tab_test_utils.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/test/base/browser_with_test_window_test.h"
16 #include "chrome/test/base/testing_profile.h"
17 #include "testing/gtest/include/gtest/gtest.h"
21 KeyedService
* BuildPinnedTabService(content::BrowserContext
* profile
) {
22 return new PinnedTabService(static_cast<Profile
*>(profile
));
25 PinnedTabService
* BuildForProfile(Profile
* profile
) {
26 return static_cast<PinnedTabService
*>(
27 PinnedTabServiceFactory::GetInstance()->SetTestingFactoryAndUse(
28 profile
, BuildPinnedTabService
));
31 class PinnedTabServiceTest
: public BrowserWithTestWindowTest
{
33 PinnedTabServiceTest() : pinned_tab_service_(NULL
) {}
36 virtual TestingProfile
* CreateProfile() OVERRIDE
{
37 TestingProfile
* profile
= BrowserWithTestWindowTest::CreateProfile();
38 pinned_tab_service_
= BuildForProfile(profile
);
43 PinnedTabService
* pinned_tab_service_
;
45 DISALLOW_COPY_AND_ASSIGN(PinnedTabServiceTest
);
48 // Makes sure closing a popup triggers writing pinned tabs.
49 TEST_F(PinnedTabServiceTest
, Popup
) {
50 GURL
url("http://www.google.com");
51 AddTab(browser(), url
);
52 browser()->tab_strip_model()->SetTabPinned(0, true);
55 Browser::CreateParams
params(Browser::TYPE_POPUP
, profile(),
56 browser()->host_desktop_type());
57 scoped_ptr
<Browser
> popup(
58 chrome::CreateBrowserWithTestWindowForParams(¶ms
));
60 // Close the browser. This should trigger saving the tabs. No need to destroy
61 // the browser (this happens automatically in the test destructor).
62 browser()->OnWindowClosing();
64 std::string result
= PinnedTabTestUtils::TabsToString(
65 PinnedTabCodec::ReadPinnedTabs(profile()));
66 EXPECT_EQ("http://www.google.com/::pinned:", result
);
68 // Close the popup. This shouldn't reset the saved state.
69 popup
->tab_strip_model()->CloseAllTabs();
72 // Check the state to make sure it hasn't changed.
73 result
= PinnedTabTestUtils::TabsToString(
74 PinnedTabCodec::ReadPinnedTabs(profile()));
75 EXPECT_EQ("http://www.google.com/::pinned:", result
);