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

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

Issue 12225076: Delete most web intents code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 10 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
(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/WebSerializedScriptVa lue.h"
15 #include "webkit/glue/web_intent_data.h"
16
17 namespace content {
18
19 class WebIntentsHostTest : public RenderViewTest {
20 protected:
21 RenderViewImpl* view() { return static_cast<RenderViewImpl*>(view_); }
22 WebIntentsHost* web_intents_host() { return view()->intents_host_; }
23
24 void SetIntentData(const webkit_glue::WebIntentData& data) {
25 web_intents_host()->OnSetIntent(data);
26 }
27
28 base::DictionaryValue* ParseValueFromReply(const IPC::Message* reply_msg) {
29 IntentsHostMsg_WebIntentReply::Param reply_params;
30 IntentsHostMsg_WebIntentReply::Read(reply_msg, &reply_params);
31 WebKit::WebSerializedScriptValue serialized_data =
32 WebKit::WebSerializedScriptValue::fromString(reply_params.a.data);
33
34 v8::HandleScope scope;
35 v8::Local<v8::Context> ctx = GetMainFrame()->mainWorldScriptContext();
36 v8::Context::Scope cscope(ctx);
37 v8::Handle<v8::Value> v8_val = serialized_data.deserialize();
38 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
39 base::Value* reply = converter->FromV8Value(v8_val, ctx);
40 EXPECT_TRUE(reply->IsType(base::Value::TYPE_DICTIONARY));
41 base::DictionaryValue* dict = NULL;
42 reply->GetAsDictionary(&dict);
43 return dict;
44 }
45 };
46
47 TEST_F(WebIntentsHostTest, TestUnserialized) {
48 webkit_glue::WebIntentData data(ASCIIToUTF16("action"), ASCIIToUTF16("type"),
49 ASCIIToUTF16("unserialized data"));
50 SetIntentData(data);
51
52 LoadHTML("<html>"
53 "<head><script>\n"
54 "var d = {};\n"
55 "d.action = window.webkitIntent.action;\n"
56 "d.type = window.webkitIntent.type;\n"
57 "d.data = window.webkitIntent.data;\n"
58 "window.webkitIntent.postResult(d);\n"
59 "</script></head>"
60 "<body>body</body></html>");
61
62 const IPC::Message* reply_msg =
63 render_thread_->sink().GetUniqueMessageMatching(
64 IntentsHostMsg_WebIntentReply::ID);
65 ASSERT_TRUE(reply_msg);
66 scoped_ptr<base::DictionaryValue> dict(ParseValueFromReply(reply_msg));
67
68 std::string reply_action;
69 dict->GetStringASCII(std::string("action"), &reply_action);
70 EXPECT_EQ("action", reply_action);
71 std::string reply_type;
72 dict->GetStringASCII(std::string("type"), &reply_type);
73 EXPECT_EQ("type", reply_type);
74 std::string reply_data;
75 dict->GetStringASCII(std::string("data"), &reply_data);
76 EXPECT_EQ("unserialized data", reply_data);
77 }
78
79 TEST_F(WebIntentsHostTest, TestVector) {
80 webkit_glue::WebIntentData data(ASCIIToUTF16("action"), ASCIIToUTF16("type"));
81 DictionaryValue* d1 = new DictionaryValue;
82 d1->SetString(std::string("key1"), std::string("val1"));
83 data.mime_data.Append(d1);
84 DictionaryValue* d2 = new DictionaryValue;
85 d2->SetString(std::string("key2"), std::string("val2"));
86 data.mime_data.Append(d2);
87 SetIntentData(data);
88
89 LoadHTML("<html>"
90 "<head><script>\n"
91 "var d = {};\n"
92 "d.action = window.webkitIntent.action;\n"
93 "d.type = window.webkitIntent.type;\n"
94 "d.data = window.webkitIntent.data;\n"
95 "window.webkitIntent.postResult(d);\n"
96 "</script></head>"
97 "<body>body</body></html>");
98
99 const IPC::Message* reply_msg =
100 render_thread_->sink().GetUniqueMessageMatching(
101 IntentsHostMsg_WebIntentReply::ID);
102 ASSERT_TRUE(reply_msg);
103 scoped_ptr<base::DictionaryValue> dict(ParseValueFromReply(reply_msg));
104
105 base::ListValue* payload;
106 ASSERT_TRUE(dict->GetList("data", &payload));
107 EXPECT_EQ(2U, payload->GetSize());
108
109 base::DictionaryValue* v1 = NULL;
110 ASSERT_TRUE(payload->GetDictionary(0, &v1));
111 DCHECK(v1);
112 std::string val1;
113 ASSERT_TRUE(v1->GetStringASCII(std::string("key1"), &val1));
114 EXPECT_EQ("val1", val1);
115
116 base::DictionaryValue* v2 = NULL;
117 ASSERT_TRUE(payload->GetDictionary(1, &v2));
118 std::string val2;
119 v2->GetStringASCII(std::string("key2"), &val2);
120 EXPECT_EQ("val2", val2);
121 }
122
123 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698