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

Side by Side Diff: chrome/browser/extensions/api/notification_provider/notification_provider_apitest.cc

Issue 441753002: Route newly created notifications to notification provider API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: bug fix Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/notification_provider/notification_provi der_api.h" 5 #include "chrome/browser/extensions/api/notification_provider/notification_provi der_api.h"
6 #include "chrome/browser/extensions/chrome_extension_function.h" 6 #include "chrome/browser/extensions/chrome_extension_function.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/extensions/api/notification_provider.h" 9 #include "chrome/common/extensions/api/notification_provider.h"
10 10
11 typedef ExtensionApiTest NotificationProviderApiTest; 11 typedef ExtensionApiTest NotificationProviderApiTest;
12 12
13 namespace { 13 namespace {
14 14
15 void CreateNotificationOptionsForTest( 15 void CreateNotificationOptionsForTest(
16 extensions::api::notifications::NotificationOptions* options) { 16 extensions::api::notifications::NotificationOptions* options) {
17 options->type = extensions::api::notifications::ParseTemplateType("basic"); 17 options->type = extensions::api::notifications::ParseTemplateType("basic");
18 options->icon_url = scoped_ptr<std::string>(new std::string("icon.png")); 18 options->icon_url = scoped_ptr<std::string>(new std::string("icon.png"));
19 options->title = scoped_ptr<std::string>(new std::string("Title")); 19 options->title = scoped_ptr<std::string>(new std::string("Title"));
20 options->message = 20 options->message =
21 scoped_ptr<std::string>(new std::string("Here goes the message")); 21 scoped_ptr<std::string>(new std::string("Here goes the message"));
22 return; 22 return;
23 } 23 }
24 24
25 } // namespace 25 } // namespace
26 26
27 IN_PROC_BROWSER_TEST_F(NotificationProviderApiTest, Events) { 27 IN_PROC_BROWSER_TEST_F(NotificationProviderApiTest, Events) {
28 std::string sender_id1 = "SenderId1"; 28 ASSERT_TRUE(RunExtensionTest("notification_provider/events")) << message_;
29 std::string notification_id1 = "NotificationId1";
30
31 scoped_ptr<extensions::api::notifications::NotificationOptions> options(
32 new extensions::api::notifications::NotificationOptions());
33 CreateNotificationOptionsForTest(options.get());
34
35 ResultCatcher catcher;
36 catcher.RestrictToProfile(browser()->profile());
37
38 // Test notification provider extension
39 const extensions::Extension* extension =
40 LoadExtension(test_data_dir_.AppendASCII("notification_provider/events"));
41 ASSERT_TRUE(extension);
42
43 scoped_ptr<extensions::NotificationProviderEventRouter> event_router(
44 new extensions::NotificationProviderEventRouter(browser()->profile()));
45
46 event_router->CreateNotification(
47 extension->id(), sender_id1, notification_id1, *options);
48 event_router->UpdateNotification(
49 extension->id(), sender_id1, notification_id1, *options);
50 event_router->ClearNotification(
51 extension->id(), sender_id1, notification_id1);
52
53 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
54 } 29 }
55 30
56 IN_PROC_BROWSER_TEST_F(NotificationProviderApiTest, TestBasicUsage) { 31 IN_PROC_BROWSER_TEST_F(NotificationProviderApiTest, TestBasicUsage) {
57 // set up content of a notification 32 // set up content of a notification
58 std::string sender_id1 = "SenderId"; 33 std::string sender_id1 = "SenderId";
59 std::string notification_id1 = "NotificationId"; 34 std::string notification_id1 = "NotificationId";
60 35
61 scoped_ptr<extensions::api::notifications::NotificationOptions> options( 36 scoped_ptr<extensions::api::notifications::NotificationOptions> options(
62 new extensions::api::notifications::NotificationOptions()); 37 new extensions::api::notifications::NotificationOptions());
63 CreateNotificationOptionsForTest(options.get()); 38 CreateNotificationOptionsForTest(options.get());
64 39
65 ResultCatcher catcher; 40 ResultCatcher catcher;
66 catcher.RestrictToProfile(browser()->profile()); 41 catcher.RestrictToProfile(browser()->profile());
67 42
68 // Test notification provider extension 43 // Test notification provider extension
69 const extensions::Extension* extension = LoadExtension( 44 const extensions::Extension* extension = LoadExtension(
70 test_data_dir_.AppendASCII("notification_provider/basic_usage")); 45 test_data_dir_.AppendASCII("notification_provider/basic_usage"));
71 ASSERT_TRUE(extension); 46 ASSERT_TRUE(extension);
72 47
73 scoped_ptr<extensions::NotificationProviderEventRouter> event_router( 48 scoped_ptr<extensions::NotificationProviderEventRouter> event_router(
74 new extensions::NotificationProviderEventRouter(browser()->profile())); 49 new extensions::NotificationProviderEventRouter(browser()->profile()));
75 50
76 event_router->CreateNotification( 51 event_router->CreateNotification(
77 extension->id(), sender_id1, notification_id1, *options); 52 extension->id(), sender_id1, notification_id1, *options);
78 53
79 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 54 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
80 } 55 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698