| 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" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 virtual void SetUpOnMainThread() OVERRIDE { | 73 virtual void SetUpOnMainThread() OVERRIDE { |
| 74 ExtensionApiTest::SetUpOnMainThread(); | 74 ExtensionApiTest::SetUpOnMainThread(); |
| 75 fake_invalidation_service_ = | 75 fake_invalidation_service_ = |
| 76 static_cast<invalidation::FakeInvalidationService*>( | 76 static_cast<invalidation::FakeInvalidationService*>( |
| 77 InvalidationServiceFactory::GetInstance()->GetForProfile( | 77 InvalidationServiceFactory::GetInstance()->GetForProfile( |
| 78 profile())); | 78 profile())); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void EmitInvalidation( | 81 void EmitInvalidation( |
| 82 const invalidation::ObjectId& object_id, | 82 const invalidation::ObjectId& object_id, |
| 83 int64 version, |
| 83 const std::string& payload) { | 84 const std::string& payload) { |
| 84 fake_invalidation_service_->EmitInvalidationForTest( | 85 fake_invalidation_service_->EmitInvalidationForTest( |
| 85 object_id, | 86 syncer::Invalidation::Init(object_id, version, payload)); |
| 86 syncer::Invalidation::kUnknownVersion, | |
| 87 payload); | |
| 88 } | 87 } |
| 89 | 88 |
| 90 PushMessagingAPI* GetAPI() { | 89 PushMessagingAPI* GetAPI() { |
| 91 return PushMessagingAPI::Get(profile()); | 90 return PushMessagingAPI::Get(profile()); |
| 92 } | 91 } |
| 93 | 92 |
| 94 PushMessagingEventRouter* GetEventRouter() { | 93 PushMessagingEventRouter* GetEventRouter() { |
| 95 return PushMessagingAPI::Get(profile())->GetEventRouterForTest(); | 94 return PushMessagingAPI::Get(profile())->GetEventRouterForTest(); |
| 96 } | 95 } |
| 97 | 96 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 const extensions::Extension* extension = | 121 const extensions::Extension* extension = |
| 123 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 122 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| 124 ASSERT_TRUE(extension); | 123 ASSERT_TRUE(extension); |
| 125 ui_test_utils::NavigateToURL( | 124 ui_test_utils::NavigateToURL( |
| 126 browser(), extension->GetResourceURL("event_dispatch.html")); | 125 browser(), extension->GetResourceURL("event_dispatch.html")); |
| 127 | 126 |
| 128 // PushMessagingInvalidationHandler suppresses the initial invalidation on | 127 // PushMessagingInvalidationHandler suppresses the initial invalidation on |
| 129 // each subchannel at install, so trigger the suppressions first. | 128 // each subchannel at install, so trigger the suppressions first. |
| 130 for (int i = 0; i < 3; ++i) { | 129 for (int i = 0; i < 3; ++i) { |
| 131 EmitInvalidation( | 130 EmitInvalidation( |
| 132 ExtensionAndSubchannelToObjectId(extension->id(), i), std::string()); | 131 ExtensionAndSubchannelToObjectId(extension->id(), i), i, std::string()); |
| 133 } | 132 } |
| 134 | 133 |
| 135 EmitInvalidation( | 134 EmitInvalidation( |
| 136 ExtensionAndSubchannelToObjectId(extension->id(), 1), "payload"); | 135 ExtensionAndSubchannelToObjectId(extension->id(), 1), 5, "payload"); |
| 137 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 136 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 138 } | 137 } |
| 139 | 138 |
| 140 // Checks that an extension with the pushMessaging permission gets automatically | 139 // Checks that an extension with the pushMessaging permission gets automatically |
| 141 // registered for invalidations when it is loaded. | 140 // registered for invalidations when it is loaded. |
| 142 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { | 141 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { |
| 143 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( | 142 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( |
| 144 new StrictMock<MockInvalidationMapper>); | 143 new StrictMock<MockInvalidationMapper>); |
| 145 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); | 144 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); |
| 146 // PushMessagingEventRouter owns the mapper now. | 145 // PushMessagingEventRouter owns the mapper now. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 const extensions::Extension* extension = | 187 const extensions::Extension* extension = |
| 189 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); | 188 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); |
| 190 ASSERT_TRUE(extension); | 189 ASSERT_TRUE(extension); |
| 191 ui_test_utils::NavigateToURL( | 190 ui_test_utils::NavigateToURL( |
| 192 browser(), extension->GetResourceURL("get_channel_id.html")); | 191 browser(), extension->GetResourceURL("get_channel_id.html")); |
| 193 | 192 |
| 194 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 193 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 195 } | 194 } |
| 196 | 195 |
| 197 } // namespace extensions | 196 } // namespace extensions |
| OLD | NEW |