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

Side by Side Diff: chrome/browser/extensions/extension_messages_apitest.cc

Issue 11440004: Remove deprecated extension EventRouter APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 8 years 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
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/values.h" 5 #include "base/values.h"
6 #include "chrome/browser/extensions/event_router.h" 6 #include "chrome/browser/extensions/event_router.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_system.h" 8 #include "chrome/browser/extensions/extension_system.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
(...skipping 15 matching lines...) Expand all
26 static scoped_ptr<ListValue> BuildEventArguments(const bool last_message, 26 static scoped_ptr<ListValue> BuildEventArguments(const bool last_message,
27 const std::string& data) { 27 const std::string& data) {
28 DictionaryValue* event = new DictionaryValue(); 28 DictionaryValue* event = new DictionaryValue();
29 event->SetBoolean("lastMessage", last_message); 29 event->SetBoolean("lastMessage", last_message);
30 event->SetString("data", data); 30 event->SetString("data", data);
31 scoped_ptr<ListValue> arguments(new ListValue()); 31 scoped_ptr<ListValue> arguments(new ListValue());
32 arguments->Append(event); 32 arguments->Append(event);
33 return arguments.Pass(); 33 return arguments.Pass();
34 } 34 }
35 35
36 static scoped_ptr<extensions::Event> BuildEvent(
37 scoped_ptr<ListValue> event_args,
38 Profile* profile,
39 GURL event_url) {
40 scoped_ptr<extensions::Event> event(new extensions::Event(
41 "test.onMessage", event_args.Pass()));
42 event->restrict_to_profile = profile;
43 event->event_url = event_url;
44 return event.Pass();
45 }
46
36 virtual void Observe(int type, 47 virtual void Observe(int type,
37 const content::NotificationSource& source, 48 const content::NotificationSource& source,
38 const content::NotificationDetails& details) { 49 const content::NotificationDetails& details) {
39 extensions::EventRouter* event_router = 50 extensions::EventRouter* event_router =
40 extensions::ExtensionSystem::Get( 51 extensions::ExtensionSystem::Get(
41 content::Source<Profile>(source).ptr())->event_router(); 52 content::Source<Profile>(source).ptr())->event_router();
42 53
43 // Sends four messages to the extension. All but the third message sent 54 // Sends four messages to the extension. All but the third message sent
44 // from the origin http://b.com/ are supposed to arrive. 55 // from the origin http://b.com/ are supposed to arrive.
45 event_router->DispatchEventToRenderers("test.onMessage", 56 event_router->BroadcastEvent(BuildEvent(
46 BuildEventArguments(false, "no restriction"), 57 BuildEventArguments(false, "no restriction"),
47 content::Source<Profile>(source).ptr(), 58 content::Source<Profile>(source).ptr(),
48 GURL(), 59 GURL()));
49 extensions::EventFilteringInfo()); 60 event_router->BroadcastEvent(BuildEvent(
50 event_router->DispatchEventToRenderers("test.onMessage",
51 BuildEventArguments(false, "http://a.com/"), 61 BuildEventArguments(false, "http://a.com/"),
52 content::Source<Profile>(source).ptr(), 62 content::Source<Profile>(source).ptr(),
53 GURL("http://a.com/"), 63 GURL("http://a.com/")));
54 extensions::EventFilteringInfo()); 64 event_router->BroadcastEvent(BuildEvent(
55 event_router->DispatchEventToRenderers("test.onMessage",
56 BuildEventArguments(false, "http://b.com/"), 65 BuildEventArguments(false, "http://b.com/"),
57 content::Source<Profile>(source).ptr(), 66 content::Source<Profile>(source).ptr(),
58 GURL("http://b.com/"), 67 GURL("http://b.com/")));
59 extensions::EventFilteringInfo()); 68 event_router->BroadcastEvent(BuildEvent(
60 event_router->DispatchEventToRenderers("test.onMessage",
61 BuildEventArguments(true, "last message"), 69 BuildEventArguments(true, "last message"),
62 content::Source<Profile>(source).ptr(), 70 content::Source<Profile>(source).ptr(),
63 GURL(), 71 GURL()));
64 extensions::EventFilteringInfo());
65 } 72 }
66 73
67 content::NotificationRegistrar registrar_; 74 content::NotificationRegistrar registrar_;
68 }; 75 };
69 76
70 } // namespace 77 } // namespace
71 78
72 // Tests that message passing between extensions and content scripts works. 79 // Tests that message passing between extensions and content scripts works.
73 // Flaky on the trybots. See http://crbug.com/96725. 80 // Flaky on the trybots. See http://crbug.com/96725.
74 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Messaging) { 81 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_Messaging) {
(...skipping 23 matching lines...) Expand all
98 class PanelMessagingTest : public ExtensionApiTest { 105 class PanelMessagingTest : public ExtensionApiTest {
99 virtual void SetUpCommandLine(CommandLine* command_line) { 106 virtual void SetUpCommandLine(CommandLine* command_line) {
100 ExtensionApiTest::SetUpCommandLine(command_line); 107 ExtensionApiTest::SetUpCommandLine(command_line);
101 command_line->AppendSwitch(switches::kEnablePanels); 108 command_line->AppendSwitch(switches::kEnablePanels);
102 } 109 }
103 }; 110 };
104 111
105 IN_PROC_BROWSER_TEST_F(PanelMessagingTest, MessagingPanel) { 112 IN_PROC_BROWSER_TEST_F(PanelMessagingTest, MessagingPanel) {
106 ASSERT_TRUE(RunExtensionTest("messaging/connect_panel")) << message_; 113 ASSERT_TRUE(RunExtensionTest("messaging/connect_panel")) << message_;
107 } 114 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_devtools_bridge.cc ('k') | chrome/browser/extensions/menu_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698