Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / tabs / pinned_tab_service_unittest.cc
blob298b9328feee9a0a631a3d6cef4d33e793e7f7db
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.
5 #include <string>
6 #include <vector>
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"
19 namespace {
21 BrowserContextKeyedService* BuildPinnedTabService(
22 content::BrowserContext* profile) {
23 return new PinnedTabService(static_cast<Profile*>(profile));
26 PinnedTabService* BuildForProfile(Profile* profile) {
27 return static_cast<PinnedTabService*>(
28 PinnedTabServiceFactory::GetInstance()->SetTestingFactoryAndUse(
29 profile, BuildPinnedTabService));
32 class PinnedTabServiceTest : public BrowserWithTestWindowTest {
33 public:
34 PinnedTabServiceTest() : pinned_tab_service_(NULL) {}
36 protected:
37 virtual TestingProfile* CreateProfile() OVERRIDE {
38 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile();
39 pinned_tab_service_ = BuildForProfile(profile);
40 return profile;
43 private:
44 PinnedTabService* pinned_tab_service_;
46 DISALLOW_COPY_AND_ASSIGN(PinnedTabServiceTest);
49 // Makes sure closing a popup triggers writing pinned tabs.
50 TEST_F(PinnedTabServiceTest, Popup) {
51 GURL url("http://www.google.com");
52 AddTab(browser(), url);
53 browser()->tab_strip_model()->SetTabPinned(0, true);
55 // Create a popup.
56 Browser::CreateParams params(Browser::TYPE_POPUP, profile(),
57 browser()->host_desktop_type());
58 scoped_ptr<Browser> popup(
59 chrome::CreateBrowserWithTestWindowForParams(&params));
61 // Close the browser. This should trigger saving the tabs. No need to destroy
62 // the browser (this happens automatically in the test destructor).
63 browser()->OnWindowClosing();
65 std::string result = PinnedTabTestUtils::TabsToString(
66 PinnedTabCodec::ReadPinnedTabs(profile()));
67 EXPECT_EQ("http://www.google.com/::pinned:", result);
69 // Close the popup. This shouldn't reset the saved state.
70 popup->tab_strip_model()->CloseAllTabs();
71 popup.reset(NULL);
73 // Check the state to make sure it hasn't changed.
74 result = PinnedTabTestUtils::TabsToString(
75 PinnedTabCodec::ReadPinnedTabs(profile()));
76 EXPECT_EQ("http://www.google.com/::pinned:", result);
79 } // namespace