| Index: chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc
|
| diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc
|
| index c78f77a75f32ed901370b9a70b1916239277d7bb..c863fd93fdcbad65ca43aa61208377cfdc743451 100644
|
| --- a/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc
|
| +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc
|
| @@ -3,16 +3,34 @@
|
| // found in the LICENSE file.
|
|
|
| #include "chrome/browser/extensions/api/push_messaging/push_messaging_api.h"
|
| +#include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidation_mapper.h"
|
| #include "chrome/browser/extensions/extension_apitest.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/extensions/extension_system.h"
|
| #include "chrome/browser/extensions/extension_test_message_listener.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/common/chrome_switches.h"
|
| #include "chrome/test/base/ui_test_utils.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +
|
| +using ::testing::MatchesRegex;
|
| +using ::testing::StrictMock;
|
|
|
| namespace extensions {
|
|
|
| +class MockInvalidationMapper : public PushMessagingInvalidationMapper {
|
| + public:
|
| + MockInvalidationMapper();
|
| + ~MockInvalidationMapper();
|
| +
|
| + MOCK_METHOD1(RegisterExtension, void(const std::string&));
|
| + MOCK_METHOD1(UnregisterExtension, void(const std::string&));
|
| +};
|
| +
|
| +MockInvalidationMapper::MockInvalidationMapper() {}
|
| +MockInvalidationMapper::~MockInvalidationMapper() {}
|
| +
|
| class PushMessagingApiTest : public ExtensionApiTest {
|
| public:
|
| virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
|
| @@ -34,11 +52,31 @@ IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) {
|
| EXPECT_TRUE(ready.WaitUntilSatisfied());
|
|
|
| // Trigger a callback.
|
| - browser()->profile()->GetExtensionService()->
|
| + ExtensionSystem::Get(browser()->profile())->extension_service()->
|
| push_messaging_event_router()->OnMessage(
|
| extension->id(), 1, "payload");
|
|
|
| EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
|
| }
|
|
|
| +// Checks that an extension with the pushMessaging permission gets automatically
|
| +// registered for invalidations when it is loaded.
|
| +IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) {
|
| + // The odd ordering allows us to avoid ugly casts here and when passing
|
| + // ownership to PushMessagingEventRouter.
|
| + StrictMock<MockInvalidationMapper>* unsafe_mapper =
|
| + new StrictMock<MockInvalidationMapper>;
|
| + scoped_ptr<PushMessagingInvalidationMapper> mapper(unsafe_mapper);
|
| + // PushMessagingEventRouter owns the mapper now.
|
| + ExtensionSystem::Get(browser()->profile())->extension_service()->
|
| + push_messaging_event_router()->SetMapperForTest(mapper.Pass());
|
| +
|
| + EXPECT_CALL(*unsafe_mapper, RegisterExtension(MatchesRegex("[a-p]{32}")));
|
| + const extensions::Extension* extension =
|
| + LoadExtension(test_data_dir_.AppendASCII("push_messaging"));
|
| + ASSERT_TRUE(extension);
|
| + EXPECT_CALL(*unsafe_mapper, UnregisterExtension(extension->id()));
|
| + UnloadExtension(extension->id());
|
| +}
|
| +
|
| } // namespace extensions
|
|
|