Output data about media requests to the netlog too.
[chromium-blink-merge.git] / base / cancellation_flag_unittest.cc
blobeb28b53ebea54d4598c34ad49a3cd0a31f0468ac
1 // Copyright (c) 2010 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/cancellation_flag.h"
9 #include "base/logging.h"
10 #include "base/message_loop.h"
11 #include "base/spin_wait.h"
12 #include "base/time.h"
13 #include "base/thread.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h"
17 using base::CancellationFlag;
18 using base::TimeDelta;
19 using base::Thread;
21 namespace {
23 //------------------------------------------------------------------------------
24 // Define our test class.
25 //------------------------------------------------------------------------------
27 class CancelTask : public Task {
28 public:
29 explicit CancelTask(CancellationFlag* flag) : flag_(flag) {}
30 virtual void Run() {
31 ASSERT_DEBUG_DEATH(flag_->Set(), "");
33 private:
34 CancellationFlag* flag_;
37 TEST(CancellationFlagTest, SimpleSingleThreadedTest) {
38 CancellationFlag flag;
39 ASSERT_FALSE(flag.IsSet());
40 flag.Set();
41 ASSERT_TRUE(flag.IsSet());
44 TEST(CancellationFlagTest, DoubleSetTest) {
45 CancellationFlag flag;
46 ASSERT_FALSE(flag.IsSet());
47 flag.Set();
48 ASSERT_TRUE(flag.IsSet());
49 flag.Set();
50 ASSERT_TRUE(flag.IsSet());
53 TEST(CancellationFlagTest, SetOnDifferentThreadDeathTest) {
54 // Checks that Set() can't be called from any other thread.
55 // CancellationFlag should die on a DCHECK if Set() is called from
56 // other thread.
57 ::testing::FLAGS_gtest_death_test_style = "threadsafe";
58 Thread t("CancellationFlagTest.SetOnDifferentThreadDeathTest");
59 ASSERT_TRUE(t.Start());
60 ASSERT_TRUE(t.message_loop());
61 ASSERT_TRUE(t.IsRunning());
63 CancellationFlag flag;
64 t.message_loop()->PostTask(FROM_HERE, new CancelTask(&flag));
67 } // namespace