| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/background_page_tracker.h" | 8 #include "chrome/browser/background_page_tracker.h" |
| 9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
| 10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
| 11 #include "chrome/common/notification_type.h" | 11 #include "chrome/common/notification_type.h" |
| 12 #include "chrome/test/testing_pref_service.h" | 12 #include "chrome/test/testing_pref_service.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 15 | 15 |
| 16 class MockBackgroundPageTracker : public BackgroundPageTracker { | 16 class MockBackgroundPageTracker : public BackgroundPageTracker { |
| 17 public: | 17 public: |
| 18 MockBackgroundPageTracker() { | 18 MockBackgroundPageTracker() |
| 19 BackgroundPageTracker::RegisterPrefs(&prefs_); | 19 : prefs_(TestingPrefService::CreateTestingPrefService()) { |
| 20 BackgroundPageTracker::RegisterPrefs(prefs_.get()); |
| 20 } | 21 } |
| 21 ~MockBackgroundPageTracker() {} | 22 ~MockBackgroundPageTracker() {} |
| 22 // Overridden from BackgroundPageTracker to mock out functionality. | 23 // Overridden from BackgroundPageTracker to mock out functionality. |
| 23 virtual bool IsEnabled() { return true; } | 24 virtual bool IsEnabled() { return true; } |
| 24 virtual PrefService* GetPrefService() { return &prefs_; } | 25 virtual PrefService* GetPrefService() { return prefs_.get(); } |
| 25 private: | 26 private: |
| 26 TestingPrefService prefs_; | 27 scoped_ptr<TestingPrefService> prefs_; |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 TEST(BackgroundPageTrackerTest, Create) { | 30 TEST(BackgroundPageTrackerTest, Create) { |
| 30 MockBackgroundPageTracker tracker; | 31 MockBackgroundPageTracker tracker; |
| 31 EXPECT_EQ(0, tracker.GetBackgroundPageCount()); | 32 EXPECT_EQ(0, tracker.GetBackgroundPageCount()); |
| 32 EXPECT_EQ(0, tracker.GetUnacknowledgedBackgroundPageCount()); | 33 EXPECT_EQ(0, tracker.GetUnacknowledgedBackgroundPageCount()); |
| 33 } | 34 } |
| 34 | 35 |
| 35 TEST(BackgroundPageTrackerTest, OnBackgroundPageLoaded) { | 36 TEST(BackgroundPageTrackerTest, OnBackgroundPageLoaded) { |
| 36 MockBackgroundPageTracker tracker; | 37 MockBackgroundPageTracker tracker; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 tracker.OnBackgroundPageLoaded(app2); | 113 tracker.OnBackgroundPageLoaded(app2); |
| 113 EXPECT_EQ(2, counter.count()); | 114 EXPECT_EQ(2, counter.count()); |
| 114 // Acknowledging pages should generate notification. | 115 // Acknowledging pages should generate notification. |
| 115 tracker.AcknowledgeBackgroundPages(); | 116 tracker.AcknowledgeBackgroundPages(); |
| 116 EXPECT_EQ(3, counter.count()); | 117 EXPECT_EQ(3, counter.count()); |
| 117 tracker.OnBackgroundPageLoaded(app1); | 118 tracker.OnBackgroundPageLoaded(app1); |
| 118 EXPECT_EQ(3, counter.count()); | 119 EXPECT_EQ(3, counter.count()); |
| 119 tracker.OnBackgroundPageLoaded(app3); | 120 tracker.OnBackgroundPageLoaded(app3); |
| 120 EXPECT_EQ(4, counter.count()); | 121 EXPECT_EQ(4, counter.count()); |
| 121 } | 122 } |
| OLD | NEW |