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 | |
|
Mihai Parparita -not on Chrome
2012/09/13 20:37:09
Nit: capitalize sentence, end it with a period.
(
Pete Williamson
2012/09/14 19:14:48
Done.
| |
| 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 // launch the test app | |
|
dcheng
2012/09/13 21:00:48
In general, comments like this aren't needed. Ditt
Pete Williamson
2012/09/14 19:14:48
Done.
| |
| 76 const extensions::Extension* extension = | |
| 77 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | |
| 78 ASSERT_TRUE(extension); | |
| 79 GURL page_url = extension->GetResourceURL("event_dispatch.html"); | |
| 80 ui_test_utils::NavigateToURL(browser(), page_url); | |
| 81 EXPECT_TRUE(ready.WaitUntilSatisfied()); | |
| 82 | |
| 83 // get the profile sync service to use | |
| 84 ProfileSyncService* pss = ProfileSyncServiceFactory:: | |
| 85 GetForProfile(browser()->profile()); | |
| 86 ASSERT_TRUE(NULL != pss); | |
|
dcheng
2012/09/13 21:00:48
ASSERT_TRUE(pss) to match style in other parts of
Pete Williamson
2012/09/14 19:14:48
Done.
| |
| 87 | |
| 88 // construct a sync id for the object "U/<extension-id>/1" | |
| 89 std::string id("U/"); | |
| 90 id += extension->id(); | |
| 91 id += "/1"; | |
| 92 | |
| 93 // now send the notification via the profile sync service | |
| 94 pss->SendNotificationForTest(id, "payload"); | |
| 95 | |
| 96 // verify that the test app sees a push message | |
| 97 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | |
| 98 } | |
| 99 | |
| 66 // Checks that an extension with the pushMessaging permission gets automatically | 100 // Checks that an extension with the pushMessaging permission gets automatically |
| 67 // registered for invalidations when it is loaded. | 101 // registered for invalidations when it is loaded. |
| 68 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { | 102 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { |
| 69 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( | 103 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( |
| 70 new StrictMock<MockInvalidationMapper>); | 104 new StrictMock<MockInvalidationMapper>); |
| 71 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); | 105 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); |
| 72 // PushMessagingEventRouter owns the mapper now. | 106 // PushMessagingEventRouter owns the mapper now. |
| 73 GetEventRouter()->SetMapperForTest( | 107 GetEventRouter()->SetMapperForTest( |
| 74 mapper.PassAs<PushMessagingInvalidationMapper>()); | 108 mapper.PassAs<PushMessagingInvalidationMapper>()); |
| 75 | 109 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 96 } | 130 } |
| 97 | 131 |
| 98 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { | 132 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { |
| 99 PushMessagingInvalidationHandler* handler = | 133 PushMessagingInvalidationHandler* handler = |
| 100 static_cast<PushMessagingInvalidationHandler*>( | 134 static_cast<PushMessagingInvalidationHandler*>( |
| 101 GetEventRouter()->GetMapperForTest()); | 135 GetEventRouter()->GetMapperForTest()); |
| 102 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); | 136 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); |
| 103 } | 137 } |
| 104 | 138 |
| 105 } // namespace extensions | 139 } // namespace extensions |
| OLD | NEW |