| OLD | NEW |
| 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 "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" | 5 #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h" |
| 6 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" | 6 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" |
| 7 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_mapper.h" | 7 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_mapper.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | |
| 10 #include "chrome/browser/extensions/extension_system.h" | |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "chrome/browser/extensions/platform_app_launcher.h" | 10 #include "chrome/browser/extensions/platform_app_launcher.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/sync/profile_sync_service.h" | 12 #include "chrome/browser/sync/profile_sync_service.h" |
| 15 #include "chrome/browser/sync/profile_sync_service_factory.h" | 13 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 16 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "google/cacheinvalidation/types.pb.h" | 17 #include "google/cacheinvalidation/types.pb.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 MockInvalidationMapper::MockInvalidationMapper() {} | 35 MockInvalidationMapper::MockInvalidationMapper() {} |
| 38 MockInvalidationMapper::~MockInvalidationMapper() {} | 36 MockInvalidationMapper::~MockInvalidationMapper() {} |
| 39 | 37 |
| 40 class PushMessagingApiTest : public ExtensionApiTest { | 38 class PushMessagingApiTest : public ExtensionApiTest { |
| 41 public: | 39 public: |
| 42 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 40 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 43 ExtensionApiTest::SetUpCommandLine(command_line); | 41 ExtensionApiTest::SetUpCommandLine(command_line); |
| 44 } | 42 } |
| 45 | 43 |
| 46 PushMessagingEventRouter* GetEventRouter() { | 44 PushMessagingEventRouter* GetEventRouter() { |
| 47 return ExtensionSystem::Get(browser()->profile())->extension_service()-> | 45 return PushMessagingAPI::Get(browser()->profile())-> |
| 48 push_messaging_event_router(); | 46 GetEventRouterForTest(); |
| 49 } | 47 } |
| 50 }; | 48 }; |
| 51 | 49 |
| 52 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { | 50 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { |
| 53 ResultCatcher catcher; | 51 ResultCatcher catcher; |
| 54 catcher.RestrictToProfile(browser()->profile()); | 52 catcher.RestrictToProfile(browser()->profile()); |
| 55 ExtensionTestMessageListener ready("ready", true); | 53 ExtensionTestMessageListener ready("ready", true); |
| 56 | 54 |
| 57 const extensions::Extension* extension = | 55 const extensions::Extension* extension = |
| 58 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 56 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 pss->EmitInvalidationForTest(object_id, "payload"); | 93 pss->EmitInvalidationForTest(object_id, "payload"); |
| 96 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 94 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 97 } | 95 } |
| 98 | 96 |
| 99 // Checks that an extension with the pushMessaging permission gets automatically | 97 // Checks that an extension with the pushMessaging permission gets automatically |
| 100 // registered for invalidations when it is loaded. | 98 // registered for invalidations when it is loaded. |
| 101 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { | 99 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { |
| 102 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( | 100 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( |
| 103 new StrictMock<MockInvalidationMapper>); | 101 new StrictMock<MockInvalidationMapper>); |
| 104 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); | 102 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); |
| 103 PushMessagingAPI::Get(browser()->profile())->InitializeEventRouterForTest(); |
| 105 // PushMessagingEventRouter owns the mapper now. | 104 // PushMessagingEventRouter owns the mapper now. |
| 106 GetEventRouter()->SetMapperForTest( | 105 GetEventRouter()->SetMapperForTest( |
| 107 mapper.PassAs<PushMessagingInvalidationMapper>()); | 106 mapper.PassAs<PushMessagingInvalidationMapper>()); |
| 108 | 107 |
| 109 std::string extension_id; | 108 std::string extension_id; |
| 110 EXPECT_CALL(*unsafe_mapper, RegisterExtension(_)) | 109 EXPECT_CALL(*unsafe_mapper, RegisterExtension(_)) |
| 111 .WillOnce(SaveArg<0>(&extension_id)); | 110 .WillOnce(SaveArg<0>(&extension_id)); |
| 112 const extensions::Extension* extension = | 111 const extensions::Extension* extension = |
| 113 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 112 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| 114 ASSERT_TRUE(extension); | 113 ASSERT_TRUE(extension); |
| 115 EXPECT_EQ(extension->id(), extension_id); | 114 EXPECT_EQ(extension->id(), extension_id); |
| 116 EXPECT_CALL(*unsafe_mapper, UnregisterExtension(extension->id())); | 115 EXPECT_CALL(*unsafe_mapper, UnregisterExtension(extension->id())); |
| 117 UnloadExtension(extension->id()); | 116 UnloadExtension(extension->id()); |
| 118 } | 117 } |
| 119 | 118 |
| 120 // Tests that we re-register for invalidations on restart for extensions that | 119 // Tests that we re-register for invalidations on restart for extensions that |
| 121 // are already installed. | 120 // are already installed. |
| 122 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, PRE_Restart) { | 121 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, PRE_Restart) { |
| 122 PushMessagingAPI::Get(browser()->profile())->InitializeEventRouterForTest(); |
| 123 PushMessagingInvalidationHandler* handler = | 123 PushMessagingInvalidationHandler* handler = |
| 124 static_cast<PushMessagingInvalidationHandler*>( | 124 static_cast<PushMessagingInvalidationHandler*>( |
| 125 GetEventRouter()->GetMapperForTest()); | 125 GetEventRouter()->GetMapperForTest()); |
| 126 EXPECT_TRUE(handler->GetRegisteredExtensionsForTest().empty()); | 126 EXPECT_TRUE(handler->GetRegisteredExtensionsForTest().empty()); |
| 127 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("push_messaging"), | 127 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("push_messaging"), |
| 128 1 /* new install */)); | 128 1 /* new install */)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { | 131 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { |
| 132 PushMessagingAPI::Get(browser()->profile())->InitializeEventRouterForTest(); |
| 132 PushMessagingInvalidationHandler* handler = | 133 PushMessagingInvalidationHandler* handler = |
| 133 static_cast<PushMessagingInvalidationHandler*>( | 134 static_cast<PushMessagingInvalidationHandler*>( |
| 134 GetEventRouter()->GetMapperForTest()); | 135 GetEventRouter()->GetMapperForTest()); |
| 135 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); | 136 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); |
| 136 } | 137 } |
| 137 | 138 |
| 138 // Test that GetChannelId fails if no user is signed in. | 139 // Test that GetChannelId fails if no user is signed in. |
| 139 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, GetChannelId) { | 140 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, GetChannelId) { |
| 140 ResultCatcher catcher; | 141 ResultCatcher catcher; |
| 141 catcher.RestrictToProfile(browser()->profile()); | 142 catcher.RestrictToProfile(browser()->profile()); |
| 142 | 143 |
| 143 const extensions::Extension* extension = | 144 const extensions::Extension* extension = |
| 144 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 145 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| 145 ASSERT_TRUE(extension); | 146 ASSERT_TRUE(extension); |
| 146 ui_test_utils::NavigateToURL( | 147 ui_test_utils::NavigateToURL( |
| 147 browser(), extension->GetResourceURL("get_channel_id.html")); | 148 browser(), extension->GetResourceURL("get_channel_id.html")); |
| 148 | 149 |
| 149 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 150 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 150 } | 151 } |
| 151 | 152 |
| 152 } // namespace extensions | 153 } // namespace extensions |
| OLD | NEW |