Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: extensions/renderer/gc_callback_unittest.cc

Issue 2628053003: Remove extension group from DOMWrapperWorld. (Closed)
Patch Set: Fix GCCallbackTest Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/renderer/extension_groups.h ('k') | extensions/renderer/script_context_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/memory/weak_ptr.h" 7 #include "base/memory/weak_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "extensions/common/extension.h" 10 #include "extensions/common/extension.h"
11 #include "extensions/common/extension_set.h" 11 #include "extensions/common/extension_set.h"
12 #include "extensions/common/features/feature.h" 12 #include "extensions/common/features/feature.h"
13 #include "extensions/renderer/gc_callback.h" 13 #include "extensions/renderer/gc_callback.h"
14 #include "extensions/renderer/scoped_web_frame.h" 14 #include "extensions/renderer/scoped_web_frame.h"
15 #include "extensions/renderer/script_context.h" 15 #include "extensions/renderer/script_context.h"
16 #include "extensions/renderer/script_context_set.h" 16 #include "extensions/renderer/script_context_set.h"
17 #include "extensions/renderer/test_extensions_renderer_client.h"
17 #include "gin/function_template.h" 18 #include "gin/function_template.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/public/web/WebFrame.h" 20 #include "third_party/WebKit/public/web/WebFrame.h"
20 #include "v8/include/v8.h" 21 #include "v8/include/v8.h"
21 22
22 namespace extensions { 23 namespace extensions {
23 namespace { 24 namespace {
24 25
25 void SetToTrue(bool* value) { 26 void SetToTrue(bool* value) {
26 if (*value) 27 if (*value)
27 ADD_FAILURE() << "Value is already true"; 28 ADD_FAILURE() << "Value is already true";
28 *value = true; 29 *value = true;
29 } 30 }
30 31
31 class GCCallbackTest : public testing::Test { 32 class GCCallbackTest : public testing::Test {
32 public: 33 public:
33 GCCallbackTest() : script_context_set_(&active_extensions_) {} 34 GCCallbackTest() : script_context_set_(&active_extensions_) {}
34 35
35 protected: 36 protected:
36 base::MessageLoop& message_loop() { return message_loop_; } 37 base::MessageLoop& message_loop() { return message_loop_; }
37 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 extension group or 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(),
48 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), v8_context_), 0, 49 v8::Local<v8::Context>::New(v8::Isolate::GetCurrent(), v8_context_), 0);
49 0);
50 } 50 }
51 51
52 void RequestGarbageCollection() { 52 void RequestGarbageCollection() {
53 v8::Isolate::GetCurrent()->RequestGarbageCollectionForTesting( 53 v8::Isolate::GetCurrent()->RequestGarbageCollectionForTesting(
54 v8::Isolate::kFullGarbageCollection); 54 v8::Isolate::kFullGarbageCollection);
55 } 55 }
56 56
57 private: 57 private:
58 void SetUp() override { 58 void SetUp() override {
59 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 59 v8::Isolate* isolate = v8::Isolate::GetCurrent();
60 v8::HandleScope handle_scope(isolate); 60 v8::HandleScope handle_scope(isolate);
61 // We need a context that has been initialized by blink; grab the main world 61 // We need a context that has been initialized by blink; grab the main world
62 // context from the web frame. 62 // context from the web frame.
63 v8::Local<v8::Context> local_v8_context = 63 v8::Local<v8::Context> local_v8_context =
64 web_frame_.frame()->mainWorldScriptContext(); 64 web_frame_.frame()->mainWorldScriptContext();
65 DCHECK(!local_v8_context.IsEmpty()); 65 DCHECK(!local_v8_context.IsEmpty());
66 v8_context_.Reset(isolate, local_v8_context); 66 v8_context_.Reset(isolate, local_v8_context);
67 } 67 }
68 68
69 void TearDown() override { 69 void TearDown() override {
70 v8_context_.Reset(); 70 v8_context_.Reset();
71 RequestGarbageCollection(); 71 RequestGarbageCollection();
72 } 72 }
73 73
74 base::MessageLoop message_loop_; 74 base::MessageLoop message_loop_;
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.
77 TestExtensionsRendererClient extensions_renderer_client_;
76 ExtensionIdSet active_extensions_; 78 ExtensionIdSet active_extensions_;
77 ScriptContextSet script_context_set_; 79 ScriptContextSet script_context_set_;
78 v8::Global<v8::Context> v8_context_; 80 v8::Global<v8::Context> v8_context_;
79 81
80 DISALLOW_COPY_AND_ASSIGN(GCCallbackTest); 82 DISALLOW_COPY_AND_ASSIGN(GCCallbackTest);
81 }; 83 };
82 84
83 TEST_F(GCCallbackTest, GCBeforeContextInvalidated) { 85 TEST_F(GCCallbackTest, GCBeforeContextInvalidated) {
84 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 86 v8::Isolate* isolate = v8::Isolate::GetCurrent();
85 v8::HandleScope handle_scope(isolate); 87 v8::HandleScope handle_scope(isolate);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 // 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
152 // already invoked. 154 // already invoked.
153 RequestGarbageCollection(); 155 RequestGarbageCollection();
154 base::RunLoop().RunUntilIdle(); 156 base::RunLoop().RunUntilIdle();
155 157
156 EXPECT_FALSE(callback_invoked); 158 EXPECT_FALSE(callback_invoked);
157 } 159 }
158 160
159 } // namespace 161 } // namespace
160 } // namespace extensions 162 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/extension_groups.h ('k') | extensions/renderer/script_context_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698