| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "content/public/common/content_switches.h" | 6 #include "content/public/common/content_switches.h" |
| 7 #include "content/public/test/render_view_test.h" | 7 #include "content/public/test/render_view_test.h" |
| 8 #include "content/renderer/render_view_impl.h" | 8 #include "content/renderer/render_view_impl.h" |
| 9 #include "gin/handle.h" | 9 #include "gin/handle.h" |
| 10 #include "gin/object_template_builder.h" |
| 10 #include "gin/per_isolate_data.h" | 11 #include "gin/per_isolate_data.h" |
| 11 #include "gin/wrappable.h" | 12 #include "gin/wrappable.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/web/WebFrame.h" | 14 #include "third_party/WebKit/public/web/WebFrame.h" |
| 14 #include "third_party/WebKit/public/web/WebKit.h" | 15 #include "third_party/WebKit/public/web/WebKit.h" |
| 15 #include "third_party/WebKit/public/web/WebView.h" | 16 #include "third_party/WebKit/public/web/WebView.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class TestGinObject : public gin::Wrappable<TestGinObject> { | 22 class TestGinObject : public gin::Wrappable<TestGinObject> { |
| 22 public: | 23 public: |
| 23 static gin::WrapperInfo kWrapperInfo; | 24 static gin::WrapperInfo kWrapperInfo; |
| 24 | 25 |
| 25 static gin::Handle<TestGinObject> Create(v8::Isolate* isolate, bool* alive) { | 26 static gin::Handle<TestGinObject> Create(v8::Isolate* isolate, bool* alive) { |
| 26 return gin::CreateHandle(isolate, new TestGinObject(alive)); | 27 return gin::CreateHandle(isolate, new TestGinObject(alive)); |
| 27 } | 28 } |
| 28 | 29 |
| 29 private: | 30 private: |
| 31 friend class gin::Wrappable<TestGinObject>; |
| 32 static v8::Local<v8::ObjectTemplate> GetObjectTemplate(v8::Isolate* isolate) { |
| 33 return gin::ObjectTemplateBuilder(isolate).Build(); |
| 34 } |
| 35 |
| 30 TestGinObject(bool* alive) : alive_(alive) { *alive_ = true; } | 36 TestGinObject(bool* alive) : alive_(alive) { *alive_ = true; } |
| 31 virtual ~TestGinObject() { *alive_ = false; } | 37 virtual ~TestGinObject() { *alive_ = false; } |
| 32 | 38 |
| 33 bool* alive_; | 39 bool* alive_; |
| 34 | 40 |
| 35 DISALLOW_COPY_AND_ASSIGN(TestGinObject); | 41 DISALLOW_COPY_AND_ASSIGN(TestGinObject); |
| 36 }; | 42 }; |
| 37 | 43 |
| 38 gin::WrapperInfo TestGinObject::kWrapperInfo = { gin::kEmbedderNativeGin }; | 44 gin::WrapperInfo TestGinObject::kWrapperInfo = { gin::kEmbedderNativeGin }; |
| 39 | 45 |
| 40 void RegisterTemplates(v8::Isolate* isolate) { | |
| 41 gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | |
| 42 | |
| 43 v8::Handle<v8::ObjectTemplate> templ = v8::ObjectTemplate::New(isolate); | |
| 44 templ->SetInternalFieldCount(gin::kNumberOfInternalFields); | |
| 45 data->SetObjectTemplate(&TestGinObject::kWrapperInfo, templ); | |
| 46 } | |
| 47 | |
| 48 class GinBrowserTest : public RenderViewTest { | 46 class GinBrowserTest : public RenderViewTest { |
| 49 public: | 47 public: |
| 50 GinBrowserTest() {} | 48 GinBrowserTest() {} |
| 51 virtual ~GinBrowserTest() {} | 49 virtual ~GinBrowserTest() {} |
| 52 | 50 |
| 53 virtual void SetUp() OVERRIDE { | 51 virtual void SetUp() OVERRIDE { |
| 54 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 52 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 55 switches::kJavaScriptFlags, "--expose_gc"); | 53 switches::kJavaScriptFlags, "--expose_gc"); |
| 56 | 54 |
| 57 RenderViewTest::SetUp(); | 55 RenderViewTest::SetUp(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 68 LoadHTML("<!doctype html>"); | 66 LoadHTML("<!doctype html>"); |
| 69 | 67 |
| 70 bool alive = false; | 68 bool alive = false; |
| 71 | 69 |
| 72 { | 70 { |
| 73 v8::Isolate* isolate = blink::mainThreadIsolate(); | 71 v8::Isolate* isolate = blink::mainThreadIsolate(); |
| 74 v8::HandleScope handle_scope(isolate); | 72 v8::HandleScope handle_scope(isolate); |
| 75 v8::Context::Scope context_scope( | 73 v8::Context::Scope context_scope( |
| 76 view_->GetWebView()->mainFrame()->mainWorldScriptContext()); | 74 view_->GetWebView()->mainFrame()->mainWorldScriptContext()); |
| 77 | 75 |
| 78 RegisterTemplates(isolate); | |
| 79 | |
| 80 // We create the object inside a scope so it's not kept alive by a handle | 76 // We create the object inside a scope so it's not kept alive by a handle |
| 81 // on the stack. | 77 // on the stack. |
| 82 TestGinObject::Create(isolate, &alive); | 78 TestGinObject::Create(isolate, &alive); |
| 83 } | 79 } |
| 84 | 80 |
| 85 CHECK(alive); | 81 CHECK(alive); |
| 86 | 82 |
| 87 // Should not crash. | 83 // Should not crash. |
| 88 v8::V8::LowMemoryNotification(); | 84 v8::V8::LowMemoryNotification(); |
| 89 | 85 |
| 90 CHECK(!alive); | 86 CHECK(!alive); |
| 91 } | 87 } |
| 92 | 88 |
| 93 } // namespace | 89 } // namespace |
| 94 | 90 |
| 95 } // namespace content | 91 } // namespace content |
| OLD | NEW |