Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "chrome/browser/engagement/site_engagement_service.h" | 8 #include "chrome/browser/engagement/site_engagement_service.h" |
| 9 #include "chrome/browser/push_messaging/background_budget_service.h" | 9 #include "chrome/browser/push_messaging/background_budget_service.h" |
| 10 #include "chrome/browser/push_messaging/background_budget_service_factory.h" | |
| 10 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" | 12 #include "content/public/test/test_browser_thread_bundle.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 const char kTestOrigin[] = "https://example.com"; | 17 const char kTestOrigin[] = "https://example.com"; |
| 17 const double kTestBudget = 10.0; | 18 const double kTestBudget = 10.0; |
| 18 const double kTestSES = 24.0; | 19 const double kTestSES = 24.0; |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 class BackgroundBudgetServiceTest : public testing::Test { | 23 class BackgroundBudgetServiceTest : public testing::Test { |
| 23 public: | 24 public: |
| 24 BackgroundBudgetServiceTest() {} | 25 BackgroundBudgetServiceTest() {} |
| 25 ~BackgroundBudgetServiceTest() override {} | 26 ~BackgroundBudgetServiceTest() override {} |
| 26 | 27 |
| 27 TestingProfile* profile() { return &profile_; } | 28 TestingProfile* profile() { return &profile_; } |
|
Michael van Ouwerkerk
2016/04/14 14:36:31
It seems a service() method instead of a profile()
harkness
2016/04/14 17:44:19
Done.
| |
| 28 | 29 |
| 29 void SetSiteEngagementScore(const GURL& url, double score) { | 30 void SetSiteEngagementScore(const GURL& url, double score) { |
| 30 SiteEngagementService* service = SiteEngagementService::Get(&profile_); | 31 SiteEngagementService* service = SiteEngagementService::Get(&profile_); |
| 31 service->ResetScoreForURL(url, score); | 32 service->ResetScoreForURL(url, score); |
| 32 } | 33 } |
| 33 | 34 |
| 34 private: | 35 private: |
| 35 content::TestBrowserThreadBundle thread_bundle_; | 36 content::TestBrowserThreadBundle thread_bundle_; |
| 36 TestingProfile profile_; | 37 TestingProfile profile_; |
| 37 }; | 38 }; |
| 38 | 39 |
| 39 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoBudgetOrSES) { | 40 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoBudgetOrSES) { |
| 40 const GURL origin(kTestOrigin); | 41 const GURL origin(kTestOrigin); |
| 41 | 42 |
| 42 double budget = 0.0; | 43 double budget = 0.0; |
| 43 BackgroundBudgetService::GetBudget(profile(), origin, budget); | 44 BackgroundBudgetService* service = |
| 45 BackgroundBudgetServiceFactory::GetForProfile(profile()); | |
| 46 service->GetBudget(origin, budget); | |
| 44 | 47 |
| 45 EXPECT_EQ(budget, 0.0); | 48 EXPECT_EQ(budget, 0.0); |
| 46 } | 49 } |
| 47 | 50 |
| 48 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoBudgetSESExists) { | 51 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoBudgetSESExists) { |
| 49 const GURL origin(kTestOrigin); | 52 const GURL origin(kTestOrigin); |
| 50 | 53 |
| 51 // Set a starting SES for the url but no stored budget info. | 54 // Set a starting SES for the url but no stored budget info. |
| 52 SetSiteEngagementScore(origin, kTestSES); | 55 SetSiteEngagementScore(origin, kTestSES); |
| 53 | 56 |
| 54 double budget = 0.0; | 57 double budget = 0.0; |
| 55 BackgroundBudgetService::GetBudget(profile(), origin, budget); | 58 BackgroundBudgetService* service = |
| 59 BackgroundBudgetServiceFactory::GetForProfile(profile()); | |
| 60 service->GetBudget(origin, budget); | |
| 56 | 61 |
| 57 EXPECT_EQ(budget, kTestSES); | 62 EXPECT_EQ(budget, kTestSES); |
| 58 } | 63 } |
| 59 | 64 |
| 60 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoElapsedTime) { | 65 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoElapsedTime) { |
| 61 const GURL origin(kTestOrigin); | 66 const GURL origin(kTestOrigin); |
| 62 | 67 |
| 63 BackgroundBudgetService::StoreBudget(profile(), origin, kTestBudget); | 68 BackgroundBudgetService* service = |
| 69 BackgroundBudgetServiceFactory::GetForProfile(profile()); | |
| 70 service->StoreBudget(origin, kTestBudget); | |
| 64 | 71 |
| 65 double budget = 0.0; | 72 double budget = 0.0; |
| 66 BackgroundBudgetService::GetBudget(profile(), origin, budget); | 73 service->GetBudget(origin, budget); |
| 67 | 74 |
| 68 EXPECT_EQ(budget, kTestBudget); | 75 EXPECT_EQ(budget, kTestBudget); |
| 69 } | 76 } |
| OLD | NEW |