| 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 "extensions/renderer/activity_log_converter_strategy.h" | 5 #include "extensions/renderer/activity_log_converter_strategy.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "v8/include/v8.h" | 11 #include "v8/include/v8.h" |
| 12 | 12 |
| 13 using content::V8ValueConverter; | |
| 14 | |
| 15 namespace extensions { | 13 namespace extensions { |
| 16 | 14 |
| 17 class ActivityLogConverterStrategyTest : public testing::Test { | 15 class ActivityLogConverterStrategyTest : public testing::Test { |
| 18 public: | 16 public: |
| 19 ActivityLogConverterStrategyTest() | 17 ActivityLogConverterStrategyTest() |
| 20 : isolate_(v8::Isolate::GetCurrent()), | 18 : isolate_(v8::Isolate::GetCurrent()), |
| 21 handle_scope_(isolate_), | 19 handle_scope_(isolate_), |
| 22 context_(isolate_, v8::Context::New(isolate_)), | 20 context_(isolate_, v8::Context::New(isolate_)), |
| 23 context_scope_(context()) {} | 21 context_scope_(context()) {} |
| 24 | 22 |
| 25 protected: | 23 protected: |
| 26 void SetUp() override { | 24 void SetUp() override { |
| 27 converter_.reset(V8ValueConverter::create()); | 25 converter_ = content::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) { |
| 34 std::unique_ptr<base::Value> value( | 32 std::unique_ptr<base::Value> value( |
| 35 converter_->FromV8Value(v8_value, context())); | 33 converter_->FromV8Value(v8_value, context())); |
| 36 if (value->IsType(base::Value::Type::NONE)) | 34 if (value->IsType(base::Value::Type::NONE)) |
| 37 return testing::AssertionSuccess(); | 35 return testing::AssertionSuccess(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 85 } |
| 88 | 86 |
| 89 v8::Local<v8::Context> context() const { | 87 v8::Local<v8::Context> context() const { |
| 90 return v8::Local<v8::Context>::New(isolate_, context_); | 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 v8::Global<v8::Context> context_; | 93 v8::Global<v8::Context> context_; |
| 96 v8::Context::Scope context_scope_; | 94 v8::Context::Scope context_scope_; |
| 97 std::unique_ptr<V8ValueConverter> converter_; | 95 std::unique_ptr<content::V8ValueConverter> converter_; |
| 98 std::unique_ptr<ActivityLogConverterStrategy> strategy_; | 96 std::unique_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," |
| 106 "true: true," | 104 "true: true," |
| 107 "false: false," | 105 "false: false," |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 "[Array]")); | 163 "[Array]")); |
| 166 EXPECT_TRUE(VerifyString( | 164 EXPECT_TRUE(VerifyString( |
| 167 v8_object->Get(v8::String::NewFromUtf8(isolate_, "function")), | 165 v8_object->Get(v8::String::NewFromUtf8(isolate_, "function")), |
| 168 "[Function]")); | 166 "[Function]")); |
| 169 EXPECT_TRUE(VerifyString( | 167 EXPECT_TRUE(VerifyString( |
| 170 v8_object->Get(v8::String::NewFromUtf8(isolate_, "named_function")), | 168 v8_object->Get(v8::String::NewFromUtf8(isolate_, "named_function")), |
| 171 "[Function foo()]")); | 169 "[Function foo()]")); |
| 172 } | 170 } |
| 173 | 171 |
| 174 } // namespace extensions | 172 } // namespace extensions |
| OLD | NEW |