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

Unified Diff: chrome/browser/extensions/event_router_forwarder_unittest.cc

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing memory leak in a test. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/event_router_forwarder_unittest.cc
diff --git a/chrome/browser/extensions/event_router_forwarder_unittest.cc b/chrome/browser/extensions/event_router_forwarder_unittest.cc
index ab68262f5e16b89ee010084519ac2fda27ba7458..c39e081d4eae3c58356329e67bb92a686cccc1a1 100644
--- a/chrome/browser/extensions/event_router_forwarder_unittest.cc
+++ b/chrome/browser/extensions/event_router_forwarder_unittest.cc
@@ -24,19 +24,64 @@ namespace extensions {
namespace {
const char kEventName[] = "event_name";
-const char kEventArgs[] = "event_args";
const char kExt[] = "extension";
class MockEventRouterForwarder : public EventRouterForwarder {
public:
- MOCK_METHOD6(CallEventRouter,
- void(Profile*, const std::string&, const std::string&, const std::string&,
- Profile*, const GURL&));
+ MOCK_METHOD5(CallEventRouter,
+ void(Profile*, const std::string&, const std::string&, Profile*,
+ const GURL&));
+
+ virtual void CallEventRouter(
+ Profile* profile, const std::string& extension_id,
+ const std::string& event_name, scoped_ptr<base::ListValue> event_args,
+ Profile* restrict_to_profile, const GURL& event_url) {
+ CallEventRouter(profile, extension_id, event_name,
+ restrict_to_profile, event_url);
+ }
protected:
virtual ~MockEventRouterForwarder() {}
};
+static void BroadcastEventToRenderers(EventRouterForwarder* event_router,
+ const std::string& event_name,
+ const GURL& url) {
+ scoped_ptr<ListValue> args(new ListValue());
+ event_router->BroadcastEventToRenderers(event_name, args.Pass(), url);
+}
+
+static void DispatchEventToRenderers(EventRouterForwarder* event_router,
+ const std::string& event_name,
+ void* profile,
+ bool use_profile_to_restrict_events,
+ const GURL& url) {
+ scoped_ptr<ListValue> args(new ListValue());
+ event_router->DispatchEventToRenderers(event_name, args.Pass(), profile,
+ use_profile_to_restrict_events, url);
+}
+
+static void BroadcastEventToExtension(EventRouterForwarder* event_router,
+ const std::string& extension,
+ const std::string& event_name,
+ const GURL& url) {
+ scoped_ptr<ListValue> args(new ListValue());
+ event_router->BroadcastEventToExtension(extension, event_name, args.Pass(),
+ url);
+}
+
+static void DispatchEventToExtension(EventRouterForwarder* event_router,
+ const std::string& extension,
+ const std::string& event_name,
+ void* profile,
+ bool use_profile_to_restrict_events,
+ const GURL& url) {
+ scoped_ptr<ListValue> args(new ListValue());
+ event_router->DispatchEventToExtension(
+ extension, event_name, args.Pass(), profile,
+ use_profile_to_restrict_events, url);
+}
+
} // namespace
class EventRouterForwarderTest : public testing::Test {
@@ -84,12 +129,10 @@ TEST_F(EventRouterForwarderTest, BroadcastRendererUI) {
new MockEventRouterForwarder);
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, "", kEventName, kEventArgs, profile1_, url));
+ CallEventRouter(profile1_, "", kEventName, profile1_, url));
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile2_, "", kEventName, kEventArgs, profile2_, url));
- event_router->BroadcastEventToRenderers(kEventName, kEventArgs, url);
+ CallEventRouter(profile2_, "", kEventName, profile2_, url));
+ BroadcastEventToRenderers(event_router.get(), kEventName, url);
}
TEST_F(EventRouterForwarderTest, BroadcastRendererUIIncognito) {
@@ -99,14 +142,12 @@ TEST_F(EventRouterForwarderTest, BroadcastRendererUIIncognito) {
GURL url;
Profile* incognito = CreateIncognitoProfile(profile1_);
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, "", kEventName, kEventArgs, profile1_, url));
+ CallEventRouter(profile1_, "", kEventName, profile1_, url));
EXPECT_CALL(*event_router,
- CallEventRouter(incognito, _, _, _, _, _)).Times(0);
+ CallEventRouter(incognito, _, _, _, _)).Times(0);
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile2_, "", kEventName, kEventArgs, profile2_, url));
- event_router->BroadcastEventToRenderers(kEventName, kEventArgs, url);
+ CallEventRouter(profile2_, "", kEventName, profile2_, url));
+ BroadcastEventToRenderers(event_router.get(), kEventName, url);
}
// This is the canonical test for passing control flow from the IO thread
@@ -117,16 +158,13 @@ TEST_F(EventRouterForwarderTest, BroadcastRendererIO) {
new MockEventRouterForwarder);
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, "", kEventName, kEventArgs, profile1_, url));
+ CallEventRouter(profile1_, "", kEventName, profile1_, url));
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile2_, "", kEventName, kEventArgs, profile2_, url));
+ CallEventRouter(profile2_, "", kEventName, profile2_, url));
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(
- &MockEventRouterForwarder::BroadcastEventToRenderers,
- event_router.get(),
- std::string(kEventName), std::string(kEventArgs), url));
+ &BroadcastEventToRenderers, base::Unretained(event_router.get()),
+ kEventName, url));
// Wait for IO thread's message loop to be processed
scoped_refptr<base::ThreadTestHelper> helper(
@@ -143,12 +181,11 @@ TEST_F(EventRouterForwarderTest, UnicastRendererUIRestricted) {
using ::testing::_;
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, "", kEventName, kEventArgs, profile1_, url));
+ CallEventRouter(profile1_, "", kEventName, profile1_, url));
EXPECT_CALL(*event_router,
- CallEventRouter(profile2_, _, _, _, _, _)).Times(0);
- event_router->DispatchEventToRenderers(kEventName, kEventArgs,
- profile1_, true, url);
+ CallEventRouter(profile2_, _, _, _, _)).Times(0);
+ DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true,
+ url);
}
TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito1) {
@@ -158,14 +195,13 @@ TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito1) {
using ::testing::_;
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, "", kEventName, kEventArgs, profile1_, url));
+ CallEventRouter(profile1_, "", kEventName, profile1_, url));
EXPECT_CALL(*event_router,
- CallEventRouter(incognito, _, _, _, _, _)).Times(0);
+ CallEventRouter(incognito, _, _, _, _)).Times(0);
EXPECT_CALL(*event_router,
- CallEventRouter(profile2_, _, _, _, _, _)).Times(0);
- event_router->DispatchEventToRenderers(kEventName, kEventArgs,
- profile1_, true, url);
+ CallEventRouter(profile2_, _, _, _, _)).Times(0);
+ DispatchEventToRenderers(event_router.get(), kEventName, profile1_, true,
+ url);
}
TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito2) {
@@ -175,14 +211,13 @@ TEST_F(EventRouterForwarderTest, UnicastRendererUIRestrictedIncognito2) {
using ::testing::_;
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(profile1_, _, _, _, _, _)).Times(0);
+ CallEventRouter(profile1_, _, _, _, _)).Times(0);
EXPECT_CALL(*event_router,
- CallEventRouter(
- incognito, "", kEventName, kEventArgs, incognito, url));
+ CallEventRouter(incognito, "", kEventName, incognito, url));
EXPECT_CALL(*event_router,
- CallEventRouter(profile2_, _, _, _, _, _)).Times(0);
- event_router->DispatchEventToRenderers(kEventName, kEventArgs,
- incognito, true, url);
+ CallEventRouter(profile2_, _, _, _, _)).Times(0);
+ DispatchEventToRenderers(event_router.get(), kEventName, incognito, true,
+ url);
}
TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestricted) {
@@ -191,12 +226,11 @@ TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestricted) {
using ::testing::_;
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, "", kEventName, kEventArgs, NULL, url));
+ CallEventRouter(profile1_, "", kEventName, NULL, url));
EXPECT_CALL(*event_router,
- CallEventRouter(profile2_, _, _, _, _, _)).Times(0);
- event_router->DispatchEventToRenderers(kEventName, kEventArgs,
- profile1_, false, url);
+ CallEventRouter(profile2_, _, _, _, _)).Times(0);
+ DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false,
+ url);
}
TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestrictedIncognito) {
@@ -206,14 +240,13 @@ TEST_F(EventRouterForwarderTest, UnicastRendererUIUnrestrictedIncognito) {
using ::testing::_;
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, "", kEventName, kEventArgs, NULL, url));
+ CallEventRouter(profile1_, "", kEventName, NULL, url));
EXPECT_CALL(*event_router,
- CallEventRouter(incognito, _, _, _, _, _)).Times(0);
+ CallEventRouter(incognito, _, _, _, _)).Times(0);
EXPECT_CALL(*event_router,
- CallEventRouter(profile2_, _, _, _, _, _)).Times(0);
- event_router->DispatchEventToRenderers(kEventName, kEventArgs,
- profile1_, false, url);
+ CallEventRouter(profile2_, _, _, _, _)).Times(0);
+ DispatchEventToRenderers(event_router.get(), kEventName, profile1_, false,
+ url);
}
TEST_F(EventRouterForwarderTest, BroadcastExtensionUI) {
@@ -221,12 +254,10 @@ TEST_F(EventRouterForwarderTest, BroadcastExtensionUI) {
new MockEventRouterForwarder);
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, kExt, kEventName, kEventArgs, profile1_, url));
+ CallEventRouter(profile1_, kExt, kEventName, profile1_, url));
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile2_, kExt, kEventName, kEventArgs, profile2_, url));
- event_router->BroadcastEventToExtension(kExt, kEventName, kEventArgs, url);
+ CallEventRouter(profile2_, kExt, kEventName, profile2_, url));
+ BroadcastEventToExtension(event_router.get(), kExt, kEventName, url);
}
TEST_F(EventRouterForwarderTest, UnicastExtensionUIRestricted) {
@@ -235,12 +266,11 @@ TEST_F(EventRouterForwarderTest, UnicastExtensionUIRestricted) {
using ::testing::_;
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, kExt, kEventName, kEventArgs, profile1_, url));
+ CallEventRouter(profile1_, kExt, kEventName, profile1_, url));
EXPECT_CALL(*event_router,
- CallEventRouter(profile2_, _, _, _, _, _)).Times(0);
- event_router->DispatchEventToExtension(kExt, kEventName, kEventArgs,
- profile1_, true, url);
+ CallEventRouter(profile2_, _, _, _, _)).Times(0);
+ DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_,
+ true, url);
}
TEST_F(EventRouterForwarderTest, UnicastExtensionUIUnrestricted) {
@@ -249,12 +279,11 @@ TEST_F(EventRouterForwarderTest, UnicastExtensionUIUnrestricted) {
using ::testing::_;
GURL url;
EXPECT_CALL(*event_router,
- CallEventRouter(
- profile1_, kExt, kEventName, kEventArgs, NULL, url));
+ CallEventRouter(profile1_, kExt, kEventName, NULL, url));
EXPECT_CALL(*event_router,
- CallEventRouter(profile2_, _, _, _, _, _)).Times(0);
- event_router->DispatchEventToExtension(kExt, kEventName, kEventArgs,
- profile1_, false, url);
+ CallEventRouter(profile2_, _, _, _, _)).Times(0);
+ DispatchEventToExtension(event_router.get(), kExt, kEventName, profile1_,
+ false, url);
}
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/event_router_forwarder.cc ('k') | chrome/browser/extensions/extension_devtools_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698