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