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

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

Issue 2272563005: Start plumbing connections from the BudgetManager to the BudgetDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the task runner Created 4 years, 3 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
« no previous file with comments | « chrome/browser/budget_service/budget_manager_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 run_loop_closure.Run(); 69 run_loop_closure.Run();
70 } 70 }
71 71
72 void StoreBudget(double budget) { 72 void StoreBudget(double budget) {
73 const GURL origin(kTestOrigin); 73 const GURL origin(kTestOrigin);
74 base::RunLoop run_loop; 74 base::RunLoop run_loop;
75 GetManager()->StoreBudget(origin, budget, run_loop.QuitClosure()); 75 GetManager()->StoreBudget(origin, budget, run_loop.QuitClosure());
76 run_loop.Run(); 76 run_loop.Run();
77 } 77 }
78 78
79 // Budget for callbacks to set. 79 void StatusCallback(base::Closure run_loop_closure, bool success) {
80 success_ = success;
81 run_loop_closure.Run();
82 }
83
84 bool ReserveBudget(blink::mojom::BudgetOperationType type) {
85 const GURL origin(kTestOrigin);
86 base::RunLoop run_loop;
87 GetManager()->Reserve(
88 origin, type,
89 base::Bind(&BudgetManagerTest::StatusCallback, base::Unretained(this),
90 run_loop.QuitClosure()));
91 run_loop.Run();
92 return success_;
93 }
94
95 // Members for callbacks to set.
80 double budget_; 96 double budget_;
97 bool success_;
81 98
82 private: 99 private:
83 content::TestBrowserThreadBundle thread_bundle_; 100 content::TestBrowserThreadBundle thread_bundle_;
84 TestingProfile profile_; 101 TestingProfile profile_;
85 }; 102 };
86 103
87 TEST_F(BudgetManagerTest, GetBudgetNoBudgetOrSES) { 104 TEST_F(BudgetManagerTest, GetBudgetNoBudgetOrSES) {
88 EXPECT_DOUBLE_EQ(GetBudget(), 0.0); 105 EXPECT_DOUBLE_EQ(GetBudget(), 0.0);
89 } 106 }
90 107
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 257
241 // Store the updated budget. 258 // Store the updated budget.
242 StoreBudget(original_budget); 259 StoreBudget(original_budget);
243 EXPECT_NE(kTestBudget, original_budget); 260 EXPECT_NE(kTestBudget, original_budget);
244 261
245 // Now move time backwards a day and make sure that the current 262 // Now move time backwards a day and make sure that the current
246 // budget matches the budget of the most foward time. 263 // budget matches the budget of the most foward time.
247 clock->SetNow(starting_time - base::TimeDelta::FromDays(1)); 264 clock->SetNow(starting_time - base::TimeDelta::FromDays(1));
248 EXPECT_NEAR(original_budget, GetBudget(), 0.01); 265 EXPECT_NEAR(original_budget, GetBudget(), 0.01);
249 } 266 }
267
268 TEST_F(BudgetManagerTest, ReserveBudgetTest) {
269 // Reserve without any budget allocated should fail.
270 ASSERT_FALSE(ReserveBudget(blink::mojom::BudgetOperationType::SILENT_PUSH));
271 }
OLDNEW
« no previous file with comments | « chrome/browser/budget_service/budget_manager_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698