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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 PushMessagingEventRouter* GetEventRouter() { | 49 PushMessagingEventRouter* GetEventRouter() { |
50 return ExtensionSystem::Get(browser()->profile())->extension_service()-> | 50 return ExtensionSystem::Get(browser()->profile())->extension_service()-> |
51 push_messaging_event_router(); | 51 push_messaging_event_router(); |
52 } | 52 } |
53 }; | 53 }; |
54 | 54 |
55 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { | 55 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { |
56 ResultCatcher catcher; | 56 ResultCatcher catcher; |
57 catcher.RestrictToProfile(browser()->profile()); | 57 catcher.RestrictToProfile(browser()->profile()); |
58 ExtensionTestMessageListener ready("ready", true); | 58 ExtensionTestMessageListener ready("ready", false); |
59 | 59 |
60 const extensions::Extension* extension = | 60 const extensions::Extension* extension = |
61 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 61 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
62 ASSERT_TRUE(extension); | 62 ASSERT_TRUE(extension); |
63 extensions::LaunchPlatformApp( | 63 extensions::LaunchPlatformApp( |
64 browser()->profile(), extension, NULL, FilePath()); | 64 browser()->profile(), extension, NULL, FilePath()); |
65 EXPECT_TRUE(ready.WaitUntilSatisfied()); | 65 EXPECT_TRUE(ready.WaitUntilSatisfied()); |
66 | 66 |
67 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload"); | 67 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload"); |
68 | 68 |
69 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 69 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 70 CloseShellWindowsAndWaitForAppToExit(); |
70 } | 71 } |
71 | 72 |
72 // Test that a push introduced into the sync code makes it to the extension | 73 // Test that a push introduced into the sync code makes it to the extension |
73 // that we install. | 74 // that we install. |
74 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, ReceivesPush) { | 75 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, ReceivesPush) { |
75 ResultCatcher catcher; | 76 ResultCatcher catcher; |
76 catcher.RestrictToProfile(browser()->profile()); | 77 catcher.RestrictToProfile(browser()->profile()); |
77 ExtensionTestMessageListener ready("ready", true); | 78 ExtensionTestMessageListener ready("ready", false); |
78 | 79 |
79 const extensions::Extension* extension = | 80 const extensions::Extension* extension = |
80 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 81 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
81 ASSERT_TRUE(extension); | 82 ASSERT_TRUE(extension); |
82 extensions::LaunchPlatformApp( | 83 extensions::LaunchPlatformApp( |
83 browser()->profile(), extension, NULL, FilePath()); | 84 browser()->profile(), extension, NULL, FilePath()); |
84 EXPECT_TRUE(ready.WaitUntilSatisfied()); | 85 EXPECT_TRUE(ready.WaitUntilSatisfied()); |
85 | 86 |
86 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile( | 87 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile( |
87 browser()->profile()); | 88 browser()->profile()); |
88 ASSERT_TRUE(pss); | 89 ASSERT_TRUE(pss); |
89 | 90 |
90 // Construct a sync id for the object "U/<extension-id>/1". | 91 // Construct a sync id for the object "U/<extension-id>/1". |
91 std::string id = "U/"; | 92 std::string id = "U/"; |
92 id += extension->id(); | 93 id += extension->id(); |
93 id += "/1"; | 94 id += "/1"; |
94 | 95 |
95 invalidation::ObjectId object_id(kSourceId, id); | 96 invalidation::ObjectId object_id(kSourceId, id); |
96 | 97 |
97 pss->EmitInvalidationForTest(object_id, "payload"); | 98 pss->EmitInvalidationForTest(object_id, "payload"); |
98 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 99 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 100 CloseShellWindowsAndWaitForAppToExit(); |
99 } | 101 } |
100 | 102 |
101 // Checks that an extension with the pushMessaging permission gets automatically | 103 // Checks that an extension with the pushMessaging permission gets automatically |
102 // registered for invalidations when it is loaded. | 104 // registered for invalidations when it is loaded. |
103 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { | 105 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { |
104 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( | 106 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( |
105 new StrictMock<MockInvalidationMapper>); | 107 new StrictMock<MockInvalidationMapper>); |
106 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); | 108 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); |
107 // PushMessagingEventRouter owns the mapper now. | 109 // PushMessagingEventRouter owns the mapper now. |
108 GetEventRouter()->SetMapperForTest( | 110 GetEventRouter()->SetMapperForTest( |
(...skipping 10 matching lines...) Expand all Loading... |
119 UnloadExtension(extension->id()); | 121 UnloadExtension(extension->id()); |
120 } | 122 } |
121 | 123 |
122 // Tests that we re-register for invalidations on restart for extensions that | 124 // Tests that we re-register for invalidations on restart for extensions that |
123 // are already installed. | 125 // are already installed. |
124 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, PRE_Restart) { | 126 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, PRE_Restart) { |
125 PushMessagingInvalidationHandler* handler = | 127 PushMessagingInvalidationHandler* handler = |
126 static_cast<PushMessagingInvalidationHandler*>( | 128 static_cast<PushMessagingInvalidationHandler*>( |
127 GetEventRouter()->GetMapperForTest()); | 129 GetEventRouter()->GetMapperForTest()); |
128 EXPECT_TRUE(handler->GetRegisteredExtensionsForTest().empty()); | 130 EXPECT_TRUE(handler->GetRegisteredExtensionsForTest().empty()); |
| 131 ExtensionTestMessageListener ready("ready", false); |
129 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("push_messaging"), | 132 ASSERT_TRUE(InstallExtension(test_data_dir_.AppendASCII("push_messaging"), |
130 1 /* new install */)); | 133 1 /* new install */)); |
| 134 EXPECT_TRUE(ready.WaitUntilSatisfied()); |
| 135 CloseShellWindowsAndWaitForAppToExit(); |
131 } | 136 } |
132 | 137 |
133 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { | 138 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { |
134 PushMessagingInvalidationHandler* handler = | 139 PushMessagingInvalidationHandler* handler = |
135 static_cast<PushMessagingInvalidationHandler*>( | 140 static_cast<PushMessagingInvalidationHandler*>( |
136 GetEventRouter()->GetMapperForTest()); | 141 GetEventRouter()->GetMapperForTest()); |
137 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); | 142 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); |
138 } | 143 } |
139 | 144 |
140 // Test the GetChannelId API. | 145 // Test the GetChannelId API. |
141 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, GetChannelId) { | 146 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, GetChannelId) { |
142 ResultCatcher catcher; | 147 ResultCatcher catcher; |
143 catcher.RestrictToProfile(browser()->profile()); | 148 catcher.RestrictToProfile(browser()->profile()); |
144 | 149 |
145 const extensions::Extension* extension = | 150 const extensions::Extension* extension = |
146 LoadExtension(test_data_dir_.AppendASCII("get_channel_id")); | 151 LoadExtension(test_data_dir_.AppendASCII("get_channel_id")); |
147 ASSERT_TRUE(extension); | 152 ASSERT_TRUE(extension); |
148 extensions::LaunchPlatformApp( | 153 extensions::LaunchPlatformApp( |
149 browser()->profile(), extension, NULL, FilePath()); | 154 browser()->profile(), extension, NULL, FilePath()); |
150 | 155 |
151 // Just loading the page will cause a getChannelId call, so we check | 156 // Just loading the page will cause a getChannelId call, so we check |
152 // for a callback. It should fail because there is no auth token. | 157 // for a callback. It should fail because there is no auth token. |
153 | 158 |
154 // Make sure we got a failure (but we do get a result). | 159 // Make sure we got a failure (but we do get a result). |
155 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 160 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 161 CloseShellWindowsAndWaitForAppToExit(); |
156 } | 162 } |
157 | 163 |
158 } // namespace extensions | 164 } // namespace extensions |
OLD | NEW |