OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 #include "chrome/browser/ui/tabs/pinned_tab_service.h" |
| 6 |
| 7 #include <memory> |
5 #include <string> | 8 #include <string> |
6 #include <vector> | 9 #include <vector> |
7 | 10 |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/ptr_util.h" |
10 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_tabstrip.h" | 14 #include "chrome/browser/ui/browser_tabstrip.h" |
12 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" | 15 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" |
13 #include "chrome/browser/ui/tabs/pinned_tab_service.h" | |
14 #include "chrome/browser/ui/tabs/pinned_tab_service_factory.h" | 16 #include "chrome/browser/ui/tabs/pinned_tab_service_factory.h" |
15 #include "chrome/browser/ui/tabs/pinned_tab_test_utils.h" | 17 #include "chrome/browser/ui/tabs/pinned_tab_test_utils.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/test/base/browser_with_test_window_test.h" | 19 #include "chrome/test/base/browser_with_test_window_test.h" |
18 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 scoped_ptr<KeyedService> BuildPinnedTabService( | 25 std::unique_ptr<KeyedService> BuildPinnedTabService( |
24 content::BrowserContext* profile) { | 26 content::BrowserContext* profile) { |
25 return make_scoped_ptr(new PinnedTabService(static_cast<Profile*>(profile))); | 27 return base::WrapUnique(new PinnedTabService(static_cast<Profile*>(profile))); |
26 } | 28 } |
27 | 29 |
28 PinnedTabService* BuildForProfile(Profile* profile) { | 30 PinnedTabService* BuildForProfile(Profile* profile) { |
29 return static_cast<PinnedTabService*>( | 31 return static_cast<PinnedTabService*>( |
30 PinnedTabServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 32 PinnedTabServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
31 profile, BuildPinnedTabService)); | 33 profile, BuildPinnedTabService)); |
32 } | 34 } |
33 | 35 |
34 class PinnedTabServiceTest : public BrowserWithTestWindowTest { | 36 class PinnedTabServiceTest : public BrowserWithTestWindowTest { |
35 public: | 37 public: |
(...skipping 13 matching lines...) Expand all Loading... |
49 }; | 51 }; |
50 | 52 |
51 // Makes sure closing a popup triggers writing pinned tabs. | 53 // Makes sure closing a popup triggers writing pinned tabs. |
52 TEST_F(PinnedTabServiceTest, Popup) { | 54 TEST_F(PinnedTabServiceTest, Popup) { |
53 GURL url("http://www.google.com"); | 55 GURL url("http://www.google.com"); |
54 AddTab(browser(), url); | 56 AddTab(browser(), url); |
55 browser()->tab_strip_model()->SetTabPinned(0, true); | 57 browser()->tab_strip_model()->SetTabPinned(0, true); |
56 | 58 |
57 // Create a popup. | 59 // Create a popup. |
58 Browser::CreateParams params(Browser::TYPE_POPUP, profile()); | 60 Browser::CreateParams params(Browser::TYPE_POPUP, profile()); |
59 scoped_ptr<Browser> popup( | 61 std::unique_ptr<Browser> popup( |
60 chrome::CreateBrowserWithTestWindowForParams(¶ms)); | 62 chrome::CreateBrowserWithTestWindowForParams(¶ms)); |
61 | 63 |
62 // Close the browser. This should trigger saving the tabs. No need to destroy | 64 // Close the browser. This should trigger saving the tabs. No need to destroy |
63 // the browser (this happens automatically in the test destructor). | 65 // the browser (this happens automatically in the test destructor). |
64 browser()->OnWindowClosing(); | 66 browser()->OnWindowClosing(); |
65 | 67 |
66 std::string result = PinnedTabTestUtils::TabsToString( | 68 std::string result = PinnedTabTestUtils::TabsToString( |
67 PinnedTabCodec::ReadPinnedTabs(profile())); | 69 PinnedTabCodec::ReadPinnedTabs(profile())); |
68 EXPECT_EQ("http://www.google.com/:pinned", result); | 70 EXPECT_EQ("http://www.google.com/:pinned", result); |
69 | 71 |
70 // Close the popup. This shouldn't reset the saved state. | 72 // Close the popup. This shouldn't reset the saved state. |
71 popup->tab_strip_model()->CloseAllTabs(); | 73 popup->tab_strip_model()->CloseAllTabs(); |
72 popup.reset(NULL); | 74 popup.reset(NULL); |
73 | 75 |
74 // Check the state to make sure it hasn't changed. | 76 // Check the state to make sure it hasn't changed. |
75 result = PinnedTabTestUtils::TabsToString( | 77 result = PinnedTabTestUtils::TabsToString( |
76 PinnedTabCodec::ReadPinnedTabs(profile())); | 78 PinnedTabCodec::ReadPinnedTabs(profile())); |
77 EXPECT_EQ("http://www.google.com/:pinned", result); | 79 EXPECT_EQ("http://www.google.com/:pinned", result); |
78 } | 80 } |
79 | 81 |
80 } // namespace | 82 } // namespace |
OLD | NEW |