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

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

Issue 983793003: Replace extensions::ScopedPersistent with v8::UniquePersistent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « extensions/extensions.gypi ('k') | extensions/renderer/app_window_custom_bindings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "extensions/renderer/activity_log_converter_strategy.h" 7 #include "extensions/renderer/activity_log_converter_strategy.h"
8 #include "extensions/renderer/scoped_persistent.h"
9 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
10 #include "v8/include/v8.h" 9 #include "v8/include/v8.h"
11 10
12 using content::V8ValueConverter; 11 using content::V8ValueConverter;
13 12
14 namespace extensions { 13 namespace extensions {
15 14
16 class ActivityLogConverterStrategyTest : public testing::Test { 15 class ActivityLogConverterStrategyTest : public testing::Test {
17 public: 16 public:
18 ActivityLogConverterStrategyTest() 17 ActivityLogConverterStrategyTest()
19 : isolate_(v8::Isolate::GetCurrent()) 18 : isolate_(v8::Isolate::GetCurrent()),
20 , handle_scope_(isolate_) 19 handle_scope_(isolate_),
21 , context_(v8::Context::New(isolate_)) 20 context_(isolate_, v8::Context::New(isolate_)),
22 , context_scope_(context()) { 21 context_scope_(context()) {}
23 }
24 22
25 protected: 23 protected:
26 void SetUp() override { 24 void SetUp() override {
27 converter_.reset(V8ValueConverter::create()); 25 converter_.reset(V8ValueConverter::create());
28 strategy_.reset(new ActivityLogConverterStrategy()); 26 strategy_.reset(new ActivityLogConverterStrategy());
29 converter_->SetFunctionAllowed(true); 27 converter_->SetFunctionAllowed(true);
30 converter_->SetStrategy(strategy_.get()); 28 converter_->SetStrategy(strategy_.get());
31 } 29 }
32 30
33 testing::AssertionResult VerifyNull(v8::Local<v8::Value> v8_value) { 31 testing::AssertionResult VerifyNull(v8::Local<v8::Value> v8_value) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 scoped_ptr<base::Value> value( 78 scoped_ptr<base::Value> value(
81 converter_->FromV8Value(v8_value, context())); 79 converter_->FromV8Value(v8_value, context()));
82 if (value->IsType(base::Value::TYPE_STRING) 80 if (value->IsType(base::Value::TYPE_STRING)
83 && value->GetAsString(&out) 81 && value->GetAsString(&out)
84 && out == expected) 82 && out == expected)
85 return testing::AssertionSuccess(); 83 return testing::AssertionSuccess();
86 return testing::AssertionFailure(); 84 return testing::AssertionFailure();
87 } 85 }
88 86
89 v8::Handle<v8::Context> context() const { 87 v8::Handle<v8::Context> context() const {
90 return context_.NewHandle(isolate_); 88 return v8::Local<v8::Context>::New(isolate_, context_);
91 } 89 }
92 90
93 v8::Isolate* isolate_; 91 v8::Isolate* isolate_;
94 v8::HandleScope handle_scope_; 92 v8::HandleScope handle_scope_;
95 ScopedPersistent<v8::Context> context_; 93 v8::UniquePersistent<v8::Context> context_;
96 v8::Context::Scope context_scope_; 94 v8::Context::Scope context_scope_;
97 scoped_ptr<V8ValueConverter> converter_; 95 scoped_ptr<V8ValueConverter> converter_;
98 scoped_ptr<ActivityLogConverterStrategy> strategy_; 96 scoped_ptr<ActivityLogConverterStrategy> strategy_;
99 }; 97 };
100 98
101 TEST_F(ActivityLogConverterStrategyTest, ConversionTest) { 99 TEST_F(ActivityLogConverterStrategyTest, ConversionTest) {
102 const char* source = "(function() {" 100 const char* source = "(function() {"
103 "function foo() {}" 101 "function foo() {}"
104 "return {" 102 "return {"
105 "null: null," 103 "null: null,"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 "[Array]")); 161 "[Array]"));
164 EXPECT_TRUE(VerifyString( 162 EXPECT_TRUE(VerifyString(
165 v8_object->Get(v8::String::NewFromUtf8(isolate_, "function")), 163 v8_object->Get(v8::String::NewFromUtf8(isolate_, "function")),
166 "[Function]")); 164 "[Function]"));
167 EXPECT_TRUE(VerifyString( 165 EXPECT_TRUE(VerifyString(
168 v8_object->Get(v8::String::NewFromUtf8(isolate_, "named_function")), 166 v8_object->Get(v8::String::NewFromUtf8(isolate_, "named_function")),
169 "[Function foo()]")); 167 "[Function foo()]"));
170 } 168 }
171 169
172 } // namespace extensions 170 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/extensions.gypi ('k') | extensions/renderer/app_window_custom_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698