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

Side by Side Diff: gin/wrappable_unittest.cc

Issue 116163008: Move the plugin placeholder from CppBoundClass to gin::Wrappable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: counter-proposal Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/logging.h" 5 #include "base/logging.h"
6 #include "gin/arguments.h" 6 #include "gin/arguments.h"
7 #include "gin/handle.h" 7 #include "gin/handle.h"
8 #include "gin/object_template_builder.h" 8 #include "gin/object_template_builder.h"
9 #include "gin/per_isolate_data.h" 9 #include "gin/per_isolate_data.h"
10 #include "gin/public/isolate_holder.h" 10 #include "gin/public/isolate_holder.h"
11 #include "gin/test/v8_test.h" 11 #include "gin/test/v8_test.h"
12 #include "gin/try_catch.h" 12 #include "gin/try_catch.h"
13 #include "gin/wrappable.h" 13 #include "gin/wrappable.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace gin { 16 namespace gin {
17 17
18 class MyObject : public Wrappable<MyObject> { 18 class MyObject : public Wrappable<MyObject> {
19 public: 19 public:
20 static WrapperInfo kWrapperInfo; 20 static WrapperInfo kWrapperInfo;
21 21
22 static v8::Local<v8::ObjectTemplate> GetObjectTemplate(v8::Isolate* isolate);
23
24 static gin::Handle<MyObject> Create(v8::Isolate* isolate) { 22 static gin::Handle<MyObject> Create(v8::Isolate* isolate) {
25 return CreateHandle(isolate, new MyObject()); 23 return CreateHandle(isolate, new MyObject());
26 } 24 }
27 25
28 int value() const { return value_; } 26 int value() const { return value_; }
29 void set_value(int value) { value_ = value; } 27 void set_value(int value) { value_ = value; }
30 28
31 private: 29 private:
30 virtual ObjectTemplateBuilder GetObjectTemplateBuilder(
31 v8::Isolate* isolate) OVERRIDE;
32
32 MyObject() : value_(0) {} 33 MyObject() : value_(0) {}
33 virtual ~MyObject() {} 34 virtual ~MyObject() {}
34 35
35 int value_; 36 int value_;
36 }; 37 };
37 38
38 class MyObject2 : public Wrappable<MyObject2> { 39 class MyObject2 : public Wrappable<MyObject2> {
39 public: 40 public:
40 static WrapperInfo kWrapperInfo; 41 static WrapperInfo kWrapperInfo;
41 }; 42 };
42 43
43 class MyObjectBlink : public Wrappable<MyObjectBlink> { 44 class MyObjectBlink : public Wrappable<MyObjectBlink> {
44 public: 45 public:
45 static WrapperInfo kWrapperInfo; 46 static WrapperInfo kWrapperInfo;
46 }; 47 };
47 48
48 WrapperInfo MyObject::kWrapperInfo = { kEmbedderNativeGin }; 49 WrapperInfo MyObject::kWrapperInfo = { kEmbedderNativeGin };
49 v8::Local<v8::ObjectTemplate> MyObject::GetObjectTemplate( 50 ObjectTemplateBuilder MyObject::GetObjectTemplateBuilder(v8::Isolate* isolate) {
50 v8::Isolate* isolate) { 51 return Wrappable<MyObject>::GetObjectTemplateBuilder(isolate)
51 return ObjectTemplateBuilder(isolate) 52 .SetProperty("value", &MyObject::value, &MyObject::set_value);
52 .SetProperty("value", &MyObject::value, &MyObject::set_value)
53 .Build();
54 } 53 }
55 54
56 WrapperInfo MyObject2::kWrapperInfo = { kEmbedderNativeGin }; 55 WrapperInfo MyObject2::kWrapperInfo = { kEmbedderNativeGin };
57 WrapperInfo MyObjectBlink::kWrapperInfo = { kEmbedderNativeGin }; 56 WrapperInfo MyObjectBlink::kWrapperInfo = { kEmbedderNativeGin };
58 57
59 typedef V8Test WrappableTest; 58 typedef V8Test WrappableTest;
60 59
61 TEST_F(WrappableTest, WrapAndUnwrap) { 60 TEST_F(WrappableTest, WrapAndUnwrap) {
62 v8::Isolate* isolate = instance_->isolate(); 61 v8::Isolate* isolate = instance_->isolate();
63 v8::HandleScope handle_scope(isolate); 62 v8::HandleScope handle_scope(isolate);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ConvertToV8(isolate, obj.get()), 125 ConvertToV8(isolate, obj.get()),
127 }; 126 };
128 func->Call(v8::Undefined(isolate), 1, argv); 127 func->Call(v8::Undefined(isolate), 1, argv);
129 EXPECT_FALSE(try_catch.HasCaught()); 128 EXPECT_FALSE(try_catch.HasCaught());
130 EXPECT_EQ("", try_catch.GetStackTrace()); 129 EXPECT_EQ("", try_catch.GetStackTrace());
131 130
132 EXPECT_EQ(191, obj->value()); 131 EXPECT_EQ(191, obj->value());
133 } 132 }
134 133
135 } // namespace gin 134 } // namespace gin
OLDNEW
« gin/wrappable.cc ('K') | « gin/wrappable.cc ('k') | mojo/apps/js/bindings/gl/context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698