| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gtest_prod_util.h" | 5 #include "base/gtest_prod_util.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "content/common/intents_messages.h" | 8 #include "content/common/intents_messages.h" |
| 9 #include "content/public/renderer/v8_value_converter.h" | 9 #include "content/public/renderer/v8_value_converter.h" |
| 10 #include "content/public/test/render_view_test.h" | 10 #include "content/public/test/render_view_test.h" |
| 11 #include "content/renderer/render_view_impl.h" | 11 #include "content/renderer/render_view_impl.h" |
| 12 #include "content/renderer/web_intents_host.h" | 12 #include "content/renderer/web_intents_host.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeliveredIntentCli
ent.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDeliveredIntentCli
ent.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" |
| 15 #include "webkit/glue/web_intent_data.h" | 15 #include "webkit/glue/web_intent_data.h" |
| 16 | 16 |
| 17 class WebIntentsHostTest : public content::RenderViewTest { | 17 namespace content { |
| 18 |
| 19 class WebIntentsHostTest : public RenderViewTest { |
| 18 protected: | 20 protected: |
| 19 RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); } | 21 RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); } |
| 20 WebIntentsHost* web_intents_host() { return view()->intents_host_; } | 22 WebIntentsHost* web_intents_host() { return view()->intents_host_; } |
| 21 | 23 |
| 22 void SetIntentData(const webkit_glue::WebIntentData& data) { | 24 void SetIntentData(const webkit_glue::WebIntentData& data) { |
| 23 web_intents_host()->OnSetIntent(data); | 25 web_intents_host()->OnSetIntent(data); |
| 24 } | 26 } |
| 25 | 27 |
| 26 base::DictionaryValue* ParseValueFromReply(const IPC::Message* reply_msg) { | 28 base::DictionaryValue* ParseValueFromReply(const IPC::Message* reply_msg) { |
| 27 IntentsHostMsg_WebIntentReply::Param reply_params; | 29 IntentsHostMsg_WebIntentReply::Param reply_params; |
| 28 IntentsHostMsg_WebIntentReply::Read(reply_msg, &reply_params); | 30 IntentsHostMsg_WebIntentReply::Read(reply_msg, &reply_params); |
| 29 WebKit::WebSerializedScriptValue serialized_data = | 31 WebKit::WebSerializedScriptValue serialized_data = |
| 30 WebKit::WebSerializedScriptValue::fromString(reply_params.a.data); | 32 WebKit::WebSerializedScriptValue::fromString(reply_params.a.data); |
| 31 | 33 |
| 32 v8::HandleScope scope; | 34 v8::HandleScope scope; |
| 33 v8::Local<v8::Context> ctx = GetMainFrame()->mainWorldScriptContext(); | 35 v8::Local<v8::Context> ctx = GetMainFrame()->mainWorldScriptContext(); |
| 34 v8::Context::Scope cscope(ctx); | 36 v8::Context::Scope cscope(ctx); |
| 35 v8::Handle<v8::Value> v8_val = serialized_data.deserialize(); | 37 v8::Handle<v8::Value> v8_val = serialized_data.deserialize(); |
| 36 scoped_ptr<content::V8ValueConverter> converter( | 38 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
| 37 content::V8ValueConverter::create()); | |
| 38 base::Value* reply = converter->FromV8Value(v8_val, ctx); | 39 base::Value* reply = converter->FromV8Value(v8_val, ctx); |
| 39 EXPECT_TRUE(reply->IsType(base::Value::TYPE_DICTIONARY)); | 40 EXPECT_TRUE(reply->IsType(base::Value::TYPE_DICTIONARY)); |
| 40 base::DictionaryValue* dict = NULL; | 41 base::DictionaryValue* dict = NULL; |
| 41 reply->GetAsDictionary(&dict); | 42 reply->GetAsDictionary(&dict); |
| 42 return dict; | 43 return dict; |
| 43 } | 44 } |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 TEST_F(WebIntentsHostTest, TestUnserialized) { | 47 TEST_F(WebIntentsHostTest, TestUnserialized) { |
| 47 webkit_glue::WebIntentData data(ASCIIToUTF16("action"), ASCIIToUTF16("type"), | 48 webkit_glue::WebIntentData data(ASCIIToUTF16("action"), ASCIIToUTF16("type"), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 std::string val1; | 112 std::string val1; |
| 112 ASSERT_TRUE(v1->GetStringASCII(std::string("key1"), &val1)); | 113 ASSERT_TRUE(v1->GetStringASCII(std::string("key1"), &val1)); |
| 113 EXPECT_EQ("val1", val1); | 114 EXPECT_EQ("val1", val1); |
| 114 | 115 |
| 115 base::DictionaryValue* v2 = NULL; | 116 base::DictionaryValue* v2 = NULL; |
| 116 ASSERT_TRUE(payload->GetDictionary(1, &v2)); | 117 ASSERT_TRUE(payload->GetDictionary(1, &v2)); |
| 117 std::string val2; | 118 std::string val2; |
| 118 v2->GetStringASCII(std::string("key2"), &val2); | 119 v2->GetStringASCII(std::string("key2"), &val2); |
| 119 EXPECT_EQ("val2", val2); | 120 EXPECT_EQ("val2", val2); |
| 120 } | 121 } |
| 122 |
| 123 } // namespace content |
| OLD | NEW |