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

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

Issue 2090063002: Remove calls to deprecated MessageLoop methods in extensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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 "extensions/common/extension.h" 10 #include "extensions/common/extension.h"
10 #include "extensions/common/extension_set.h" 11 #include "extensions/common/extension_set.h"
11 #include "extensions/common/features/feature.h" 12 #include "extensions/common/features/feature.h"
12 #include "extensions/renderer/gc_callback.h" 13 #include "extensions/renderer/gc_callback.h"
13 #include "extensions/renderer/scoped_web_frame.h" 14 #include "extensions/renderer/scoped_web_frame.h"
14 #include "extensions/renderer/script_context.h" 15 #include "extensions/renderer/script_context.h"
15 #include "extensions/renderer/script_context_set.h" 16 #include "extensions/renderer/script_context_set.h"
16 #include "gin/function_template.h" 17 #include "gin/function_template.h"
17 #include "gin/public/context_holder.h" 18 #include "gin/public/context_holder.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 v8::Local<v8::FunctionTemplate> unreachable_function = 100 v8::Local<v8::FunctionTemplate> unreachable_function =
100 gin::CreateFunctionTemplate(isolate, 101 gin::CreateFunctionTemplate(isolate,
101 base::Bind(SetToTrue, &callback_invoked)); 102 base::Bind(SetToTrue, &callback_invoked));
102 // The GCCallback will delete itself, or memory tests will complain. 103 // The GCCallback will delete itself, or memory tests will complain.
103 new GCCallback(script_context, object, unreachable_function->GetFunction(), 104 new GCCallback(script_context, object, unreachable_function->GetFunction(),
104 base::Bind(SetToTrue, &fallback_invoked)); 105 base::Bind(SetToTrue, &fallback_invoked));
105 } 106 }
106 107
107 // Trigger a GC. Only the callback should be invoked. 108 // Trigger a GC. Only the callback should be invoked.
108 RequestGarbageCollection(); 109 RequestGarbageCollection();
109 message_loop().RunUntilIdle(); 110 base::RunLoop().RunUntilIdle();
110 111
111 EXPECT_TRUE(callback_invoked); 112 EXPECT_TRUE(callback_invoked);
112 EXPECT_FALSE(fallback_invoked); 113 EXPECT_FALSE(fallback_invoked);
113 114
114 // Invalidate the context. The fallback should not be invoked because the 115 // Invalidate the context. The fallback should not be invoked because the
115 // callback was already invoked. 116 // callback was already invoked.
116 script_context_set().Remove(script_context); 117 script_context_set().Remove(script_context);
117 message_loop().RunUntilIdle(); 118 base::RunLoop().RunUntilIdle();
118 119
119 EXPECT_FALSE(fallback_invoked); 120 EXPECT_FALSE(fallback_invoked);
120 } 121 }
121 122
122 TEST_F(GCCallbackTest, ContextInvalidatedBeforeGC) { 123 TEST_F(GCCallbackTest, ContextInvalidatedBeforeGC) {
123 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 124 v8::Isolate* isolate = v8::Isolate::GetCurrent();
124 v8::HandleScope handle_scope(isolate); 125 v8::HandleScope handle_scope(isolate);
125 v8::Context::Scope context_scope(v8_context()); 126 v8::Context::Scope context_scope(v8_context());
126 127
127 ScriptContext* script_context = RegisterScriptContext(); 128 ScriptContext* script_context = RegisterScriptContext();
128 129
129 bool callback_invoked = false; 130 bool callback_invoked = false;
130 bool fallback_invoked = false; 131 bool fallback_invoked = false;
131 132
132 { 133 {
133 // Nest another HandleScope so that |object| and |unreachable_function|'s 134 // Nest another HandleScope so that |object| and |unreachable_function|'s
134 // handles will be garbage collected. 135 // handles will be garbage collected.
135 v8::HandleScope handle_scope(isolate); 136 v8::HandleScope handle_scope(isolate);
136 v8::Local<v8::Object> object = v8::Object::New(isolate); 137 v8::Local<v8::Object> object = v8::Object::New(isolate);
137 v8::Local<v8::FunctionTemplate> unreachable_function = 138 v8::Local<v8::FunctionTemplate> unreachable_function =
138 gin::CreateFunctionTemplate(isolate, 139 gin::CreateFunctionTemplate(isolate,
139 base::Bind(SetToTrue, &callback_invoked)); 140 base::Bind(SetToTrue, &callback_invoked));
140 // The GCCallback will delete itself, or memory tests will complain. 141 // The GCCallback will delete itself, or memory tests will complain.
141 new GCCallback(script_context, object, unreachable_function->GetFunction(), 142 new GCCallback(script_context, object, unreachable_function->GetFunction(),
142 base::Bind(SetToTrue, &fallback_invoked)); 143 base::Bind(SetToTrue, &fallback_invoked));
143 } 144 }
144 145
145 // Invalidate the context. Only the fallback should be invoked. 146 // Invalidate the context. Only the fallback should be invoked.
146 script_context_set().Remove(script_context); 147 script_context_set().Remove(script_context);
147 message_loop().RunUntilIdle(); 148 base::RunLoop().RunUntilIdle();
148 149
149 EXPECT_FALSE(callback_invoked); 150 EXPECT_FALSE(callback_invoked);
150 EXPECT_TRUE(fallback_invoked); 151 EXPECT_TRUE(fallback_invoked);
151 152
152 // 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
153 // already invoked. 154 // already invoked.
154 RequestGarbageCollection(); 155 RequestGarbageCollection();
155 message_loop().RunUntilIdle(); 156 base::RunLoop().RunUntilIdle();
156 157
157 EXPECT_FALSE(callback_invoked); 158 EXPECT_FALSE(callback_invoked);
158 } 159 }
159 160
160 } // namespace 161 } // namespace
161 } // namespace extensions 162 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/value_store/value_store_frontend_unittest.cc ('k') | extensions/renderer/script_context_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698