diff options
author | sorin <sorin@chromium.org> | 2015-05-26 12:59:09 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-26 20:00:01 +0000 |
commit | 7c7176234e553c35a2d8ec014f2caa29f7278065 (patch) | |
tree | 70eb3c58c82369cc13c939c17ae63344644c4b31 /components/component_updater/timer_unittest.cc | |
parent | 92780e77b6e0755e1d4bacbd493032969d04293b (diff) | |
download | chromium_src-7c7176234e553c35a2d8ec014f2caa29f7278065.zip chromium_src-7c7176234e553c35a2d8ec014f2caa29f7278065.tar.gz chromium_src-7c7176234e553c35a2d8ec014f2caa29f7278065.tar.bz2 |
Rewrite component update service in terms of components/update_client.
The goal of this change is to re-implement the component updater by
reusing the common code in components/update_client while keeping
the its public interface the same as before, in order to minimize
changes in its existing clients.
BUG=450337
Review URL: https://codereview.chromium.org/1133443002
Cr-Commit-Position: refs/heads/master@{#331412}
Diffstat (limited to 'components/component_updater/timer_unittest.cc')
-rw-r--r-- | components/component_updater/timer_unittest.cc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/components/component_updater/timer_unittest.cc b/components/component_updater/timer_unittest.cc new file mode 100644 index 0000000..2c80e84 --- /dev/null +++ b/components/component_updater/timer_unittest.cc @@ -0,0 +1,61 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <string> + +#include "base/message_loop/message_loop.h" +#include "base/run_loop.h" +#include "base/time/time.h" +#include "components/component_updater/timer.h" +#include "testing/gtest/include/gtest/gtest.h" + +using std::string; + +namespace component_updater { + +class ComponentUpdaterTimerTest : public testing::Test { + public: + ComponentUpdaterTimerTest() {} + ~ComponentUpdaterTimerTest() override {} + + private: + base::MessageLoopForUI message_loop_; +}; + +TEST_F(ComponentUpdaterTimerTest, Start) { + class TimerClientFake { + public: + TimerClientFake(int max_count, const base::Closure& quit_closure) + : max_count_(max_count), quit_closure_(quit_closure), count_(0) {} + + void OnTimerEvent() { + ++count_; + if (count_ >= max_count_) + quit_closure_.Run(); + } + + int count() const { return count_; } + + private: + const int max_count_; + const base::Closure quit_closure_; + + int count_; + }; + + base::RunLoop run_loop; + TimerClientFake timer_client_fake(3, run_loop.QuitClosure()); + EXPECT_EQ(0, timer_client_fake.count()); + + Timer timer; + const base::TimeDelta delay(base::TimeDelta::FromMilliseconds(1)); + timer.Start(delay, delay, base::Bind(&TimerClientFake::OnTimerEvent, + base::Unretained(&timer_client_fake))); + run_loop.Run(); + timer.Stop(); + + EXPECT_EQ(3, timer_client_fake.count()); +} + +} // namespace component_updater |