| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "extensions/common/extension.h" | 8 #include "extensions/common/extension.h" |
| 9 #include "extensions/common/extension_set.h" | 9 #include "extensions/common/extension_set.h" |
| 10 #include "extensions/common/features/feature.h" | 10 #include "extensions/common/features/feature.h" |
| 11 #include "extensions/renderer/script_context.h" | 11 #include "extensions/renderer/script_context.h" |
| 12 #include "extensions/renderer/script_context_set.h" | 12 #include "extensions/renderer/script_context_set.h" |
| 13 #include "gin/public/context_holder.h" | 13 #include "gin/public/context_holder.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 16 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
| 17 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
| 18 | 18 |
| 19 namespace extensions { | 19 namespace extensions { |
| 20 | 20 |
| 21 TEST(ScriptContextSetTest, Lifecycle) { | 21 TEST(ScriptContextSetTest, Lifecycle) { |
| 22 base::MessageLoop loop; | 22 base::MessageLoop loop; |
| 23 | 23 |
| 24 blink::WebView* webview = blink::WebView::create(nullptr); | 24 blink::WebView* webview = blink::WebView::create(nullptr); |
| 25 blink::WebLocalFrame* frame = blink::WebLocalFrame::create(nullptr); | 25 blink::WebLocalFrame* frame = |
| 26 blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, nullptr); |
| 26 webview->setMainFrame(frame); | 27 webview->setMainFrame(frame); |
| 27 | 28 |
| 28 // Do this after construction of the webview, since it may construct the | 29 // Do this after construction of the webview, since it may construct the |
| 29 // Isolate. | 30 // Isolate. |
| 30 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 31 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 31 | 32 |
| 32 v8::HandleScope handle_scope(isolate); | 33 v8::HandleScope handle_scope(isolate); |
| 33 v8::Local<v8::Context> v8_context = v8::Context::New(isolate); | 34 v8::Local<v8::Context> v8_context = v8::Context::New(isolate); |
| 34 v8::Context::Scope context_scope(v8_context); | 35 v8::Context::Scope context_scope(v8_context); |
| 35 // ScriptContext relies on gin, it just doesn't look like it from here. | 36 // ScriptContext relies on gin, it just doesn't look like it from here. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 57 EXPECT_EQ(nullptr, context_set.GetByV8Context(v8_context)); | 58 EXPECT_EQ(nullptr, context_set.GetByV8Context(v8_context)); |
| 58 | 59 |
| 59 // After removal, the context should be marked for destruction. | 60 // After removal, the context should be marked for destruction. |
| 60 EXPECT_FALSE(context->is_valid()); | 61 EXPECT_FALSE(context->is_valid()); |
| 61 | 62 |
| 62 // Run loop to do the actual deletion. | 63 // Run loop to do the actual deletion. |
| 63 loop.RunUntilIdle(); | 64 loop.RunUntilIdle(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 } // namespace extensions | 67 } // namespace extensions |
| OLD | NEW |