Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: chrome/browser/extensions/api/push_messaging/push_messaging_apitest.cc

Issue 10826156: Plumb invalidations from Tango to the extensions code for the Push Messaging API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix gmock and maybe Android build Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_mapper.h"
6 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/extensions/extension_system.h"
8 #include "chrome/browser/extensions/extension_test_message_listener.h" 10 #include "chrome/browser/extensions/extension_test_message_listener.h"
9 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
12 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16
17 using ::testing::_;
18 using ::testing::SaveArg;
19 using ::testing::StrictMock;
13 20
14 namespace extensions { 21 namespace extensions {
15 22
23 class MockInvalidationMapper : public PushMessagingInvalidationMapper {
24 public:
25 MockInvalidationMapper();
26 ~MockInvalidationMapper();
27
28 MOCK_METHOD1(RegisterExtension, void(const std::string&));
29 MOCK_METHOD1(UnregisterExtension, void(const std::string&));
30 };
31
32 MockInvalidationMapper::MockInvalidationMapper() {}
33 MockInvalidationMapper::~MockInvalidationMapper() {}
34
16 class PushMessagingApiTest : public ExtensionApiTest { 35 class PushMessagingApiTest : public ExtensionApiTest {
17 public: 36 public:
18 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
19 ExtensionApiTest::SetUpCommandLine(command_line); 38 ExtensionApiTest::SetUpCommandLine(command_line);
20 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 39 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
21 } 40 }
22 }; 41 };
23 42
Pete Williamson 2012/08/13 18:24:09 Should we also have a unit test for the "Init()" m
dcheng 2012/08/13 20:44:14 This wasn't originally possible since it would req
24 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) { 43 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, EventDispatch) {
25 ResultCatcher catcher; 44 ResultCatcher catcher;
26 catcher.RestrictToProfile(browser()->profile()); 45 catcher.RestrictToProfile(browser()->profile());
27 46
28 ExtensionTestMessageListener ready("ready", true); 47 ExtensionTestMessageListener ready("ready", true);
29 const extensions::Extension* extension = 48 const extensions::Extension* extension =
30 LoadExtension(test_data_dir_.AppendASCII("push_messaging")); 49 LoadExtension(test_data_dir_.AppendASCII("push_messaging"));
31 ASSERT_TRUE(extension); 50 ASSERT_TRUE(extension);
32 GURL page_url = extension->GetResourceURL("event_dispatch.html"); 51 GURL page_url = extension->GetResourceURL("event_dispatch.html");
33 ui_test_utils::NavigateToURL(browser(), page_url); 52 ui_test_utils::NavigateToURL(browser(), page_url);
34 EXPECT_TRUE(ready.WaitUntilSatisfied()); 53 EXPECT_TRUE(ready.WaitUntilSatisfied());
35 54
36 // Trigger a callback. 55 // Trigger a callback.
37 browser()->profile()->GetExtensionService()-> 56 ExtensionSystem::Get(browser()->profile())->extension_service()->
38 push_messaging_event_router()->OnMessage( 57 push_messaging_event_router()->OnMessage(
39 extension->id(), 1, "payload"); 58 extension->id(), 1, "payload");
40 59
41 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 60 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
42 } 61 }
43 62
63 // Checks that an extension with the pushMessaging permission gets automatically
64 // registered for invalidations when it is loaded.
65 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) {
66 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper(
67 new StrictMock<MockInvalidationMapper>);
68 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get();
69 // PushMessagingEventRouter owns the mapper now.
70 ExtensionSystem::Get(browser()->profile())->extension_service()->
71 push_messaging_event_router()->SetMapperForTest(
72 mapper.PassAs<PushMessagingInvalidationMapper>());
73
74 std::string extension_id;
75 EXPECT_CALL(*unsafe_mapper, RegisterExtension(_))
76 .WillOnce(SaveArg<0>(&extension_id));
77 const extensions::Extension* extension =
78 LoadExtension(test_data_dir_.AppendASCII("push_messaging"));
79 ASSERT_TRUE(extension);
80 EXPECT_EQ(extension->id(), extension_id);
81 EXPECT_CALL(*unsafe_mapper, UnregisterExtension(extension->id()));
82 UnloadExtension(extension->id());
83 }
84
44 } // namespace extensions 85 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698