Broke ContentSettingBubbleModelTest.Plugins on Android.
[chromium-blink-merge.git] / content / browser / intents / internal_web_intents_dispatcher_unittest.cc
blob134903f29f0f25e3622124b1755d79f744b01714
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.
5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/utf_string_conversions.h"
8 #include "content/browser/intents/intent_injector.h"
9 #include "content/browser/intents/internal_web_intents_dispatcher.h"
10 #include "content/browser/renderer_host/test_render_view_host.h"
11 #include "content/browser/web_contents/test_web_contents.h"
12 #include "webkit/glue/web_intent_data.h"
13 #include "webkit/glue/web_intent_reply_data.h"
15 namespace content {
17 class InternalWebIntentsDispatcherTest : public RenderViewHostTestHarness {
18 public:
19 InternalWebIntentsDispatcherTest() : reply_count_(0) {
22 ~InternalWebIntentsDispatcherTest() {}
24 void NotifyReply(const webkit_glue::WebIntentReply& reply) {
25 reply_.reset(new webkit_glue::WebIntentReply(reply));
28 void ReplySent(webkit_glue::WebIntentReplyType reply_type) {
29 reply_count_++;
32 int reply_count_;
33 scoped_ptr<const webkit_glue::WebIntentReply> reply_;
36 // Tests that the internal dispatcher correctly notifies
37 // its callbacks of any reply messages.
38 TEST_F(InternalWebIntentsDispatcherTest, NotifiesOnReply) {
39 webkit_glue::WebIntentData intent(ASCIIToUTF16("action"),
40 ASCIIToUTF16("type"),
41 ASCIIToUTF16("unserialized_data"));
42 InternalWebIntentsDispatcher* dispatcher = new InternalWebIntentsDispatcher(
43 intent, base::Bind(&InternalWebIntentsDispatcherTest::NotifyReply,
44 base::Unretained(this)));
45 dispatcher->RegisterReplyNotification(
46 base::Bind(&InternalWebIntentsDispatcherTest::ReplySent,
47 base::Unretained(this)));
49 dispatcher->DispatchIntent(web_contents());
51 webkit_glue::WebIntentReply reply(
52 webkit_glue::WEB_INTENT_REPLY_SUCCESS, ASCIIToUTF16("success"));
53 dispatcher->SendReply(reply);
55 ASSERT_TRUE(1 == reply_count_);
56 ASSERT_TRUE(reply_);
57 EXPECT_EQ(*reply_.get(), reply);
60 TEST_F(InternalWebIntentsDispatcherTest, CancelAbandonsInjector) {
61 webkit_glue::WebIntentData intent(ASCIIToUTF16("action"),
62 ASCIIToUTF16("type"),
63 ASCIIToUTF16("unserialized_data"));
64 InternalWebIntentsDispatcher* dispatcher = new InternalWebIntentsDispatcher(
65 intent, base::Bind(&InternalWebIntentsDispatcherTest::NotifyReply,
66 base::Unretained(this)));
67 dispatcher->DispatchIntent(web_contents());
68 EXPECT_FALSE(dispatcher->intent_injector_ == NULL);
69 dispatcher->ResetDispatch();
70 EXPECT_TRUE(dispatcher->intent_injector_ == NULL);
72 dispatcher->SendReply(webkit_glue::WebIntentReply(
73 webkit_glue::WEB_INTENT_REPLY_SUCCESS, ASCIIToUTF16("success")));
76 } // namespace content