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

Side by Side Diff: chrome/browser/budget_service/budget_database_unittest.cc

Issue 2922203002: Always use milliseconds in the Budget API implementation (Closed)
Patch Set: missing file? Created 3 years, 6 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 "chrome/browser/budget_service/budget_database.h" 5 #include "chrome/browser/budget_service/budget_database.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // The budget should include kDefaultExpirationInDays days worth of 126 // The budget should include kDefaultExpirationInDays days worth of
127 // engagement. 127 // engagement.
128 double daily_budget = 128 double daily_budget =
129 kMaxDailyBudget * (kEngagement / SiteEngagementScore::kMaxPoints); 129 kMaxDailyBudget * (kEngagement / SiteEngagementScore::kMaxPoints);
130 GetBudgetDetails(); 130 GetBudgetDetails();
131 ASSERT_TRUE(success_); 131 ASSERT_TRUE(success_);
132 ASSERT_EQ(2U, prediction_.size()); 132 ASSERT_EQ(2U, prediction_.size());
133 ASSERT_DOUBLE_EQ(daily_budget * kDefaultExpirationInDays, 133 ASSERT_DOUBLE_EQ(daily_budget * kDefaultExpirationInDays,
134 prediction_[0]->budget_at); 134 prediction_[0]->budget_at);
135 ASSERT_EQ(0, prediction_[1]->budget_at); 135 ASSERT_EQ(0, prediction_[1]->budget_at);
136 ASSERT_EQ(expiration_time.ToDoubleT(), prediction_[1]->time); 136 ASSERT_EQ(expiration_time.ToDoubleT() * base::Time::kMillisecondsPerSecond,
137 prediction_[1]->time);
137 138
138 // Advance time 1 day and add more engagement budget. 139 // Advance time 1 day and add more engagement budget.
139 clock->Advance(base::TimeDelta::FromDays(1)); 140 clock->Advance(base::TimeDelta::FromDays(1));
140 GetBudgetDetails(); 141 GetBudgetDetails();
141 142
142 // The budget should now have 1 full share plus 1 daily budget. 143 // The budget should now have 1 full share plus 1 daily budget.
143 ASSERT_TRUE(success_); 144 ASSERT_TRUE(success_);
144 ASSERT_EQ(3U, prediction_.size()); 145 ASSERT_EQ(3U, prediction_.size());
145 ASSERT_DOUBLE_EQ(daily_budget * (kDefaultExpirationInDays + 1), 146 ASSERT_DOUBLE_EQ(daily_budget * (kDefaultExpirationInDays + 1),
146 prediction_[0]->budget_at); 147 prediction_[0]->budget_at);
147 ASSERT_DOUBLE_EQ(daily_budget, prediction_[1]->budget_at); 148 ASSERT_DOUBLE_EQ(daily_budget, prediction_[1]->budget_at);
148 ASSERT_EQ(expiration_time.ToDoubleT(), prediction_[1]->time); 149 ASSERT_EQ(expiration_time.ToDoubleT() * base::Time::kMillisecondsPerSecond,
150 prediction_[1]->time);
149 ASSERT_DOUBLE_EQ(0, prediction_[2]->budget_at); 151 ASSERT_DOUBLE_EQ(0, prediction_[2]->budget_at);
150 ASSERT_EQ((expiration_time + base::TimeDelta::FromDays(1)).ToDoubleT(), 152 ASSERT_EQ((expiration_time + base::TimeDelta::FromDays(1)).ToDoubleT() *
153 base::Time::kMillisecondsPerSecond,
151 prediction_[2]->time); 154 prediction_[2]->time);
152 155
153 // Advance time by 59 minutes and check that no engagement budget is added 156 // Advance time by 59 minutes and check that no engagement budget is added
154 // since budget should only be added for > 1 hour increments. 157 // since budget should only be added for > 1 hour increments.
155 clock->Advance(base::TimeDelta::FromMinutes(59)); 158 clock->Advance(base::TimeDelta::FromMinutes(59));
156 GetBudgetDetails(); 159 GetBudgetDetails();
157 160
158 // The budget should be the same as before the attempted add. 161 // The budget should be the same as before the attempted add.
159 ASSERT_TRUE(success_); 162 ASSERT_TRUE(success_);
160 ASSERT_EQ(3U, prediction_.size()); 163 ASSERT_EQ(3U, prediction_.size());
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ASSERT_FALSE(second_profile.IsOffTheRecord()); 345 ASSERT_FALSE(second_profile.IsOffTheRecord());
343 ASSERT_TRUE(second_profile_incognito->IsOffTheRecord()); 346 ASSERT_TRUE(second_profile_incognito->IsOffTheRecord());
344 347
345 // The Site Engagement Score considered by an Incognito profile must be equal 348 // The Site Engagement Score considered by an Incognito profile must be equal
346 // to the score considered in a regular profile visting a page for the first 349 // to the score considered in a regular profile visting a page for the first
347 // time. This may grant a small amount of budget, but does mean that Incognito 350 // time. This may grant a small amount of budget, but does mean that Incognito
348 // mode cannot be detected through the Budget API. 351 // mode cannot be detected through the Budget API.
349 EXPECT_EQ(database()->GetSiteEngagementScoreForOrigin(origin()), 352 EXPECT_EQ(database()->GetSiteEngagementScoreForOrigin(origin()),
350 second_database->GetSiteEngagementScoreForOrigin(origin())); 353 second_database->GetSiteEngagementScoreForOrigin(origin()));
351 } 354 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698