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

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_apitest.cc

Issue 12313115: Take notification API out of experimental. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Missed one pathname. Created 7 years, 9 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/browser_process.h" 5 #include "chrome/browser/browser_process.h"
6 #include "chrome/browser/extensions/api/notification/notification_api.h" 6 #include "chrome/browser/extensions/api/notifications/notifications_api.h"
7 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/extensions/extension_function_test_utils.h" 8 #include "chrome/browser/extensions/extension_function_test_utils.h"
9 #include "chrome/common/chrome_notification_types.h" 9 #include "chrome/common/chrome_notification_types.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/extensions/features/feature.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
12 #include "content/public/test/test_utils.h" 13 #include "content/public/test/test_utils.h"
13 #include "ui/message_center/message_center.h" 14 #include "ui/message_center/message_center.h"
14 #include "ui/message_center/message_center_util.h" 15 #include "ui/message_center/message_center_util.h"
15 16
16 using extensions::Extension; 17 using extensions::Extension;
17 18
18 namespace utils = extension_function_test_utils; 19 namespace utils = extension_function_test_utils;
19 20
20 namespace { 21 namespace {
21 22
22 class NotificationApiTest : public ExtensionApiTest { 23 class NotificationsApiTest : public ExtensionApiTest {
23 public: 24 public:
24 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 25 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
25 ExtensionApiTest::SetUpCommandLine(command_line); 26 ExtensionApiTest::SetUpCommandLine(command_line);
26 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 27 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
27 } 28 }
28 29
29 const extensions::Extension* LoadExtensionAndWait( 30 const extensions::Extension* LoadExtensionAndWait(
30 const std::string& test_name) { 31 const std::string& test_name) {
31 base::FilePath extdir = test_data_dir_.AppendASCII(test_name); 32 base::FilePath extdir = test_data_dir_.AppendASCII(test_name);
32 content::WindowedNotificationObserver page_created( 33 content::WindowedNotificationObserver page_created(
33 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY, 34 chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
34 content::NotificationService::AllSources()); 35 content::NotificationService::AllSources());
35 const extensions::Extension* extension = LoadExtension(extdir); 36 const extensions::Extension* extension = LoadExtension(extdir);
36 if (extension) { 37 if (extension) {
37 page_created.Wait(); 38 page_created.Wait();
38 } 39 }
39 return extension; 40 return extension;
40 } 41 }
41 }; 42 };
42 43
43 } // namespace 44 } // namespace
44 45
45 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestIdUsage) { 46 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestIdUsage) {
46 // Create a new notification. A lingering output of this block is the 47 // Create a new notifications. A lingering output of this block is the
47 // notification ID, which we'll use in later parts of this test. 48 // notifications ID, which we'll use in later parts of this test.
48 std::string notification_id; 49 std::string notification_id;
49 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 50 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
50 { 51 {
51 scoped_refptr<extensions::NotificationCreateFunction> 52 scoped_refptr<extensions::NotificationsCreateFunction>
52 notification_function( 53 notification_function(
53 new extensions::NotificationCreateFunction()); 54 new extensions::NotificationsCreateFunction());
54 55
55 notification_function->set_extension(empty_extension.get()); 56 notification_function->set_extension(empty_extension.get());
56 notification_function->set_has_callback(true); 57 notification_function->set_has_callback(true);
57 58
58 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 59 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
59 notification_function, 60 notification_function,
60 "[\"\", " // Empty string: ask API to generate ID 61 "[\"\", " // Empty string: ask API to generate ID
61 "{" 62 "{"
62 "\"templateType\": \"simple\"," 63 "\"templateType\": \"simple\","
63 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," 64 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
64 "\"title\": \"Attention!\"," 65 "\"title\": \"Attention!\","
65 "\"message\": \"Check out Cirque du Soleil\"" 66 "\"message\": \"Check out Cirque du Soleil\""
66 "}]", 67 "}]",
67 browser(), utils::NONE)); 68 browser(), utils::NONE));
68 69
69 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 70 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
70 ASSERT_TRUE(result->GetAsString(&notification_id)); 71 ASSERT_TRUE(result->GetAsString(&notification_id));
71 ASSERT_TRUE(notification_id.length() > 0); 72 ASSERT_TRUE(notification_id.length() > 0);
72 } 73 }
73 74
74 // Update the existing notification. 75 // Update the existing notifications.
75 { 76 {
76 scoped_refptr<extensions::NotificationUpdateFunction> 77 scoped_refptr<extensions::NotificationsUpdateFunction>
77 notification_function( 78 notification_function(
78 new extensions::NotificationUpdateFunction()); 79 new extensions::NotificationsUpdateFunction());
79 80
80 notification_function->set_extension(empty_extension.get()); 81 notification_function->set_extension(empty_extension.get());
81 notification_function->set_has_callback(true); 82 notification_function->set_has_callback(true);
82 83
83 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 84 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
84 notification_function, 85 notification_function,
85 "[\"" + notification_id + "\", " 86 "[\"" + notification_id + "\", "
86 "{" 87 "{"
87 "\"templateType\": \"simple\"," 88 "\"templateType\": \"simple\","
88 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," 89 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
89 "\"title\": \"Attention!\"," 90 "\"title\": \"Attention!\","
90 "\"message\": \"Too late! The show ended yesterday\"" 91 "\"message\": \"Too late! The show ended yesterday\""
91 "}]", 92 "}]",
92 browser(), utils::NONE)); 93 browser(), utils::NONE));
93 94
94 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 95 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
95 bool copy_bool_value = false; 96 bool copy_bool_value = false;
96 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value)); 97 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
97 ASSERT_TRUE(copy_bool_value); 98 ASSERT_TRUE(copy_bool_value);
98 99
99 // TODO(miket): add a testing method to query the message from the 100 // TODO(miket): add a testing method to query the message from the
100 // displayed notification, and assert it matches the updated message. 101 // displayed notifications, and assert it matches the updated message.
101 // 102 //
102 // TODO(miket): add a method to count the number of outstanding 103 // TODO(miket): add a method to count the number of outstanding
103 // notifications, and confirm it remains at one at this point. 104 // notifications, and confirm it remains at one at this point.
104 } 105 }
105 106
106 // Update a nonexistent notification. 107 // Update a nonexistent notifications.
107 { 108 {
108 scoped_refptr<extensions::NotificationUpdateFunction> 109 scoped_refptr<extensions::NotificationsUpdateFunction>
109 notification_function( 110 notification_function(
110 new extensions::NotificationUpdateFunction()); 111 new extensions::NotificationsUpdateFunction());
111 112
112 notification_function->set_extension(empty_extension.get()); 113 notification_function->set_extension(empty_extension.get());
113 notification_function->set_has_callback(true); 114 notification_function->set_has_callback(true);
114 115
115 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 116 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
116 notification_function, 117 notification_function,
117 "[\"xxxxxxxxxxxx\", " 118 "[\"xxxxxxxxxxxx\", "
118 "{" 119 "{"
119 "\"templateType\": \"simple\"," 120 "\"templateType\": \"simple\","
120 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," 121 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
121 "\"title\": \"!\"," 122 "\"title\": \"!\","
122 "\"message\": \"!\"" 123 "\"message\": \"!\""
123 "}]", 124 "}]",
124 browser(), utils::NONE)); 125 browser(), utils::NONE));
125 126
126 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 127 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
127 bool copy_bool_value = false; 128 bool copy_bool_value = false;
128 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value)); 129 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
129 ASSERT_FALSE(copy_bool_value); 130 ASSERT_FALSE(copy_bool_value);
130 } 131 }
131 132
132 // Clear a nonexistent notification. 133 // Clear a nonexistent notifications.
133 { 134 {
134 scoped_refptr<extensions::NotificationClearFunction> 135 scoped_refptr<extensions::NotificationsClearFunction>
135 notification_function( 136 notification_function(
136 new extensions::NotificationClearFunction()); 137 new extensions::NotificationsClearFunction());
137 138
138 notification_function->set_extension(empty_extension.get()); 139 notification_function->set_extension(empty_extension.get());
139 notification_function->set_has_callback(true); 140 notification_function->set_has_callback(true);
140 141
141 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 142 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
142 notification_function, 143 notification_function,
143 "[\"xxxxxxxxxxx\"]", browser(), utils::NONE)); 144 "[\"xxxxxxxxxxx\"]", browser(), utils::NONE));
144 145
145 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 146 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
146 bool copy_bool_value = false; 147 bool copy_bool_value = false;
147 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value)); 148 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
148 ASSERT_FALSE(copy_bool_value); 149 ASSERT_FALSE(copy_bool_value);
149 } 150 }
150 151
151 // Clear the notification we created. 152 // Clear the notifications we created.
152 { 153 {
153 scoped_refptr<extensions::NotificationClearFunction> 154 scoped_refptr<extensions::NotificationsClearFunction>
154 notification_function( 155 notification_function(
155 new extensions::NotificationClearFunction()); 156 new extensions::NotificationsClearFunction());
156 157
157 notification_function->set_extension(empty_extension.get()); 158 notification_function->set_extension(empty_extension.get());
158 notification_function->set_has_callback(true); 159 notification_function->set_has_callback(true);
159 160
160 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 161 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
161 notification_function, 162 notification_function,
162 "[\"" + notification_id + "\"]", browser(), utils::NONE)); 163 "[\"" + notification_id + "\"]", browser(), utils::NONE));
163 164
164 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType()); 165 ASSERT_EQ(base::Value::TYPE_BOOLEAN, result->GetType());
165 bool copy_bool_value = false; 166 bool copy_bool_value = false;
166 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value)); 167 ASSERT_TRUE(result->GetAsBoolean(&copy_bool_value));
167 ASSERT_TRUE(copy_bool_value); 168 ASSERT_TRUE(copy_bool_value);
168 } 169 }
169 } 170 }
170 171
171 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestBaseFormatNotification) { 172 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestBaseFormatNotification) {
172 scoped_refptr<extensions::NotificationCreateFunction> 173 scoped_refptr<extensions::NotificationsCreateFunction>
173 notification_create_function( 174 notification_create_function(
174 new extensions::NotificationCreateFunction()); 175 new extensions::NotificationsCreateFunction());
175 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 176 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
176 177
177 notification_create_function->set_extension(empty_extension.get()); 178 notification_create_function->set_extension(empty_extension.get());
178 notification_create_function->set_has_callback(true); 179 notification_create_function->set_has_callback(true);
179 180
180 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 181 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
181 notification_create_function, 182 notification_create_function,
182 "[\"\", " 183 "[\"\", "
183 "{" 184 "{"
184 "\"templateType\": \"basic\"," 185 "\"templateType\": \"basic\","
(...skipping 15 matching lines...) Expand all
200 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\"" 201 "\"imageUrl\": \"http://www.google.com/logos/2012/election12-hp.jpg\""
201 "}]", 202 "}]",
202 browser(), utils::NONE)); 203 browser(), utils::NONE));
203 204
204 std::string notification_id; 205 std::string notification_id;
205 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 206 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
206 ASSERT_TRUE(result->GetAsString(&notification_id)); 207 ASSERT_TRUE(result->GetAsString(&notification_id));
207 ASSERT_TRUE(notification_id.length() > 0); 208 ASSERT_TRUE(notification_id.length() > 0);
208 } 209 }
209 210
210 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestMultipleItemNotification) { 211 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestMultipleItemNotification) {
211 scoped_refptr<extensions::NotificationCreateFunction> 212 scoped_refptr<extensions::NotificationsCreateFunction>
212 notification_create_function( 213 notification_create_function(
213 new extensions::NotificationCreateFunction()); 214 new extensions::NotificationsCreateFunction());
214 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension()); 215 scoped_refptr<Extension> empty_extension(utils::CreateEmptyExtension());
215 216
216 notification_create_function->set_extension(empty_extension.get()); 217 notification_create_function->set_extension(empty_extension.get());
217 notification_create_function->set_has_callback(true); 218 notification_create_function->set_has_callback(true);
218 219
219 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult( 220 scoped_ptr<base::Value> result(utils::RunFunctionAndReturnSingleResult(
220 notification_create_function, 221 notification_create_function,
221 "[\"\", " 222 "[\"\", "
222 "{" 223 "{"
223 "\"templateType\": \"list\"," 224 "\"templateType\": \"list\","
224 "\"iconUrl\": \"an/image/that/does/not/exist.png\"," 225 "\"iconUrl\": \"an/image/that/does/not/exist.png\","
225 "\"title\": \"Multiple Item Notification Title\"," 226 "\"title\": \"Multiple Item Notification Title\","
226 "\"message\": \"Multiple item notification message.\"," 227 "\"message\": \"Multiple item notifications message.\","
dharcourt 2013/03/04 23:46:27 Nit: Should be "Multiple item notification message
227 "\"items\": [" 228 "\"items\": ["
228 " {\"title\": \"Brett Boe\"," 229 " {\"title\": \"Brett Boe\","
229 " \"message\": \"This is an important message!\"}," 230 " \"message\": \"This is an important message!\"},"
230 " {\"title\": \"Carla Coe\"," 231 " {\"title\": \"Carla Coe\","
231 " \"message\": \"Just took a look at the proposal\"}," 232 " \"message\": \"Just took a look at the proposal\"},"
232 " {\"title\": \"Donna Doe\"," 233 " {\"title\": \"Donna Doe\","
233 " \"message\": \"I see that you went to the conference\"}," 234 " \"message\": \"I see that you went to the conference\"},"
234 " {\"title\": \"Frank Foe\"," 235 " {\"title\": \"Frank Foe\","
235 " \"message\": \"I ate Harry's sandwich!\"}," 236 " \"message\": \"I ate Harry's sandwich!\"},"
236 " {\"title\": \"Grace Goe\"," 237 " {\"title\": \"Grace Goe\","
237 " \"message\": \"I saw Frank steal a sandwich :-)\"}" 238 " \"message\": \"I saw Frank steal a sandwich :-)\"}"
238 "]," 239 "],"
239 "\"priority\": 1," 240 "\"priority\": 1,"
240 "\"eventTime\": 1361488019.9999999" 241 "\"eventTime\": 1361488019.9999999"
241 "}]", 242 "}]",
242 browser(), utils::NONE)); 243 browser(), utils::NONE));
243 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...] 244 // TODO(dharcourt): [...], items = [{title: foo, message: bar}, ...], [...]
244 245
245 std::string notification_id; 246 std::string notification_id;
246 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType()); 247 ASSERT_EQ(base::Value::TYPE_STRING, result->GetType());
247 ASSERT_TRUE(result->GetAsString(&notification_id)); 248 ASSERT_TRUE(result->GetAsString(&notification_id));
248 ASSERT_TRUE(notification_id.length() > 0); 249 ASSERT_TRUE(notification_id.length() > 0);
249 } 250 }
250 251
251 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestEvents) { 252 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestEvents) {
252 ASSERT_TRUE(RunExtensionTest("notification/api/events")) << message_; 253 ASSERT_TRUE(RunExtensionTest("notifications/api/events")) << message_;
253 } 254 }
254 255
255 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestCSP) { 256 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestCSP) {
256 ASSERT_TRUE(RunExtensionTest("notification/api/csp")) << message_; 257 ASSERT_TRUE(RunExtensionTest("notifications/api/csp")) << message_;
257 } 258 }
258 259
259 #ifdef ENABLE_MESSAGE_CENTER 260 #ifdef ENABLE_MESSAGE_CENTER
260 #if !defined(OS_WIN) || !defined(USE_ASH) 261 #if !defined(OS_WIN) || !defined(USE_ASH)
261 262
262 IN_PROC_BROWSER_TEST_F(NotificationApiTest, TestByUser) { 263 IN_PROC_BROWSER_TEST_F(NotificationsApiTest, TestByUser) {
263 if (!message_center::IsRichNotificationEnabled()) 264 if (!message_center::IsRichNotificationEnabled())
264 return; 265 return;
265 266
266 const extensions::Extension* extension = 267 const extensions::Extension* extension =
267 LoadExtensionAndWait("notification/api/by_user"); 268 LoadExtensionAndWait("notifications/api/by_user");
268 ASSERT_TRUE(extension) << message_; 269 ASSERT_TRUE(extension) << message_;
269 270
270 { 271 {
271 ResultCatcher catcher; 272 ResultCatcher catcher;
272 g_browser_process->message_center()->SendRemoveNotification( 273 g_browser_process->message_center()->SendRemoveNotification(
273 extension->id() + "-FOO", 274 extension->id() + "-FOO",
274 false); 275 false);
275 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 276 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
276 } 277 }
277 278
(...skipping 13 matching lines...) Expand all
291 292
292 { 293 {
293 ResultCatcher catcher; 294 ResultCatcher catcher;
294 g_browser_process->message_center()->SendRemoveAllNotifications(true); 295 g_browser_process->message_center()->SendRemoveAllNotifications(true);
295 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); 296 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
296 } 297 }
297 } 298 }
298 299
299 #endif 300 #endif
300 #endif 301 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698