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

Side by Side Diff: content/browser/cache_storage/cache_storage_operation_unittest.cc

Issue 2168123002: [CacheStorage] Add metrics to the scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't use unnamed namespace in header file Created 4 years, 5 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/cache_storage/cache_storage_operation.h"
6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/run_loop.h"
12 #include "base/test/histogram_tester.h"
13 #include "base/test/test_mock_time_task_runner.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
jsbell 2016/07/21 18:13:31 Needed?
jkarlin 2016/07/21 18:29:24 Done.
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace content {
18
19 namespace {
20
21 const char kSlowOperation[] =
22 "ServiceWorkerCache.CacheStorage.Scheduler.OperationSlow";
23
24 class TestTask {
25 public:
26 TestTask() = default;
27 ~TestTask() = default;
28 virtual void Run() { callback_count_++; }
jsbell 2016/07/21 18:13:31 It doesn't look like this needs to be virtual. cop
jkarlin 2016/07/21 18:29:24 Done.
29
30 int callback_count() const { return callback_count_; }
31
32 protected:
33 int callback_count_ = 0;
34 };
35
36 } // namespace
37
38 class CacheStorageOperationTest : public testing::Test {
39 protected:
40 CacheStorageOperationTest()
41 : mock_task_runner_(new base::TestMockTimeTaskRunner()) {
42 operation_ = base::MakeUnique<CacheStorageOperation>(
43 base::Bind(&TestTask::Run, base::Unretained(&task_)),
44 CacheStorageSchedulerClient::CLIENT_STORAGE, mock_task_runner_);
45 }
46
47 // TestBrowserThreadBundle browser_thread_bundle_;
jsbell 2016/07/21 18:13:31 Remove
jkarlin 2016/07/21 18:29:24 Done.
48 base::HistogramTester histogram_tester_;
49 TestTask task_;
50 scoped_refptr<base::TestMockTimeTaskRunner> mock_task_runner_;
51 std::unique_ptr<CacheStorageOperation> operation_;
52 };
53
54 TEST_F(CacheStorageOperationTest, OperationFast) {
55 operation_->Run();
56 mock_task_runner_->RunUntilIdle();
57 EXPECT_EQ(1, task_.callback_count());
58 histogram_tester_.ExpectTotalCount(kSlowOperation, 0);
59
60 // Finish the operation.
61 operation_.reset();
62
63 mock_task_runner_->RunUntilIdle();
64 EXPECT_EQ(1, task_.callback_count());
65 histogram_tester_.ExpectTotalCount(kSlowOperation, 1);
66 histogram_tester_.ExpectBucketCount(kSlowOperation, false, 1);
67 }
68
69 TEST_F(CacheStorageOperationTest, OperationSlow) {
70 operation_->Run();
71 mock_task_runner_->RunUntilIdle();
72 EXPECT_EQ(1, task_.callback_count());
73 histogram_tester_.ExpectTotalCount(kSlowOperation, 0);
74
75 // The operation takes 10 seconds.
76 mock_task_runner_->FastForwardBy(base::TimeDelta::FromSeconds(10));
77 mock_task_runner_->RunUntilIdle();
78 histogram_tester_.ExpectTotalCount(kSlowOperation, 1);
79 histogram_tester_.ExpectBucketCount(kSlowOperation, true, 1);
80
81 // Finish the operation.
82 operation_.reset();
83 mock_task_runner_->RunUntilIdle();
84 EXPECT_EQ(1, task_.callback_count());
85 histogram_tester_.ExpectTotalCount(kSlowOperation, 1);
86 histogram_tester_.ExpectBucketCount(kSlowOperation, true, 1);
87 }
88
89 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698