OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/renderer/gc_callback.h" | |
6 #include "base/bind.h" | 5 #include "base/bind.h" |
7 #include "base/macros.h" | 6 #include "base/macros.h" |
8 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
11 #include "base/test/scoped_async_task_scheduler.h" | |
12 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
13 #include "extensions/common/extension_set.h" | 11 #include "extensions/common/extension_set.h" |
14 #include "extensions/common/features/feature.h" | 12 #include "extensions/common/features/feature.h" |
| 13 #include "extensions/renderer/gc_callback.h" |
15 #include "extensions/renderer/scoped_web_frame.h" | 14 #include "extensions/renderer/scoped_web_frame.h" |
16 #include "extensions/renderer/script_context.h" | 15 #include "extensions/renderer/script_context.h" |
17 #include "extensions/renderer/script_context_set.h" | 16 #include "extensions/renderer/script_context_set.h" |
18 #include "extensions/renderer/test_extensions_renderer_client.h" | 17 #include "extensions/renderer/test_extensions_renderer_client.h" |
19 #include "gin/function_template.h" | 18 #include "gin/function_template.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "v8/include/v8.h" | 21 #include "v8/include/v8.h" |
23 | 22 |
24 namespace extensions { | 23 namespace extensions { |
25 namespace { | 24 namespace { |
26 | 25 |
27 void SetToTrue(bool* value) { | 26 void SetToTrue(bool* value) { |
28 if (*value) | 27 if (*value) |
29 ADD_FAILURE() << "Value is already true"; | 28 ADD_FAILURE() << "Value is already true"; |
30 *value = true; | 29 *value = true; |
31 } | 30 } |
32 | 31 |
33 class GCCallbackTest : public testing::Test { | 32 class GCCallbackTest : public testing::Test { |
34 public: | 33 public: |
35 GCCallbackTest() : script_context_set_(&active_extensions_) {} | 34 GCCallbackTest() : script_context_set_(&active_extensions_) {} |
36 | 35 |
37 protected: | 36 protected: |
| 37 base::MessageLoop& message_loop() { return message_loop_; } |
| 38 |
38 ScriptContextSet& script_context_set() { return script_context_set_; } | 39 ScriptContextSet& script_context_set() { return script_context_set_; } |
39 | 40 |
40 v8::Local<v8::Context> v8_context() { | 41 v8::Local<v8::Context> v8_context() { |
41 return v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), v8_context_); | 42 return v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), v8_context_); |
42 } | 43 } |
43 | 44 |
44 ScriptContext* RegisterScriptContext() { | 45 ScriptContext* RegisterScriptContext() { |
45 // No world ID. | 46 // No world ID. |
46 return script_context_set_.Register( | 47 return script_context_set_.Register( |
47 web_frame_.frame(), | 48 web_frame_.frame(), |
(...skipping 16 matching lines...) Expand all Loading... |
64 DCHECK(!local_v8_context.IsEmpty()); | 65 DCHECK(!local_v8_context.IsEmpty()); |
65 v8_context_.Reset(isolate, local_v8_context); | 66 v8_context_.Reset(isolate, local_v8_context); |
66 } | 67 } |
67 | 68 |
68 void TearDown() override { | 69 void TearDown() override { |
69 v8_context_.Reset(); | 70 v8_context_.Reset(); |
70 RequestGarbageCollection(); | 71 RequestGarbageCollection(); |
71 } | 72 } |
72 | 73 |
73 base::MessageLoop message_loop_; | 74 base::MessageLoop message_loop_; |
74 | |
75 // Required by gin::V8Platform::CallOnBackgroundThread(). Can't be a | |
76 // ScopedTaskScheduler because v8 synchronously waits for tasks to run. | |
77 base::test::ScopedAsyncTaskScheduler scoped_async_task_scheduler_; | |
78 | |
79 ScopedWebFrame web_frame_; // (this will construct the v8::Isolate) | 75 ScopedWebFrame web_frame_; // (this will construct the v8::Isolate) |
80 // ExtensionsRendererClient is a dependency of ScriptContextSet. | 76 // ExtensionsRendererClient is a dependency of ScriptContextSet. |
81 TestExtensionsRendererClient extensions_renderer_client_; | 77 TestExtensionsRendererClient extensions_renderer_client_; |
82 ExtensionIdSet active_extensions_; | 78 ExtensionIdSet active_extensions_; |
83 ScriptContextSet script_context_set_; | 79 ScriptContextSet script_context_set_; |
84 v8::Global<v8::Context> v8_context_; | 80 v8::Global<v8::Context> v8_context_; |
85 | 81 |
86 DISALLOW_COPY_AND_ASSIGN(GCCallbackTest); | 82 DISALLOW_COPY_AND_ASSIGN(GCCallbackTest); |
87 }; | 83 }; |
88 | 84 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Trigger a GC. The callback should not be invoked because the fallback was | 153 // Trigger a GC. The callback should not be invoked because the fallback was |
158 // already invoked. | 154 // already invoked. |
159 RequestGarbageCollection(); | 155 RequestGarbageCollection(); |
160 base::RunLoop().RunUntilIdle(); | 156 base::RunLoop().RunUntilIdle(); |
161 | 157 |
162 EXPECT_FALSE(callback_invoked); | 158 EXPECT_FALSE(callback_invoked); |
163 } | 159 } |
164 | 160 |
165 } // namespace | 161 } // namespace |
166 } // namespace extensions | 162 } // namespace extensions |
OLD | NEW |