| 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 | 6 |
| 7 #include "apps/launcher.h" | 7 #include "apps/launcher.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" | 9 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_handler.h" |
| 10 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_mapper.h" | 10 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati
on_mapper.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 13 #include "chrome/browser/invalidation/fake_invalidation_service.h" | 13 #include "chrome/browser/invalidation/fake_invalidation_service.h" |
| 14 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 14 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "components/invalidation/fake_invalidator.h" | 19 #include "components/invalidation/fake_invalidator.h" |
| 20 #include "components/invalidation/invalidation.h" | 20 #include "components/invalidation/invalidation.h" |
| 21 #include "components/invalidation/invalidation_service.h" | 21 #include "components/invalidation/invalidation_service.h" |
| 22 #include "components/invalidation/profile_invalidation_provider.h" | 22 #include "components/invalidation/profile_invalidation_provider.h" |
| 23 #include "components/keyed_service/core/keyed_service.h" | 23 #include "components/keyed_service/core/keyed_service.h" |
| 24 #include "extensions/test/result_catcher.h" |
| 24 #include "google/cacheinvalidation/types.pb.h" | 25 #include "google/cacheinvalidation/types.pb.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 26 | 27 |
| 27 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
| 28 using ::testing::StrictMock; | 29 using ::testing::StrictMock; |
| 29 using ::testing::_; | 30 using ::testing::_; |
| 30 | 31 |
| 31 namespace content { | 32 namespace content { |
| 32 class BrowserContext; | 33 class BrowserContext; |
| 33 } | 34 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 | 107 |
| 107 PushMessagingEventRouter* GetEventRouter() { | 108 PushMessagingEventRouter* GetEventRouter() { |
| 108 return PushMessagingAPI::Get(profile())->GetEventRouterForTest(); | 109 return PushMessagingAPI::Get(profile())->GetEventRouterForTest(); |
| 109 } | 110 } |
| 110 | 111 |
| 111 invalidation::FakeInvalidationService* fake_invalidation_service_; | 112 invalidation::FakeInvalidationService* fake_invalidation_service_; |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { | 115 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { |
| 115 ResultCatcher catcher; | 116 ResultCatcher catcher; |
| 116 catcher.RestrictToProfile(profile()); | 117 catcher.RestrictToBrowserContext(profile()); |
| 117 | 118 |
| 118 const extensions::Extension* extension = | 119 const extensions::Extension* extension = |
| 119 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 120 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| 120 ASSERT_TRUE(extension); | 121 ASSERT_TRUE(extension); |
| 121 ui_test_utils::NavigateToURL( | 122 ui_test_utils::NavigateToURL( |
| 122 browser(), extension->GetResourceURL("event_dispatch.html")); | 123 browser(), extension->GetResourceURL("event_dispatch.html")); |
| 123 | 124 |
| 124 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload"); | 125 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload"); |
| 125 | 126 |
| 126 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 127 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 // Test that a push introduced into the sync code makes it to the extension | 130 // Test that a push introduced into the sync code makes it to the extension |
| 130 // that we install. | 131 // that we install. |
| 131 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, ReceivesPush) { | 132 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, ReceivesPush) { |
| 132 ResultCatcher catcher; | 133 ResultCatcher catcher; |
| 133 catcher.RestrictToProfile(profile()); | 134 catcher.RestrictToBrowserContext(profile()); |
| 134 | 135 |
| 135 const extensions::Extension* extension = | 136 const extensions::Extension* extension = |
| 136 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 137 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| 137 ASSERT_TRUE(extension); | 138 ASSERT_TRUE(extension); |
| 138 ui_test_utils::NavigateToURL( | 139 ui_test_utils::NavigateToURL( |
| 139 browser(), extension->GetResourceURL("event_dispatch.html")); | 140 browser(), extension->GetResourceURL("event_dispatch.html")); |
| 140 | 141 |
| 141 // PushMessagingInvalidationHandler suppresses the initial invalidation on | 142 // PushMessagingInvalidationHandler suppresses the initial invalidation on |
| 142 // each subchannel at install, so trigger the suppressions first. | 143 // each subchannel at install, so trigger the suppressions first. |
| 143 for (int i = 0; i < 3; ++i) { | 144 for (int i = 0; i < 3; ++i) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { | 190 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { |
| 190 PushMessagingInvalidationHandler* handler = | 191 PushMessagingInvalidationHandler* handler = |
| 191 static_cast<PushMessagingInvalidationHandler*>( | 192 static_cast<PushMessagingInvalidationHandler*>( |
| 192 GetAPI()->GetMapperForTest()); | 193 GetAPI()->GetMapperForTest()); |
| 193 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); | 194 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // Test that GetChannelId fails if no user is signed in. | 197 // Test that GetChannelId fails if no user is signed in. |
| 197 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, GetChannelId) { | 198 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, GetChannelId) { |
| 198 ResultCatcher catcher; | 199 ResultCatcher catcher; |
| 199 catcher.RestrictToProfile(profile()); | 200 catcher.RestrictToBrowserContext(profile()); |
| 200 | 201 |
| 201 const extensions::Extension* extension = | 202 const extensions::Extension* extension = |
| 202 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 203 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| 203 ASSERT_TRUE(extension); | 204 ASSERT_TRUE(extension); |
| 204 ui_test_utils::NavigateToURL( | 205 ui_test_utils::NavigateToURL( |
| 205 browser(), extension->GetResourceURL("get_channel_id.html")); | 206 browser(), extension->GetResourceURL("get_channel_id.html")); |
| 206 | 207 |
| 207 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 208 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 208 } | 209 } |
| 209 | 210 |
| 210 } // namespace extensions | 211 } // namespace extensions |
| OLD | NEW |