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

Side by Side Diff: chrome/renderer/extensions/activity_log_converter_strategy_unittest.cc

Issue 23636015: Remove unsafe access hacks from ScopedPersistent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "chrome/renderer/extensions/activity_log_converter_strategy.h" 7 #include "chrome/renderer/extensions/activity_log_converter_strategy.h"
8 #include "chrome/renderer/extensions/scoped_persistent.h" 8 #include "chrome/renderer/extensions/scoped_persistent.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "v8/include/v8.h" 10 #include "v8/include/v8.h"
11 11
12 using content::V8ValueConverter; 12 using content::V8ValueConverter;
13 13
14 namespace extensions { 14 namespace extensions {
15 15
16 class ActivityLogConverterStrategyTest : public testing::Test { 16 class ActivityLogConverterStrategyTest : public testing::Test {
17 public: 17 public:
18 ActivityLogConverterStrategyTest() 18 ActivityLogConverterStrategyTest()
19 : isolate_(v8::Isolate::GetCurrent()) 19 : isolate_(v8::Isolate::GetCurrent())
20 , handle_scope_(isolate_) 20 , handle_scope_(isolate_)
21 , context_(v8::Context::New(isolate_)) 21 , context_(v8::Context::New(isolate_))
22 , context_scope_(context_.get()) { 22 , context_scope_(context_.NewHandle(isolate_)) {
23 } 23 }
24 24
25 protected: 25 protected:
26 virtual void SetUp() { 26 virtual void SetUp() {
27 converter_.reset(V8ValueConverter::create()); 27 converter_.reset(V8ValueConverter::create());
28 strategy_.reset(new ActivityLogConverterStrategy()); 28 strategy_.reset(new ActivityLogConverterStrategy());
29 converter_->SetFunctionAllowed(true); 29 converter_->SetFunctionAllowed(true);
30 converter_->SetStrategy(strategy_.get()); 30 converter_->SetStrategy(strategy_.get());
31 } 31 }
32 32
33 testing::AssertionResult VerifyNull(v8::Local<v8::Value> v8_value) { 33 testing::AssertionResult VerifyNull(v8::Local<v8::Value> v8_value) {
34 scoped_ptr<base::Value> value( 34 scoped_ptr<base::Value> value(
35 converter_->FromV8Value(v8_value, context_.get())); 35 converter_->FromV8Value(v8_value,
36 context_.NewHandle(v8::Isolate::GetCurrent())));
Jeffrey Yasskin 2013/09/09 17:45:07 Could you add a method "context()" or "context_han
marja 2013/09/09 18:16:18 Done (though, I noticed there is also isolate_ so
36 if (value->IsType(base::Value::TYPE_NULL)) 37 if (value->IsType(base::Value::TYPE_NULL))
37 return testing::AssertionSuccess(); 38 return testing::AssertionSuccess();
38 return testing::AssertionFailure(); 39 return testing::AssertionFailure();
39 } 40 }
40 41
41 testing::AssertionResult VerifyBoolean(v8::Local<v8::Value> v8_value, 42 testing::AssertionResult VerifyBoolean(v8::Local<v8::Value> v8_value,
42 bool expected) { 43 bool expected) {
43 bool out; 44 bool out;
44 scoped_ptr<base::Value> value( 45 scoped_ptr<base::Value> value(
45 converter_->FromV8Value(v8_value, context_.get())); 46 converter_->FromV8Value(v8_value,
47 context_.NewHandle(v8::Isolate::GetCurrent())));
46 if (value->IsType(base::Value::TYPE_BOOLEAN) 48 if (value->IsType(base::Value::TYPE_BOOLEAN)
47 && value->GetAsBoolean(&out) 49 && value->GetAsBoolean(&out)
48 && out == expected) 50 && out == expected)
49 return testing::AssertionSuccess(); 51 return testing::AssertionSuccess();
50 return testing::AssertionFailure(); 52 return testing::AssertionFailure();
51 } 53 }
52 54
53 testing::AssertionResult VerifyInteger(v8::Local<v8::Value> v8_value, 55 testing::AssertionResult VerifyInteger(v8::Local<v8::Value> v8_value,
54 int expected) { 56 int expected) {
55 int out; 57 int out;
56 scoped_ptr<base::Value> value( 58 scoped_ptr<base::Value> value(
57 converter_->FromV8Value(v8_value, context_.get())); 59 converter_->FromV8Value(v8_value,
60 context_.NewHandle(v8::Isolate::GetCurrent())));
58 if (value->IsType(base::Value::TYPE_INTEGER) 61 if (value->IsType(base::Value::TYPE_INTEGER)
59 && value->GetAsInteger(&out) 62 && value->GetAsInteger(&out)
60 && out == expected) 63 && out == expected)
61 return testing::AssertionSuccess(); 64 return testing::AssertionSuccess();
62 return testing::AssertionFailure(); 65 return testing::AssertionFailure();
63 } 66 }
64 67
65 testing::AssertionResult VerifyDouble(v8::Local<v8::Value> v8_value, 68 testing::AssertionResult VerifyDouble(v8::Local<v8::Value> v8_value,
66 double expected) { 69 double expected) {
67 double out; 70 double out;
68 scoped_ptr<base::Value> value( 71 scoped_ptr<base::Value> value(
69 converter_->FromV8Value(v8_value, context_.get())); 72 converter_->FromV8Value(v8_value,
73 context_.NewHandle(v8::Isolate::GetCurrent())));
70 if (value->IsType(base::Value::TYPE_DOUBLE) 74 if (value->IsType(base::Value::TYPE_DOUBLE)
71 && value->GetAsDouble(&out) 75 && value->GetAsDouble(&out)
72 && out == expected) 76 && out == expected)
73 return testing::AssertionSuccess(); 77 return testing::AssertionSuccess();
74 return testing::AssertionFailure(); 78 return testing::AssertionFailure();
75 } 79 }
76 80
77 testing::AssertionResult VerifyString(v8::Local<v8::Value> v8_value, 81 testing::AssertionResult VerifyString(v8::Local<v8::Value> v8_value,
78 const std::string& expected) { 82 const std::string& expected) {
79 std::string out; 83 std::string out;
80 scoped_ptr<base::Value> value( 84 scoped_ptr<base::Value> value(
81 converter_->FromV8Value(v8_value, context_.get())); 85 converter_->FromV8Value(v8_value,
86 context_.NewHandle(v8::Isolate::GetCurrent())));
82 if (value->IsType(base::Value::TYPE_STRING) 87 if (value->IsType(base::Value::TYPE_STRING)
83 && value->GetAsString(&out) 88 && value->GetAsString(&out)
84 && out == expected) 89 && out == expected)
85 return testing::AssertionSuccess(); 90 return testing::AssertionSuccess();
86 return testing::AssertionFailure(); 91 return testing::AssertionFailure();
87 } 92 }
88 93
89 v8::Isolate* isolate_; 94 v8::Isolate* isolate_;
90 v8::HandleScope handle_scope_; 95 v8::HandleScope handle_scope_;
91 ScopedPersistent<v8::Context> context_; 96 ScopedPersistent<v8::Context> context_;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 "[Array]")); 153 "[Array]"));
149 EXPECT_TRUE(VerifyString(v8_object->Get(v8::String::New("empty_list")), 154 EXPECT_TRUE(VerifyString(v8_object->Get(v8::String::New("empty_list")),
150 "[Array]")); 155 "[Array]"));
151 EXPECT_TRUE(VerifyString(v8_object->Get(v8::String::New("function")), 156 EXPECT_TRUE(VerifyString(v8_object->Get(v8::String::New("function")),
152 "[Function]")); 157 "[Function]"));
153 EXPECT_TRUE(VerifyString(v8_object->Get(v8::String::New("named_function")), 158 EXPECT_TRUE(VerifyString(v8_object->Get(v8::String::New("named_function")),
154 "[Function foo()]")); 159 "[Function foo()]"));
155 } 160 }
156 161
157 } // namespace extensions 162 } // namespace extensions
158
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/extensions/chrome_v8_context.h » ('j') | chrome/renderer/extensions/scoped_persistent.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698