| 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 #include <string> |
| 5 | 6 |
| 6 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 7 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/background_contents_service.h" | 11 #include "chrome/browser/background_contents_service.h" |
| 11 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 12 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 13 #include "chrome/browser/tab_contents/background_contents.h" | 14 #include "chrome/browser/tab_contents/background_contents.h" |
| 14 #include "chrome/common/chrome_switches.h" | |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/testing_browser_process.h" | 16 #include "chrome/test/testing_browser_process.h" |
| 17 #include "chrome/test/testing_profile.h" | 17 #include "chrome/test/testing_profile.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
| 21 | 21 |
| 22 class BackgroundContentsServiceTest : public testing::Test { | 22 class BackgroundContentsServiceTest : public testing::Test { |
| 23 public: | 23 public: |
| 24 BackgroundContentsServiceTest() {} | 24 BackgroundContentsServiceTest() {} |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 contents->SendOpenedNotification(&service); | 131 contents->SendOpenedNotification(&service); |
| 132 | 132 |
| 133 contents->Navigate(url); | 133 contents->Navigate(url); |
| 134 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 134 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
| 135 EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); | 135 EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); |
| 136 | 136 |
| 137 // Navigate the contents to a new url, should not change url. | 137 // Navigate the contents to a new url, should not change url. |
| 138 contents->Navigate(url2); | 138 contents->Navigate(url2); |
| 139 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 139 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
| 140 EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); | 140 EXPECT_EQ(url.spec(), GetPrefURLForApp(&profile, contents->appid())); |
| 141 | |
| 142 } | 141 } |
| 143 // Contents are deleted, url should persist. | 142 // Contents are deleted, url should persist. |
| 144 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 143 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
| 145 } | 144 } |
| 146 | 145 |
| 147 TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) { | 146 TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) { |
| 148 TestingProfile profile; | 147 TestingProfile profile; |
| 149 GetPrefs(&profile)->Clear(); | 148 GetPrefs(&profile)->Clear(); |
| 150 BackgroundContentsService service(&profile, command_line_.get()); | 149 BackgroundContentsService service(&profile, command_line_.get()); |
| 151 GURL url("http://a/"); | 150 GURL url("http://a/"); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 contents->Navigate(url); | 216 contents->Navigate(url); |
| 218 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 217 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
| 219 contents2->Navigate(url2); | 218 contents2->Navigate(url2); |
| 220 EXPECT_EQ(2U, GetPrefs(&profile)->size()); | 219 EXPECT_EQ(2U, GetPrefs(&profile)->size()); |
| 221 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); | 220 service.ShutdownAssociatedBackgroundContents(ASCIIToUTF16("appid")); |
| 222 EXPECT_FALSE(service.IsTracked(contents)); | 221 EXPECT_FALSE(service.IsTracked(contents)); |
| 223 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); | 222 EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid"))); |
| 224 EXPECT_EQ(1U, GetPrefs(&profile)->size()); | 223 EXPECT_EQ(1U, GetPrefs(&profile)->size()); |
| 225 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); | 224 EXPECT_EQ(url2.spec(), GetPrefURLForApp(&profile, contents2->appid())); |
| 226 } | 225 } |
| OLD | NEW |