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

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

Issue 10915216: Browser test for the push messaging feature (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: CR changes per DCheng Created 8 years, 3 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
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_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
24 // TODO(dcheng): This is hardcoded for now since the svn export is not done yet.
25 // Once it's done, use ipc::invalidation::ObjectSource::CHROME_PUSH_MESSAGING.
26 const int kSourceId = 1030;
27
22 namespace extensions { 28 namespace extensions {
23 29
24 class MockInvalidationMapper : public PushMessagingInvalidationMapper { 30 class MockInvalidationMapper : public PushMessagingInvalidationMapper {
25 public: 31 public:
26 MockInvalidationMapper(); 32 MockInvalidationMapper();
27 ~MockInvalidationMapper(); 33 ~MockInvalidationMapper();
28 34
29 MOCK_METHOD1(RegisterExtension, void(const std::string&)); 35 MOCK_METHOD1(RegisterExtension, void(const std::string&));
30 MOCK_METHOD1(UnregisterExtension, void(const std::string&)); 36 MOCK_METHOD1(UnregisterExtension, void(const std::string&));
31 }; 37 };
(...skipping 24 matching lines...) Expand all
56 ASSERT_TRUE(extension); 62 ASSERT_TRUE(extension);
57 GURL page_url = extension->GetResourceURL("event_dispatch.html"); 63 GURL page_url = extension->GetResourceURL("event_dispatch.html");
58 ui_test_utils::NavigateToURL(browser(), page_url); 64 ui_test_utils::NavigateToURL(browser(), page_url);
59 EXPECT_TRUE(ready.WaitUntilSatisfied()); 65 EXPECT_TRUE(ready.WaitUntilSatisfied());
60 66
61 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload"); 67 GetEventRouter()->TriggerMessageForTest(extension->id(), 1, "payload");
62 68
63 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 69 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
64 } 70 }
65 71
72 // Test that a push introduced into the sync code makes it to the extension
73 // that we install.
74 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, ReceivesPush) {
75 ResultCatcher catcher;
76 catcher.RestrictToProfile(browser()->profile());
77 ExtensionTestMessageListener ready("ready", true);
78
79 const extensions::Extension* extension =
80 LoadExtension(test_data_dir_.AppendASCII("push_messaging"));
81 ASSERT_TRUE(extension);
82 GURL page_url = extension->GetResourceURL("event_dispatch.html");
83 ui_test_utils::NavigateToURL(browser(), page_url);
84 EXPECT_TRUE(ready.WaitUntilSatisfied());
85
86 ProfileSyncService* pss = ProfileSyncServiceFactory::GetForProfile(
87 browser()->profile());
88 ASSERT_TRUE(pss);
89
90 // Construct a sync id for the object "U/<extension-id>/1".
91 std::string id("U/");
92 id += extension->id();
93 id += "/1";
94
95 invalidation::ObjectId objId(kSourceId, id);
dcheng 2012/09/17 21:00:56 See next comment about naming.
96
97 pss->SendInvalidationForTest(objId, "payload");
98 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
99 }
100
66 // Checks that an extension with the pushMessaging permission gets automatically 101 // Checks that an extension with the pushMessaging permission gets automatically
67 // registered for invalidations when it is loaded. 102 // registered for invalidations when it is loaded.
68 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) { 103 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, AutoRegistration) {
69 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper( 104 scoped_ptr<StrictMock<MockInvalidationMapper> > mapper(
70 new StrictMock<MockInvalidationMapper>); 105 new StrictMock<MockInvalidationMapper>);
71 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get(); 106 StrictMock<MockInvalidationMapper>* unsafe_mapper = mapper.get();
72 // PushMessagingEventRouter owns the mapper now. 107 // PushMessagingEventRouter owns the mapper now.
73 GetEventRouter()->SetMapperForTest( 108 GetEventRouter()->SetMapperForTest(
74 mapper.PassAs<PushMessagingInvalidationMapper>()); 109 mapper.PassAs<PushMessagingInvalidationMapper>());
75 110
(...skipping 20 matching lines...) Expand all
96 } 131 }
97 132
98 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) { 133 IN_PROC_BROWSER_TEST_F(PushMessagingApiTest, Restart) {
99 PushMessagingInvalidationHandler* handler = 134 PushMessagingInvalidationHandler* handler =
100 static_cast<PushMessagingInvalidationHandler*>( 135 static_cast<PushMessagingInvalidationHandler*>(
101 GetEventRouter()->GetMapperForTest()); 136 GetEventRouter()->GetMapperForTest());
102 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size()); 137 EXPECT_EQ(1U, handler->GetRegisteredExtensionsForTest().size());
103 } 138 }
104 139
105 } // namespace extensions 140 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/profile_sync_service.h » ('j') | chrome/browser/sync/profile_sync_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698