OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 5 |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/background_contents_service.h" | 10 #include "chrome/browser/background_contents_service.h" |
| 11 #include "chrome/browser/browser_list.h" |
11 #include "chrome/browser/pref_service.h" | 12 #include "chrome/browser/pref_service.h" |
12 #include "chrome/browser/tab_contents/background_contents.h" | 13 #include "chrome/browser/tab_contents/background_contents.h" |
13 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
14 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/testing_browser_process.h" | 16 #include "chrome/test/testing_browser_process.h" |
16 #include "chrome/test/testing_profile.h" | 17 #include "chrome/test/testing_profile.h" |
17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
20 | 21 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 106 |
106 TEST_F(BackgroundContentsServiceTest, Create) { | 107 TEST_F(BackgroundContentsServiceTest, Create) { |
107 // Check for creation and leaks. | 108 // Check for creation and leaks. |
108 TestingProfile profile; | 109 TestingProfile profile; |
109 BackgroundContentsService service(&profile, command_line_.get()); | 110 BackgroundContentsService service(&profile, command_line_.get()); |
110 } | 111 } |
111 | 112 |
112 TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) { | 113 TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) { |
113 TestingProfile profile; | 114 TestingProfile profile; |
114 BackgroundContentsService service(&profile, command_line_.get()); | 115 BackgroundContentsService service(&profile, command_line_.get()); |
115 // TODO(atwilson): Enable the refcount part of the test once we fix the | |
116 // APP_TERMINATING notification to be sent at the proper time. | |
117 // (http://crbug.com/45275). | |
118 // | |
119 // TestingBrowserProcess* process = | |
120 // static_cast<TestingBrowserProcess*>(g_browser_process); | |
121 // unsigned int starting_ref_count = process->module_ref_count(); | |
122 MockBackgroundContents* contents = new MockBackgroundContents(&profile); | 116 MockBackgroundContents* contents = new MockBackgroundContents(&profile); |
123 EXPECT_FALSE(service.IsTracked(contents)); | 117 EXPECT_FALSE(service.IsTracked(contents)); |
| 118 EXPECT_FALSE(BrowserList::WillKeepAlive()); |
124 contents->SendOpenedNotification(); | 119 contents->SendOpenedNotification(); |
125 // EXPECT_EQ(starting_ref_count+1, process->module_ref_count()); | 120 EXPECT_TRUE(BrowserList::WillKeepAlive()); |
126 EXPECT_TRUE(service.IsTracked(contents)); | 121 EXPECT_TRUE(service.IsTracked(contents)); |
127 delete contents; | 122 delete contents; |
128 // EXPECT_EQ(starting_ref_count, process->module_ref_count()); | 123 EXPECT_FALSE(BrowserList::WillKeepAlive()); |
129 EXPECT_FALSE(service.IsTracked(contents)); | 124 EXPECT_FALSE(service.IsTracked(contents)); |
130 } | 125 } |
131 | 126 |
132 TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) { | 127 TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) { |
133 TestingProfile profile; | 128 TestingProfile profile; |
134 GetPrefs(&profile)->Clear(); | 129 GetPrefs(&profile)->Clear(); |
135 BackgroundContentsService service(&profile, command_line_.get()); | 130 BackgroundContentsService service(&profile, command_line_.get()); |
136 GURL orig_url; | 131 GURL orig_url; |
137 GURL url("http://a/"); | 132 GURL url("http://a/"); |
138 GURL url2("http://a/"); | 133 GURL url2("http://a/"); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 contents->Navigate(url); | 224 contents->Navigate(url); |
230 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 225 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
231 contents2->Navigate(url2); | 226 contents2->Navigate(url2); |
232 EXPECT_EQ(2U, GetPrefs(&profile)->size()); | 227 EXPECT_EQ(2U, GetPrefs(&profile)->size()); |
233 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); | 228 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); |
234 EXPECT_FALSE(service.IsTracked(contents)); | 229 EXPECT_FALSE(service.IsTracked(contents)); |
235 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); | 230 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); |
236 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 231 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
237 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); | 232 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); |
238 } | 233 } |
OLD | NEW |