Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: chrome/browser/push_messaging/background_budget_service_unittest.cc

Issue 1887623002: Replace the 1 in 10 grace period with an accumulating budget based on SES. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/push_messaging/background_budget_service.h" 9 #include "chrome/browser/push_messaging/background_budget_service.h"
9 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/test/test_browser_thread_bundle.h" 11 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 const char kTestOrigin[] = "https://example.com"; 16 const char kTestOrigin[] = "https://example.com";
16 const char kTestData[] = "1111101111"; 17 const double kTestBudget = 10.0;
18 const double kTestSES = 24.0;
17 19
18 } // namespace 20 } // namespace
19 21
20 class BackgroundBudgetServiceTest : public testing::Test { 22 class BackgroundBudgetServiceTest : public testing::Test {
21 public: 23 public:
22 BackgroundBudgetServiceTest() {} 24 BackgroundBudgetServiceTest() {}
23 ~BackgroundBudgetServiceTest() override {} 25 ~BackgroundBudgetServiceTest() override {}
24 26
25 TestingProfile* profile() { return &profile_; } 27 TestingProfile* profile() { return &profile_; }
26 28
29 void SetSiteEngagementScore(const GURL& url, double score) {
30 SiteEngagementService* service = SiteEngagementService::Get(&profile_);
31 service->ResetScoreForURL(url, score);
32 }
33
27 private: 34 private:
28 content::TestBrowserThreadBundle thread_bundle_; 35 content::TestBrowserThreadBundle thread_bundle_;
29 TestingProfile profile_; 36 TestingProfile profile_;
30 }; 37 };
31 38
32 TEST_F(BackgroundBudgetServiceTest, GetBudgetFailure) { 39 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoBudgetOrSES) {
33 const GURL origin(kTestOrigin); 40 const GURL origin(kTestOrigin);
34 41
35 std::string budget_string = 42 double budget = 0.0;
36 BackgroundBudgetService::GetBudget(profile(), origin); 43 BackgroundBudgetService::GetBudget(profile(), origin, budget);
37 44
38 EXPECT_EQ(std::string(), budget_string); 45 EXPECT_EQ(budget, 0.0);
Peter Beverloo 2016/04/14 18:02:09 EXPECT_DOUBLE_EQ(), elsewhere too Comparisons are
harkness 2016/04/27 11:21:08 Done, and I changed a lot of them to EXPECT_NEAR w
39 } 46 }
40 47
41 TEST_F(BackgroundBudgetServiceTest, GetBudgetSuccess) { 48 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoBudgetSESExists) {
42 const GURL origin(kTestOrigin); 49 const GURL origin(kTestOrigin);
43 50
44 BackgroundBudgetService::StoreBudget(profile(), origin, kTestData); 51 // Set a starting SES for the url but no stored budget info.
52 SetSiteEngagementScore(origin, kTestSES);
45 53
46 std::string budget_string = 54 double budget = 0.0;
47 BackgroundBudgetService::GetBudget(profile(), origin); 55 BackgroundBudgetService::GetBudget(profile(), origin, budget);
48 56
49 EXPECT_EQ(kTestData, budget_string); 57 EXPECT_EQ(budget, kTestSES);
50 } 58 }
59
60 TEST_F(BackgroundBudgetServiceTest, GetBudgetNoElapsedTime) {
61 const GURL origin(kTestOrigin);
62
63 BackgroundBudgetService::StoreBudget(profile(), origin, kTestBudget);
64
65 double budget = 0.0;
66 BackgroundBudgetService::GetBudget(profile(), origin, budget);
67
68 EXPECT_EQ(budget, kTestBudget);
Peter Beverloo 2016/04/14 18:02:09 You probably want to talk to Sami about a thing we
harkness 2016/04/27 11:21:08 Many more tests added, now that I have a clock in
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698