Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/common/one_shot_event.h" | 5 #include "extensions/common/one_shot_event.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/test/test_simple_task_runner.h" | 10 #include "base/test/test_simple_task_runner.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 TEST(OneShotEventTest, CallsQueue) { | 26 TEST(OneShotEventTest, CallsQueue) { |
| 27 OneShotEvent event; | 27 OneShotEvent event; |
| 28 scoped_refptr<base::TestSimpleTaskRunner> runner( | 28 scoped_refptr<base::TestSimpleTaskRunner> runner( |
| 29 new base::TestSimpleTaskRunner); | 29 new base::TestSimpleTaskRunner); |
| 30 int i = 0; | 30 int i = 0; |
| 31 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); | 31 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); |
| 32 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); | 32 event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); |
| 33 EXPECT_EQ(0U, runner->NumPendingTasks()); | 33 EXPECT_EQ(0U, runner->NumPendingTasks()); |
| 34 event.Signal(); | 34 event.Signal(); |
| 35 ASSERT_EQ(2U, runner->NumPendingTasks()); | 35 ASSERT_EQ(2U, runner->NumPendingTasks()); |
| 36 EXPECT_NE(runner->GetPendingTasks()[0].location.line_number(), | 36 |
| 37 runner->GetPendingTasks()[1].location.line_number()) | 37 base::Optional<tracked_objects::Location> first_item_location = |
| 38 runner->GetPendingTaskLocationAt(0); | |
|
danakj
2016/09/29 19:42:13
Proposal: Rewrite this test to TakePendingTasks in
tzik
2016/09/30 04:00:26
SG. Updated.
| |
| 39 base::Optional<tracked_objects::Location> second_item_location = | |
| 40 runner->GetPendingTaskLocationAt(1); | |
| 41 ASSERT_TRUE(first_item_location); | |
| 42 ASSERT_TRUE(second_item_location); | |
| 43 EXPECT_NE(first_item_location->line_number(), | |
| 44 second_item_location->line_number()) | |
| 38 << "Make sure FROM_HERE is propagated."; | 45 << "Make sure FROM_HERE is propagated."; |
| 39 EXPECT_EQ(0, i); | 46 EXPECT_EQ(0, i); |
| 40 runner->RunPendingTasks(); | 47 runner->RunPendingTasks(); |
| 41 EXPECT_EQ(2, i); | 48 EXPECT_EQ(2, i); |
| 42 } | 49 } |
| 43 | 50 |
| 44 TEST(OneShotEventTest, CallsAfterSignalDontRunInline) { | 51 TEST(OneShotEventTest, CallsAfterSignalDontRunInline) { |
| 45 OneShotEvent event; | 52 OneShotEvent event; |
| 46 scoped_refptr<base::TestSimpleTaskRunner> runner( | 53 scoped_refptr<base::TestSimpleTaskRunner> runner( |
| 47 new base::TestSimpleTaskRunner); | 54 new base::TestSimpleTaskRunner); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 EXPECT_EQ(1U, runner->NumPendingTasks()); | 110 EXPECT_EQ(1U, runner->NumPendingTasks()); |
| 104 EXPECT_EQ(0, i); | 111 EXPECT_EQ(0, i); |
| 105 runner->RunPendingTasks(); | 112 runner->RunPendingTasks(); |
| 106 // Increment has run. | 113 // Increment has run. |
| 107 EXPECT_EQ(0U, runner->NumPendingTasks()); | 114 EXPECT_EQ(0U, runner->NumPendingTasks()); |
| 108 EXPECT_EQ(1, i); | 115 EXPECT_EQ(1, i); |
| 109 } | 116 } |
| 110 | 117 |
| 111 } // namespace | 118 } // namespace |
| 112 } // namespace extensions | 119 } // namespace extensions |
| OLD | NEW |