| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/weak_ptr.h" | 5 #include "base/memory/weak_ptr.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 // Main thread creates an arrow referencing the Target. | 556 // Main thread creates an arrow referencing the Target. |
| 557 Arrow* arrow = new Arrow(); | 557 Arrow* arrow = new Arrow(); |
| 558 arrow->target = target.AsWeakPtr(); | 558 arrow->target = target.AsWeakPtr(); |
| 559 | 559 |
| 560 // Background can delete arrow (as well as the WeakPtr inside). | 560 // Background can delete arrow (as well as the WeakPtr inside). |
| 561 BackgroundThread background; | 561 BackgroundThread background; |
| 562 background.Start(); | 562 background.Start(); |
| 563 background.DeleteArrow(arrow); | 563 background.DeleteArrow(arrow); |
| 564 } | 564 } |
| 565 | 565 |
| 566 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) && GTEST_HAS_DEATH_TEST | 566 #if DCHECK_IS_ON() && GTEST_HAS_DEATH_TEST |
| 567 | 567 |
| 568 TEST(WeakPtrDeathTest, WeakPtrCopyDoesNotChangeThreadBinding) { | 568 TEST(WeakPtrDeathTest, WeakPtrCopyDoesNotChangeThreadBinding) { |
| 569 // The default style "fast" does not support multi-threaded tests | 569 // The default style "fast" does not support multi-threaded tests |
| 570 // (introduces deadlock on Linux). | 570 // (introduces deadlock on Linux). |
| 571 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; | 571 ::testing::FLAGS_gtest_death_test_style = "threadsafe"; |
| 572 | 572 |
| 573 BackgroundThread background; | 573 BackgroundThread background; |
| 574 background.Start(); | 574 background.Start(); |
| 575 | 575 |
| 576 // Main thread creates a Target object. | 576 // Main thread creates a Target object. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 background.Start(); | 672 background.Start(); |
| 673 background.DeleteTarget(target.release()); | 673 background.DeleteTarget(target.release()); |
| 674 | 674 |
| 675 // Main thread attempts to dereference the target, violating thread binding. | 675 // Main thread attempts to dereference the target, violating thread binding. |
| 676 ASSERT_DEATH(arrow.target.get(), ""); | 676 ASSERT_DEATH(arrow.target.get(), ""); |
| 677 } | 677 } |
| 678 | 678 |
| 679 #endif | 679 #endif |
| 680 | 680 |
| 681 } // namespace base | 681 } // namespace base |
| OLD | NEW |