Chromium Code Reviews| 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" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" | 10 #include "chrome/browser/extensions/extension_system.h" |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | |
| 14 #include "chrome/browser/sync/profile_sync_service_factory.h" | |
| 13 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 17 | 19 |
| 18 using ::testing::_; | 20 using ::testing::_; |
| 19 using ::testing::SaveArg; | 21 using ::testing::SaveArg; |
| 20 using ::testing::StrictMock; | 22 using ::testing::StrictMock; |
| 21 | 23 |
| 22 namespace extensions { | 24 namespace extensions { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 ASSERT_TRUE(extension); | 58 ASSERT_TRUE(extension); |
| 57 GURL page_url = extension->GetResourceURL("event_dispatch.html"); | 59 GURL page_url = extension->GetResourceURL("event_dispatch.html"); |
| 58 ui_test_utils::NavigateToURL(browser(), page_url); | 60 ui_test_utils::NavigateToURL(browser(), page_url); |
| 59 EXPECT_TRUE(ready.WaitUntilSatisfied()); | 61 EXPECT_TRUE(ready.WaitUntilSatisfied()); |
| 60 | 62 |
| 61 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload"); | 63 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload"); |
| 62 | 64 |
| 63 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 65 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 64 } | 66 } |
| 65 | 67 |
| 68 // Test that a push introduced into the sync code makes it to the extension | |
| 69 // that we install. | |
| 70 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, ReceivesPush) { | |
| 71 ResultCatcher catcher; | |
| 72 catcher.RestrictToProfile(browser()->profile()); | |
| 73 ExtensionTestMessageListener ready("ready", true); | |
| 74 | |
| 75 const extensions::Extension* extension = | |
| 76 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | |
| 77 ASSERT_TRUE(extension); | |
| 78 GURL page_url = extension->GetResourceURL("event_dispatch.html"); | |
| 79 ui_test_utils::NavigateToURL(browser(), page_url); | |
| 80 EXPECT_TRUE(ready.WaitUntilSatisfied()); | |
| 81 | |
| 82 ProfileSyncService* pss = ProfileSyncServiceFactory:: | |
|
dcheng
2012/09/17 18:39:15
Nit: break the line after the ( instead and keep t
| |
| 83 GetForProfile(browser()->profile()); | |
| 84 ASSERT_TRUE(pss); | |
| 85 | |
| 86 // Construct a sync id for the object "U/<extension-id>/1". | |
| 87 std::string id("U/"); | |
| 88 id += extension->id(); | |
| 89 id += "/1"; | |
| 90 | |
| 91 pss->SendInvalidationForTest(id, "payload"); | |
| 92 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
| 93 } | |
| 94 | |
| 66 // Checks that an extension with the pushMessaging permission gets automatically | 95 // Checks that an extension with the pushMessaging permission gets automatically |
| 67 // registered for invalidations when it is loaded. | 96 // registered for invalidations when it is loaded. |
| 68 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { | 97 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { |
| 69 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( | 98 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( |
| 70 new StrictMock<MockInvalidationMapper>); | 99 new StrictMock<MockInvalidationMapper>); |
| 71 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); | 100 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); |
| 72 // PushMessagingEventRouter owns the mapper now. | 101 // PushMessagingEventRouter owns the mapper now. |
| 73 GetEventRouter()->SetMapperForTest( | 102 GetEventRouter()->SetMapperForTest( |
| 74 mapper.PassAs<PushMessagingInvalidationMapper>()); | 103 mapper.PassAs<PushMessagingInvalidationMapper>()); |
| 75 | 104 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 96 } | 125 } |
| 97 | 126 |
| 98 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { | 127 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { |
| 99 PushMessagingInvalidationHandler* handler = | 128 PushMessagingInvalidationHandler* handler = |
| 100 static_cast<PushMessagingInvalidationHandler*>( | 129 static_cast<PushMessagingInvalidationHandler*>( |
| 101 GetEventRouter()->GetMapperForTest()); | 130 GetEventRouter()->GetMapperForTest()); |
| 102 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); | 131 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); |
| 103 } | 132 } |
| 104 | 133 |
| 105 } // namespace extensions | 134 } // namespace extensions |
| OLD | NEW |