Adds resource_provider::ResourceProvider
[chromium-blink-merge.git] / base / synchronization / cancellation_flag_unittest.cc
blob13c74bcbd45ffa7b12703e93ab4c5065ccbff88b
1 // Copyright (c) 2011 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.
5 // Tests of CancellationFlag class.
7 #include "base/synchronization/cancellation_flag.h"
9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/logging.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/synchronization/spin_wait.h"
14 #include "base/threading/thread.h"
15 #include "base/time/time.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h"
19 namespace base {
21 namespace {
23 //------------------------------------------------------------------------------
24 // Define our test class.
25 //------------------------------------------------------------------------------
27 void CancelHelper(CancellationFlag* flag) {
28 #if GTEST_HAS_DEATH_TEST
29 ASSERT_DEBUG_DEATH(flag->Set(), "");
30 #endif
33 TEST(CancellationFlagTest, SimpleSingleThreadedTest) {
34 CancellationFlag flag;
35 ASSERT_FALSE(flag.IsSet());
36 flag.Set();
37 ASSERT_TRUE(flag.IsSet());
40 TEST(CancellationFlagTest, DoubleSetTest) {
41 CancellationFlag flag;
42 ASSERT_FALSE(flag.IsSet());
43 flag.Set();
44 ASSERT_TRUE(flag.IsSet());
45 flag.Set();
46 ASSERT_TRUE(flag.IsSet());
49 TEST(CancellationFlagTest, SetOnDifferentThreadDeathTest) {
50 // Checks that Set() can't be called from any other thread.
51 // CancellationFlag should die on a DCHECK if Set() is called from
52 // other thread.
53 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
54 Thread t("CancellationFlagTest.SetOnDifferentThreadDeathTest");
55 ASSERT_TRUE(t.Start());
56 ASSERT_TRUE(t.message_loop());
57 ASSERT_TRUE(t.IsRunning());
59 CancellationFlag flag;
60 t.task_runner()->PostTask(FROM_HERE, base::Bind(&CancelHelper, &flag));
63 } // namespace
65 } // namespace base