OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 CrossThreadCopier<ResourceResponse>::copy(const ResourceResponse& response) { | 62 CrossThreadCopier<ResourceResponse>::copy(const ResourceResponse& response) { |
63 return passed(response.copyData()); | 63 return passed(response.copyData()); |
64 } | 64 } |
65 | 65 |
66 // Test CrossThreadCopier using static_assert. | 66 // Test CrossThreadCopier using static_assert. |
67 | 67 |
68 // Verify that ThreadSafeRefCounted objects get handled correctly. | 68 // Verify that ThreadSafeRefCounted objects get handled correctly. |
69 class CopierThreadSafeRefCountedTest | 69 class CopierThreadSafeRefCountedTest |
70 : public ThreadSafeRefCounted<CopierThreadSafeRefCountedTest> {}; | 70 : public ThreadSafeRefCounted<CopierThreadSafeRefCountedTest> {}; |
71 | 71 |
72 // Add a generic specialization which will let's us verify that no other templat
e matches. | 72 // Add a generic specialization which will let's us verify that no other |
| 73 // template matches. |
73 template <typename T> | 74 template <typename T> |
74 struct CrossThreadCopierBase<T, false> { | 75 struct CrossThreadCopierBase<T, false> { |
75 typedef int Type; | 76 typedef int Type; |
76 }; | 77 }; |
77 | 78 |
78 static_assert( | 79 static_assert( |
79 (std::is_same<PassRefPtr<CopierThreadSafeRefCountedTest>, | 80 (std::is_same<PassRefPtr<CopierThreadSafeRefCountedTest>, |
80 CrossThreadCopier<PassRefPtr< | 81 CrossThreadCopier<PassRefPtr< |
81 CopierThreadSafeRefCountedTest>>::Type>::value), | 82 CopierThreadSafeRefCountedTest>>::Type>::value), |
82 "PassRefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); | 83 "PassRefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); |
83 static_assert( | 84 static_assert( |
84 (std::is_same<RefPtr<CopierThreadSafeRefCountedTest>, | 85 (std::is_same<RefPtr<CopierThreadSafeRefCountedTest>, |
85 CrossThreadCopier< | 86 CrossThreadCopier< |
86 RefPtr<CopierThreadSafeRefCountedTest>>::Type>::value), | 87 RefPtr<CopierThreadSafeRefCountedTest>>::Type>::value), |
87 "RefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); | 88 "RefPtr + ThreadSafeRefCounted should pass CrossThreadCopier"); |
88 static_assert( | 89 static_assert( |
89 (std::is_same< | 90 (std::is_same< |
90 int, | 91 int, |
91 CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type>::value), | 92 CrossThreadCopier<CopierThreadSafeRefCountedTest*>::Type>::value), |
92 "Raw pointer + ThreadSafeRefCounted should NOT pass CrossThreadCopier"); | 93 "Raw pointer + ThreadSafeRefCounted should NOT pass CrossThreadCopier"); |
93 | 94 |
94 // Verify that RefCounted objects only match our generic template which exposes
Type as int. | 95 // Verify that RefCounted objects only match our generic template which exposes |
| 96 // Type as int. |
95 class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> {}; | 97 class CopierRefCountedTest : public RefCounted<CopierRefCountedTest> {}; |
96 | 98 |
97 static_assert( | 99 static_assert( |
98 (std::is_same<int, CrossThreadCopier<CopierRefCountedTest*>::Type>::value), | 100 (std::is_same<int, CrossThreadCopier<CopierRefCountedTest*>::Type>::value), |
99 "Raw pointer + RefCounted should NOT pass CrossThreadCopier"); | 101 "Raw pointer + RefCounted should NOT pass CrossThreadCopier"); |
100 | 102 |
101 // Verify that std::unique_ptr gets passed through. | 103 // Verify that std::unique_ptr gets passed through. |
102 static_assert( | 104 static_assert( |
103 (std::is_same<std::unique_ptr<float>, | 105 (std::is_same<std::unique_ptr<float>, |
104 CrossThreadCopier<std::unique_ptr<float>>::Type>::value), | 106 CrossThreadCopier<std::unique_ptr<float>>::Type>::value), |
105 "std::unique_ptr test"); | 107 "std::unique_ptr test"); |
106 | 108 |
107 } // namespace blink | 109 } // namespace blink |
OLD | NEW |