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

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

Issue 2934063002: Always use milliseconds in the Budget API implementation (Closed)
Patch Set: 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.ToJsTime(), prediction_[1]->time);
137 137
138 // Advance time 1 day and add more engagement budget. 138 // Advance time 1 day and add more engagement budget.
139 clock->Advance(base::TimeDelta::FromDays(1)); 139 clock->Advance(base::TimeDelta::FromDays(1));
140 GetBudgetDetails(); 140 GetBudgetDetails();
141 141
142 // The budget should now have 1 full share plus 1 daily budget. 142 // The budget should now have 1 full share plus 1 daily budget.
143 ASSERT_TRUE(success_); 143 ASSERT_TRUE(success_);
144 ASSERT_EQ(3U, prediction_.size()); 144 ASSERT_EQ(3U, prediction_.size());
145 ASSERT_DOUBLE_EQ(daily_budget * (kDefaultExpirationInDays + 1), 145 ASSERT_DOUBLE_EQ(daily_budget * (kDefaultExpirationInDays + 1),
146 prediction_[0]->budget_at); 146 prediction_[0]->budget_at);
147 ASSERT_DOUBLE_EQ(daily_budget, prediction_[1]->budget_at); 147 ASSERT_DOUBLE_EQ(daily_budget, prediction_[1]->budget_at);
148 ASSERT_EQ(expiration_time.ToDoubleT(), prediction_[1]->time); 148 ASSERT_EQ(expiration_time.ToJsTime(), prediction_[1]->time);
149 ASSERT_DOUBLE_EQ(0, prediction_[2]->budget_at); 149 ASSERT_DOUBLE_EQ(0, prediction_[2]->budget_at);
150 ASSERT_EQ((expiration_time + base::TimeDelta::FromDays(1)).ToDoubleT(), 150 ASSERT_EQ((expiration_time + base::TimeDelta::FromDays(1)).ToJsTime(),
151 prediction_[2]->time); 151 prediction_[2]->time);
152 152
153 // Advance time by 59 minutes and check that no engagement budget is added 153 // Advance time by 59 minutes and check that no engagement budget is added
154 // since budget should only be added for > 1 hour increments. 154 // since budget should only be added for > 1 hour increments.
155 clock->Advance(base::TimeDelta::FromMinutes(59)); 155 clock->Advance(base::TimeDelta::FromMinutes(59));
156 GetBudgetDetails(); 156 GetBudgetDetails();
157 157
158 // The budget should be the same as before the attempted add. 158 // The budget should be the same as before the attempted add.
159 ASSERT_TRUE(success_); 159 ASSERT_TRUE(success_);
160 ASSERT_EQ(3U, prediction_.size()); 160 ASSERT_EQ(3U, prediction_.size());
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ASSERT_FALSE(second_profile.IsOffTheRecord()); 342 ASSERT_FALSE(second_profile.IsOffTheRecord());
343 ASSERT_TRUE(second_profile_incognito->IsOffTheRecord()); 343 ASSERT_TRUE(second_profile_incognito->IsOffTheRecord());
344 344
345 // The Site Engagement Score considered by an Incognito profile must be equal 345 // 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 346 // 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 347 // time. This may grant a small amount of budget, but does mean that Incognito
348 // mode cannot be detected through the Budget API. 348 // mode cannot be detected through the Budget API.
349 EXPECT_EQ(database()->GetSiteEngagementScoreForOrigin(origin()), 349 EXPECT_EQ(database()->GetSiteEngagementScoreForOrigin(origin()),
350 second_database->GetSiteEngagementScoreForOrigin(origin())); 350 second_database->GetSiteEngagementScoreForOrigin(origin()));
351 } 351 }
OLDNEW
« no previous file with comments | « chrome/browser/budget_service/budget_database.cc ('k') | chrome/browser/budget_service/budget_service_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698