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

Side by Side Diff: content/renderer/web_intents_host_browsertest.cc

Issue 11026070: Add API to construct new vector interchange MIME data type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve comment Created 8 years, 2 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
« no previous file with comments | « content/renderer/web_intents_host.cc ('k') | webkit/glue/web_intent_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/gtest_prod_util.h"
6 #include "base/values.h"
7 #include "base/utf_string_conversions.h"
8 #include "content/common/intents_messages.h"
9 #include "content/public/renderer/v8_value_converter.h"
10 #include "content/public/test/render_view_test.h"
11 #include "content/renderer/render_view_impl.h"
12 #include "content/renderer/web_intents_host.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"
15 #include "webkit/glue/web_intent_data.h"
16
17 class WebIntentsHostTest : public content::RenderViewTest {
18 protected:
19 RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); }
20 WebIntentsHost* web_intents_host() { return view()->intents_host_; }
21
22 void SetIntentData(const webkit_glue::WebIntentData& data) {
23 web_intents_host()->OnSetIntent(data);
24 }
25
26 base::DictionaryValue* ParseValueFromReply(const IPC::Message* reply_msg) {
27 IntentsHostMsg_WebIntentReply::Param reply_params;
28 IntentsHostMsg_WebIntentReply::Read(reply_msg, &reply_params);
29 WebKit::WebSerializedScriptValue serialized_data =
30 WebKit::WebSerializedScriptValue::fromString(reply_params.b);
31
32 v8::HandleScope scope;
33 v8::Local<v8::Context> ctx = GetMainFrame()->mainWorldScriptContext();
34 v8::Context::Scope cscope(ctx);
35 v8::Handle<v8::Value> v8_val = serialized_data.deserialize();
36 scoped_ptr<content::V8ValueConverter> converter(
37 content::V8ValueConverter::create());
38 base::Value* reply = converter->FromV8Value(v8_val, ctx);
39 EXPECT_TRUE(reply->IsType(base::Value::TYPE_DICTIONARY));
40 base::DictionaryValue* dict = NULL;
41 reply->GetAsDictionary(&dict);
42 return dict;
43 }
44 };
45
46 TEST_F(WebIntentsHostTest, TestUnserialized) {
47 webkit_glue::WebIntentData data(ASCIIToUTF16("action"), ASCIIToUTF16("type"),
48 ASCIIToUTF16("unserialized data"));
49 SetIntentData(data);
50
51 LoadHTML("<html>"
52 "<head><script>\n"
53 "var d = {};\n"
54 "d.action = window.webkitIntent.action;\n"
55 "d.type = window.webkitIntent.type;\n"
56 "d.data = window.webkitIntent.data;\n"
57 "window.webkitIntent.postResult(d);\n"
58 "</script></head>"
59 "<body>body</body></html>");
60
61 const IPC::Message* reply_msg =
62 render_thread_->sink().GetUniqueMessageMatching(
63 IntentsHostMsg_WebIntentReply::ID);
64 ASSERT_TRUE(reply_msg);
65 scoped_ptr<base::DictionaryValue> dict(ParseValueFromReply(reply_msg));
66
67 std::string reply_action;
68 dict->GetStringASCII(std::string("action"), &reply_action);
69 EXPECT_EQ("action", reply_action);
70 std::string reply_type;
71 dict->GetStringASCII(std::string("type"), &reply_type);
72 EXPECT_EQ("type", reply_type);
73 std::string reply_data;
74 dict->GetStringASCII(std::string("data"), &reply_data);
75 EXPECT_EQ("unserialized data", reply_data);
76 }
77
78 TEST_F(WebIntentsHostTest, TestVector) {
79 webkit_glue::WebIntentData data(ASCIIToUTF16("action"), ASCIIToUTF16("type"));
80 DictionaryValue* d1 = new DictionaryValue;
81 d1->SetString(std::string("key1"), std::string("val1"));
82 data.mime_data.Append(d1);
83 DictionaryValue* d2 = new DictionaryValue;
84 d2->SetString(std::string("key2"), std::string("val2"));
85 data.mime_data.Append(d2);
86 SetIntentData(data);
87
88 LoadHTML("<html>"
89 "<head><script>\n"
90 "var d = {};\n"
91 "d.action = window.webkitIntent.action;\n"
92 "d.type = window.webkitIntent.type;\n"
93 "d.data = window.webkitIntent.data;\n"
94 "window.webkitIntent.postResult(d);\n"
95 "</script></head>"
96 "<body>body</body></html>");
97
98 const IPC::Message* reply_msg =
99 render_thread_->sink().GetUniqueMessageMatching(
100 IntentsHostMsg_WebIntentReply::ID);
101 ASSERT_TRUE(reply_msg);
102 scoped_ptr<base::DictionaryValue> dict(ParseValueFromReply(reply_msg));
103
104 base::ListValue* payload;
105 ASSERT_TRUE(dict->GetList("data", &payload));
106 EXPECT_EQ(2U, payload->GetSize());
107
108 base::DictionaryValue* v1 = NULL;
109 ASSERT_TRUE(payload->GetDictionary(0, &v1));
110 DCHECK(v1);
111 std::string val1;
112 ASSERT_TRUE(v1->GetStringASCII(std::string("key1"), &val1));
113 EXPECT_EQ("val1", val1);
114
115 base::DictionaryValue* v2 = NULL;
116 ASSERT_TRUE(payload->GetDictionary(1, &v2));
117 std::string val2;
118 v2->GetStringASCII(std::string("key2"), &val2);
119 EXPECT_EQ("val2", val2);
120 }
OLDNEW
« no previous file with comments | « content/renderer/web_intents_host.cc ('k') | webkit/glue/web_intent_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698