Rename the PolicyManager to UpdateManager. This change renames the PolicyManager class, directory, tests, etc, to avoid confusion with libpolicy and its classes. BUG=chromium:373551 TEST=emerged on link. CQ-DEPEND=CL:I43081673c7ba409f02273197da7915537bde39c6 Change-Id: Iffa76caa3b95ecbbdba87ab01006d1d8ce35a27f Reviewed-on: https://chromium-review.googlesource.com/201876 Tested-by: Alex Deymo <[email protected]> Reviewed-by: David Zeuthen <[email protected]> Commit-Queue: Alex Deymo <[email protected]>
diff --git a/update_manager/event_loop_unittest.cc b/update_manager/event_loop_unittest.cc new file mode 100644 index 0000000..69325fe --- /dev/null +++ b/update_manager/event_loop_unittest.cc
@@ -0,0 +1,62 @@ +// Copyright (c) 2014 The Chromium OS 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 "update_engine/update_manager/event_loop.h" + +#include <base/bind.h> +#include <gtest/gtest.h> + +#include "update_engine/test_utils.h" + +using base::Bind; +using base::TimeDelta; +using chromeos_update_engine::RunGMainLoopMaxIterations; +using chromeos_update_engine::RunGMainLoopUntil; + +namespace { + +// Sets the value of the passed pointer to true. +void SetTrue(bool* value) { + *value = true; +} + +bool GetBoolean(bool* value) { + return *value; +} + +} // namespace + +namespace chromeos_update_manager { + +class EventLoopTest : public ::testing::Test {}; + +TEST(EventLoopTest, RunFromMainLoopTest) { + bool called = false; + EventId ev = RunFromMainLoop(Bind(SetTrue, &called)); + EXPECT_NE(0, ev); + RunGMainLoopMaxIterations(100); + EXPECT_TRUE(called); +} + +// Tests that we can cancel events right after we schedule them. +TEST(EventLoopTest, RunFromMainLoopCancelTest) { + bool called = false; + EventId ev = RunFromMainLoop(Bind(SetTrue, &called)); + EXPECT_NE(0, ev); + EXPECT_TRUE(CancelMainLoopEvent(ev)); + RunGMainLoopMaxIterations(100); + EXPECT_FALSE(called); +} + +TEST(EventLoopTest, RunFromMainLoopAfterTimeoutTest) { + bool called = false; + EventId ev = RunFromMainLoopAfterTimeout(Bind(SetTrue, &called), + TimeDelta::FromSeconds(1)); + EXPECT_NE(0, ev); + RunGMainLoopUntil(10000, Bind(GetBoolean, &called)); + // Check that the main loop finished before the 10 seconds timeout. + EXPECT_TRUE(called); +} + +} // namespace chromeos_update_manager