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

Side by Side Diff: chrome/browser/notifications/notification_browsertest.cc

Issue 11359174: Convert HTML5 notification pyauto tests to browser_tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from Ken. Created 8 years, 1 month 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
« no previous file with comments | « no previous file | chrome/test/data/notifications/notification_tester.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "base/stringprintf.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h"
11 #include "chrome/browser/api/infobars/infobar_delegate.h"
12 #include "chrome/browser/browser_process.h"
5 #include "chrome/browser/infobars/infobar_tab_helper.h" 13 #include "chrome/browser/infobars/infobar_tab_helper.h"
14 #include "chrome/browser/notifications/balloon.h"
15 #include "chrome/browser/notifications/balloon_collection.h"
16 #include "chrome/browser/notifications/balloon_host.h"
17 #include "chrome/browser/notifications/desktop_notification_service.h"
18 #include "chrome/browser/notifications/desktop_notification_service_factory.h"
19 #include "chrome/browser/notifications/notification.h"
20 #include "chrome/browser/notifications/notification_ui_manager.h"
21 #include "chrome/browser/profiles/profile.h"
22 #include "chrome/browser/sessions/session_tab_helper.h"
6 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_commands.h"
7 #include "chrome/browser/ui/browser_tabstrip.h" 25 #include "chrome/browser/ui/browser_tabstrip.h"
26 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents.h"
28 #include "chrome/common/chrome_notification_types.h"
8 #include "chrome/test/base/in_process_browser_test.h" 29 #include "chrome/test/base/in_process_browser_test.h"
9 #include "chrome/test/base/ui_test_utils.h" 30 #include "chrome/test/base/ui_test_utils.h"
31 #include "content/public/browser/navigation_controller.h"
32 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/notification_types.h"
10 #include "content/public/browser/web_contents.h" 34 #include "content/public/browser/web_contents.h"
11 #include "content/public/test/browser_test_utils.h" 35 #include "content/public/test/browser_test_utils.h"
36 #include "googleurl/src/gurl.h"
12 #include "net/base/net_util.h" 37 #include "net/base/net_util.h"
13 #include "net/test/test_server.h" 38 #include "net/test/test_server.h"
14 39 #include "webkit/glue/window_open_disposition.h"
15 class NotificationsPermissionTest : public InProcessBrowserTest { 40
41 #if defined(OS_WIN)
42 #include "base/win/windows_version.h"
43 #endif
44
45 namespace {
46 const std::string kReference = "preference";
kkania 2012/11/15 16:29:07 don't indent stuff inside namespace, but leave new
kkania 2012/11/15 16:29:07 http://google-styleguide.googlecode.com/svn/trunk/
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
47 const std::string kExpectedIconUrl = "files/notifications/no_such_file.png";
kkania 2012/11/15 16:29:07 http://google-styleguide.googlecode.com/svn/trunk/
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
48
49 enum InfobarAction {
50 DISMISS = 0,
51 ALLOW = 1,
52 DENY = 2,
53 };
54
55 class BrowserOpenedNotificationObserver :
56 public content::NotificationObserver {
57 public:
58 BrowserOpenedNotificationObserver();
59 virtual ~BrowserOpenedNotificationObserver();
60
61 void Wait();
62 Browser* new_browser() { return new_browser_; }
63
64 virtual void Observe(int type,
65 const content::NotificationSource& source,
66 const content::NotificationDetails& details) OVERRIDE;
67 private:
68 content::NotificationRegistrar registrar_;
69 Browser* new_browser_;
70 int new_window_id_;
71 bool done_;
72 bool running_;
73 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
74
75 DISALLOW_COPY_AND_ASSIGN(BrowserOpenedNotificationObserver);
76 };
77 }
78
79 class NotificationsPermissionTest : public InProcessBrowserTest,
80 public content::NotificationObserver {
16 public: 81 public:
17 NotificationsPermissionTest() {} 82 NotificationsPermissionTest();
83
84 protected:
85 // Overriden from InProcessBrowserTest:
86 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
87
88 // Overriden from content::NotificationObserver:
89 virtual void Observe(int type,
90 const content::NotificationSource& source,
91 const content::NotificationDetails& details) OVERRIDE;
92
93 DesktopNotificationService* GetDesktopNotificationService();
94 const std::deque<Balloon*>& GetActiveBalloons();
95 int GetNotificationCount();
96
97 bool CloseNotificationAndWait(const Notification& notification);
98 bool WaitForInfoBarCount(Browser* browser,
99 size_t count,
100 int index,
101 bool increasing);
102 Browser* CreateBrowserWindow(Browser* source_browser, bool is_incognito);
103 void CloseBrowserWindow(Browser* browser);
104 void CrashTab(Browser* browser, int index);
105 void CrashNotification(Balloon* balloon);
106
107 void SetDefaultPermissionSetting(ContentSetting setting);
108 ContentSetting GetDefaultPermissionSetting();
109 void GetDeniedOrigins(ContentSettingsForOneType* settings);
110 void GetAllowedOrigins(ContentSettingsForOneType* settings);
111 void SetDeniedOrigins(const std::vector<GURL>& new_origins);
112 void SetAllowedOrigins(const std::vector<GURL>& new_origins);
113 void DenyOrigin(const GURL& origin);
114 void AllowOrigin(const GURL& origin);
115 void DropOriginPreference(const GURL& origin);
116 void AllowAllOrigins();
117
118 void VerifyInfobar(const Browser* browser,
119 const std::string& origin,
120 int index);
121 std::string CreateNotification(Browser* browser,
122 bool waiting,
123 const char* icon,
124 const char* title,
125 const char* body,
126 const char* replace_id);
127 std::string CreateSimpleNotification(Browser* browser, bool waiting);
128 bool RequestPermission(Browser* browser);
129 bool CancelNotification(const char* notification_id, Browser* browser);
130 bool PerformActionOnInfobar(Browser* browser,
131 InfobarAction action,
132 int infobar_index,
133 int tab_index);
134 bool CheckOriginInSetting(const ContentSettingsForOneType & settings,
135 const GURL & origin);
136
137 GURL EMPTY_PAGE_URL;
kkania 2012/11/15 16:29:07 constants are kEmptyPageUrl style. There is no con
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
138 GURL TEST_PAGE_URL;
139
140 private:
141 size_t target_infobar_count_;
142 size_t target_balloon_count_;
143
144 void GetPrefsByContentSetting(ContentSetting setting,
145 ContentSettingsForOneType* settings);
18 }; 146 };
19 147
148 BrowserOpenedNotificationObserver::BrowserOpenedNotificationObserver()
149 : new_browser_(NULL),
150 new_window_id_(-1),
151 done_(false),
152 running_(false) {
153 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
154 content::NotificationService::AllBrowserContextsAndSources());
155 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
156 content::NotificationService::AllBrowserContextsAndSources());
157 }
158
159 BrowserOpenedNotificationObserver::~BrowserOpenedNotificationObserver() {}
160
161 void BrowserOpenedNotificationObserver::Wait() {
162 if (done_)
163 return;
164
165 running_ = true;
166 message_loop_runner_ = new content::MessageLoopRunner;
167 message_loop_runner_->Run();
168 EXPECT_TRUE(done_);
169 }
170
171 void BrowserOpenedNotificationObserver::Observe(
172 int type,
173 const content::NotificationSource& source,
174 const content::NotificationDetails& details) {
175 if (type == chrome::NOTIFICATION_BROWSER_OPENED) {
176 // Store the new browser ID and continue waiting for a new tab within it
177 // to stop loading.
178 new_browser_ = content::Source<Browser>(source).ptr();
179 new_window_id_ = new_browser_->session_id().id();
180 } else {
181 DCHECK_EQ(content::NOTIFICATION_LOAD_STOP, type);
182 content::NavigationController* controller =
183 content::Source<content::NavigationController>(source).ptr();
184 SessionTabHelper* session_tab_helper =
185 SessionTabHelper::FromWebContents(controller->GetWebContents());
186 int window_id = session_tab_helper ? session_tab_helper->window_id().id()
187 : -1;
188 if (window_id == new_window_id_) {
189 registrar_.RemoveAll();
190 done_ = true;
191 if (!running_)
192 return;
193
194 message_loop_runner_->Quit();
195 running_ = false;
196 }
197 }
198 }
199
200 NotificationsPermissionTest::NotificationsPermissionTest()
201 : target_infobar_count_(0U),
202 target_balloon_count_(0U) {
203 }
204
205 void NotificationsPermissionTest::SetUpInProcessBrowserTestFixture() {
206 InProcessBrowserTest::SetUpInProcessBrowserTestFixture();
207
208 ASSERT_TRUE(test_server()->Start());
209 EMPTY_PAGE_URL = test_server()->GetURL("files/empty.html");
210 TEST_PAGE_URL = test_server()->GetURL(
211 "files/notifications/notification_tester.html");
212 }
213
214 void NotificationsPermissionTest::Observe(
215 int type,
216 const content::NotificationSource& source,
217 const content::NotificationDetails& details) {
218 switch (type) {
219 case chrome::NOTIFICATION_BROWSER_CLOSED: {
220 MessageLoopForUI::current()->Quit();
221 break;
222 }
223 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED:
224 case chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED: {
225 const InfoBarTabHelper* infoBarTabHelper =
226 content::Source<const InfoBarTabHelper>(source).ptr();
227 if (infoBarTabHelper->GetInfoBarCount() == target_infobar_count_) {
228 target_infobar_count_ = 0U;
229 MessageLoopForUI::current()->Quit();
230 }
231 break;
232 }
233 case chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED:
234 case chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED: {
235 size_t current_balloon_count = GetActiveBalloons().size();
236 if (current_balloon_count == target_balloon_count_) {
237 target_balloon_count_ = 0U;
238 MessageLoopForUI::current()->Quit();
239 }
240 break;
241 }
242 default:
243 break;
244 }
245 }
246
247 DesktopNotificationService*
248 NotificationsPermissionTest::GetDesktopNotificationService() {
249 Profile* profile = browser()->profile();
250 return DesktopNotificationServiceFactory::GetForProfile(profile);
251 }
252
253 const std::deque<Balloon*>& NotificationsPermissionTest::GetActiveBalloons() {
254 NotificationUIManager* manager = g_browser_process->notification_ui_manager();
255 return manager->balloon_collection()->GetActiveBalloons();
256 }
257
258 int NotificationsPermissionTest::GetNotificationCount() {
259 NotificationUIManager* manager = g_browser_process->notification_ui_manager();
260 return manager->balloon_collection()->GetActiveBalloons().size();
261 }
262
263 bool NotificationsPermissionTest::CloseNotificationAndWait(
264 const Notification& notification) {
265 content::WindowedNotificationObserver observer(
266 chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED,
267 content::NotificationService::AllSources());
268 NotificationUIManager* manager = g_browser_process->notification_ui_manager();
269 bool flag = manager->CancelById(notification.notification_id());
270 observer.Wait();
271 return flag;
272 }
273
274 bool NotificationsPermissionTest::WaitForInfoBarCount(
275 Browser* browser,
276 size_t count,
277 int index,
278 bool increasing) {
kkania 2012/11/15 16:29:07 instead of passing in increasing arg, how about we
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Function removed.
279 size_t current_count = InfoBarTabHelper::FromWebContents(
280 chrome::GetWebContentsAt(browser, 0))->GetInfoBarCount();
kkania 2012/11/15 16:29:07 indent
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
281 if (count != current_count) {
282 target_infobar_count_ = count;
283 ui_test_utils::RegisterAndWait(
kkania 2012/11/15 16:29:07 how about usr for loop and use content::WindowedOb
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Move logic of waiting to function RequestPermissio
284 this,
285 increasing ? chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
286 : chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
287 content::NotificationService::AllSources());
288 }
289
290 current_count = InfoBarTabHelper::FromWebContents(
291 chrome::GetWebContentsAt(browser, 0))->GetInfoBarCount();
kkania 2012/11/15 16:29:07 fix all indents
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
292 return count == current_count;
293 }
294
295 Browser* NotificationsPermissionTest::CreateBrowserWindow(
296 Browser* source_browser,
297 bool is_incognito) {
298 BrowserOpenedNotificationObserver observer;
kkania 2012/11/15 16:29:07 You should use option A and find the underlying pr
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Use solution A.
299 if (is_incognito)
300 chrome::ExecuteCommand(source_browser, IDC_NEW_INCOGNITO_WINDOW);
301 else
302 chrome::ExecuteCommand(source_browser, IDC_NEW_WINDOW);
303 observer.Wait();
304 return observer.new_browser();
305 }
306
307 void NotificationsPermissionTest::CloseBrowserWindow(Browser* browser) {
308 content::WindowedNotificationObserver observer(
309 chrome::NOTIFICATION_BROWSER_CLOSED,
310 content::Source<Browser>(browser));
311 browser->window()->Close();
312 observer.Wait();
313 }
314
315 void NotificationsPermissionTest::CrashTab(Browser* browser, int index) {
316 content::CrashTab(chrome::GetWebContentsAt(browser, index));
317 }
318
319 void NotificationsPermissionTest::CrashNotification(Balloon* balloon) {
320 content::CrashTab(balloon->balloon_view()->GetHost()->web_contents());
321 }
322
323 bool NotificationsPermissionTest::CheckOriginInSetting(
324 const ContentSettingsForOneType & settings,
325 const GURL & origin) {
326 ContentSettingsPattern pattern = ContentSettingsPattern::FromURLNoWildcard(
327 origin);
328 for (ContentSettingsForOneType::const_iterator it = settings.begin();
329 it != settings.end(); ++it) {
330 if (it->primary_pattern == pattern) {
331 return true;
332 }
333 }
334 return false;
335 }
336
337 void NotificationsPermissionTest::SetDefaultPermissionSetting(
338 ContentSetting setting) {
339 DesktopNotificationService* service = GetDesktopNotificationService();
340 service->SetDefaultContentSetting(setting);
341 }
342
343 ContentSetting NotificationsPermissionTest::GetDefaultPermissionSetting() {
344 DesktopNotificationService* service = GetDesktopNotificationService();
345 return service->GetDefaultContentSetting(NULL);
346 }
347
348 void NotificationsPermissionTest::GetDeniedOrigins(
349 ContentSettingsForOneType* settings) {
350 GetPrefsByContentSetting(CONTENT_SETTING_BLOCK, settings);
351 }
352
353 void NotificationsPermissionTest::GetAllowedOrigins(
354 ContentSettingsForOneType* settings) {
355 GetPrefsByContentSetting(CONTENT_SETTING_ALLOW, settings);
356 }
357
358 void NotificationsPermissionTest::SetDeniedOrigins(
359 const std::vector<GURL>& new_origins) {
360 // clear original denied origin list.
361 ContentSettingsForOneType old_origins;
362 GetDeniedOrigins(&old_origins);
363 for (ContentSettingsForOneType::const_iterator it = old_origins.begin();
364 it != old_origins.end(); ++it) {
365 GetDesktopNotificationService()->ClearSetting(it->primary_pattern);
366 }
367 // set new origins.
368 for (std::vector<GURL>::const_iterator it = new_origins.begin();
369 it != new_origins.end(); ++it) {
370 DenyOrigin(*it);
371 }
372 }
373 void NotificationsPermissionTest::SetAllowedOrigins(
374 const std::vector<GURL>& new_origins) {
375 // clear original allowed origin list.
376 ContentSettingsForOneType old_origins;
377 GetAllowedOrigins(&old_origins);
378 for (ContentSettingsForOneType::const_iterator it = old_origins.begin();
379 it != old_origins.end(); ++it) {
380 GetDesktopNotificationService()->ClearSetting(it->primary_pattern);
381 }
382 // set new origins.
383 for (std::vector<GURL>::const_iterator it = new_origins.begin();
384 it != new_origins.end(); ++it) {
385 AllowOrigin(*it);
386 }
387 }
388 void NotificationsPermissionTest::DenyOrigin(const GURL& origin) {
389 DropOriginPreference(origin);
390 GetDesktopNotificationService()->DenyPermission(origin);
391 }
392 void NotificationsPermissionTest::AllowOrigin(const GURL& origin) {
393 DropOriginPreference(origin);
394 GetDesktopNotificationService()->GrantPermission(origin);
395 }
396 void NotificationsPermissionTest::DropOriginPreference(const GURL& origin) {
397 GetDesktopNotificationService()->ClearSetting(
398 ContentSettingsPattern::FromURLNoWildcard(origin));
399 }
400 void NotificationsPermissionTest::AllowAllOrigins() {
401 GetDesktopNotificationService()->ResetAllOrigins();
402 GetDesktopNotificationService()->SetDefaultContentSetting(
403 CONTENT_SETTING_ALLOW);
404 }
405
406 void NotificationsPermissionTest::VerifyInfobar(
407 const Browser* browser,
408 const std::string& origin,
409 int index) {
410 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents(
411 chrome::GetWebContentsAt(browser, index));
412
413 ASSERT_EQ(1U, infobar_helper->GetInfoBarCount());
414 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(0);
415 ASSERT_TRUE(infobar->AsConfirmInfoBarDelegate());
416 ConfirmInfoBarDelegate* confirm_infobar = infobar->AsConfirmInfoBarDelegate();
417 int buttons = confirm_infobar->GetButtons();
418 if (buttons & ConfirmInfoBarDelegate::BUTTON_OK) {
419 EXPECT_EQ(
420 ASCIIToUTF16("Allow"),
421 confirm_infobar->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
422 } else {
423 EXPECT_TRUE(false);
424 }
425 if (buttons & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
426 EXPECT_EQ(
427 ASCIIToUTF16("Deny"),
428 confirm_infobar->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
429 } else {
430 EXPECT_TRUE(false);
431 }
432 std::string text("Allow ");
433 text.append(origin);
434 text.append(" to show desktop notifications?");
435 EXPECT_EQ(UTF8ToUTF16(text), confirm_infobar->GetMessageText());
436 }
437
438 std::string NotificationsPermissionTest::CreateNotification(
439 Browser* browser,
440 bool waiting,
441 const char* icon,
442 const char* title,
443 const char* body,
444 const char* replace_id) {
445 std::string result;
446
447 std::string script = base::StringPrintf(
448 "createNotification('%s', '%s', '%s', '%s');",
449 icon,
450 title,
451 body,
452 replace_id);
453
454 bool flag = false;
455 if (!waiting) {
456 flag = content::ExecuteJavaScriptAndExtractString(
457 chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
458 L"",
459 UTF8ToWide(script),
460 &result);
461 } else {
462 content::WindowedNotificationObserver observer(
463 chrome::NOTIFICATION_NOTIFY_BALLOON_CONNECTED,
464 content::NotificationService::AllSources());
465 flag = content::ExecuteJavaScriptAndExtractString(
466 chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
467 L"",
468 UTF8ToWide(script),
469 &result);
470 observer.Wait();
471 }
472 EXPECT_TRUE(flag);
473
474 content::RunAllPendingInMessageLoop();
475 return result;
476 }
477
478 std::string NotificationsPermissionTest::CreateSimpleNotification(
479 Browser* browser,
480 bool waiting) {
481 return CreateNotification(
482 browser,
483 waiting,
484 "no_such_file.png",
485 "My Title",
486 "My Body",
487 "");
488 }
489
490 bool NotificationsPermissionTest::RequestPermission(Browser* browser) {
491 std::string result;
492 bool flag = content::ExecuteJavaScriptAndExtractString(
493 chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
494 L"",
495 L"requestPermission();",
496 &result);
497 return flag ? (result == "1") : false;
498 }
499
500 bool NotificationsPermissionTest::CancelNotification(
501 const char* notification_id,
502 Browser* browser) {
503 std::string script = base::StringPrintf(
504 "cancelNotification('%s');",
505 notification_id);
506
507 std::string result;
508 bool flag = content::ExecuteJavaScriptAndExtractString(
509 chrome::GetActiveWebContents(browser)->GetRenderViewHost(),
510 L"",
511 UTF8ToWide(script),
512 &result);
513 return flag ? (result == "1") : false;
514 }
515
516 bool NotificationsPermissionTest::PerformActionOnInfobar(
517 Browser* browser,
518 InfobarAction action,
519 int infobar_index,
520 int tab_index) {
521 InfoBarTabHelper* infobar_helper = InfoBarTabHelper::FromWebContents(
522 chrome::GetWebContentsAt(browser, tab_index));
523
524 InfoBarDelegate* infobar = infobar_helper->GetInfoBarDelegateAt(
525 infobar_index);
526 switch (action) {
527 case DISMISS: {
528 infobar->InfoBarDismissed();
529 infobar_helper->RemoveInfoBar(infobar);
530 return true;
531 }
532 case ALLOW: {
533 ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate();
534 if (confirm_bar->Accept()) {
535 infobar_helper->RemoveInfoBar(infobar);
536 return true;
537 }
538 }
539 case DENY: {
540 ConfirmInfoBarDelegate* confirm_bar = infobar->AsConfirmInfoBarDelegate();
541 if (confirm_bar->Cancel()) {
542 infobar_helper->RemoveInfoBar(infobar);
543 return true;
544 }
545 }
546 }
547
548 return false;
549 }
550
551 void NotificationsPermissionTest::GetPrefsByContentSetting(
552 ContentSetting setting,
553 ContentSettingsForOneType* settings) {
554 ASSERT_TRUE(settings != NULL);
555 DesktopNotificationService* service = GetDesktopNotificationService();
556 service->GetNotificationsSettings(settings);
557 for (ContentSettingsForOneType::iterator it = settings->begin();
558 it != settings->end();) {
559 if (it->setting != setting || it->source.compare(kReference) != 0) {
560 it = settings->erase(it);
561 } else {
562 ++it;
563 }
564 }
565 }
566
20 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. 567 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428.
21 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) { 568 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestUserGestureInfobar) {
22 ASSERT_TRUE(test_server()->Start());
23
24 ui_test_utils::NavigateToURL( 569 ui_test_utils::NavigateToURL(
25 browser(), 570 browser(),
26 test_server()->GetURL( 571 test_server()->GetURL(
27 "files/notifications/notifications_request_function.html")); 572 "files/notifications/notifications_request_function.html"));
28 573
29 // Request permission by calling request() while eval'ing an inline script; 574 // Request permission by calling request() while eval'ing an inline script;
30 // That's considered a user gesture to webkit, and should produce an infobar. 575 // That's considered a user gesture to webkit, and should produce an infobar.
31 bool result; 576 bool result;
32 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 577 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
33 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 578 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
34 L"", 579 L"",
35 L"window.domAutomationController.send(request());", 580 L"window.domAutomationController.send(request());",
36 &result)); 581 &result));
37 EXPECT_TRUE(result); 582 EXPECT_TRUE(result);
38 583
39 EXPECT_EQ(1U, InfoBarTabHelper::FromWebContents( 584 EXPECT_EQ(1U, InfoBarTabHelper::FromWebContents(
40 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); 585 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount());
41 } 586 }
42 587
43 // If this flakes, use http://crbug.com/62311. 588 // If this flakes, use http://crbug.com/62311.
44 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) { 589 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestNoUserGestureInfobar) {
45 ASSERT_TRUE(test_server()->Start());
46
47 // Load a page which just does a request; no user gesture should result 590 // Load a page which just does a request; no user gesture should result
48 // in no infobar. 591 // in no infobar.
49 ui_test_utils::NavigateToURL( 592 ui_test_utils::NavigateToURL(
50 browser(), 593 browser(),
51 test_server()->GetURL( 594 test_server()->GetURL(
52 "files/notifications/notifications_request_inline.html")); 595 "files/notifications/notifications_request_inline.html"));
53 596
54 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents( 597 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
55 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount()); 598 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount());
56 } 599 }
600
601 IN_PROC_BROWSER_TEST_F(
602 NotificationsPermissionTest,
603 TestCreateSimpleNotification) {
604 // Creates a simple notification.
605 AllowAllOrigins();
606 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
607
608 std::string result = CreateSimpleNotification(browser(), true);
609 EXPECT_NE("-1", result);
610
611 const std::deque<Balloon*>& balloons = GetActiveBalloons();
612 ASSERT_EQ(1U, balloons.size());
613 Balloon* balloon = balloons[0];
614 const Notification& notification = balloon->notification();
615 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
616 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
617 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title());
618 EXPECT_EQ(ASCIIToUTF16("My Body"), notification.body());
619 }
620
621 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestCloseNotification) {
622 // Creates a notification and closes it.
623 AllowAllOrigins();
624 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
625
626 std::string result = CreateSimpleNotification(browser(), true);
627 EXPECT_NE("-1", result);
628
629 const std::deque<Balloon*>& balloons = GetActiveBalloons();
630 ASSERT_EQ(1U, balloons.size());
631 EXPECT_TRUE(CloseNotificationAndWait(balloons[0]->notification()));
632 ASSERT_EQ(0, GetNotificationCount());
633 }
634
635 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestCancelNotification) {
636 // Creates a notification and cancels it in the origin page.
637 AllowAllOrigins();
638 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
639
640 std::string note_id = CreateSimpleNotification(browser(), true);
641 EXPECT_NE(note_id, "-1");
642
643 ASSERT_EQ(1, GetNotificationCount());
644 ASSERT_TRUE(CancelNotification(note_id.c_str(), browser()));
645 ASSERT_EQ(0, GetNotificationCount());
646 }
647
648 IN_PROC_BROWSER_TEST_F(
649 NotificationsPermissionTest,
650 TestPermissionInfobarAppears) {
651 // Requests notification privileges and verifies the infobar appears.
652 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
653 ASSERT_TRUE(RequestPermission(browser()));
654 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
655
656 ASSERT_EQ(0, GetNotificationCount());
657 VerifyInfobar(browser(), TEST_PAGE_URL.host(), 0);
658 }
659
660 IN_PROC_BROWSER_TEST_F(
661 NotificationsPermissionTest,
662 TestAllowOnPermissionInfobar) {
663 // Tries to create a notification and clicks allow on the infobar.
664 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
665 // This notification should not be shown because we do not have permission.
666 CreateSimpleNotification(browser(), false);
667 ASSERT_EQ(0, GetNotificationCount());
668
669 ASSERT_TRUE(RequestPermission(browser()));
670 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
671 ASSERT_TRUE(PerformActionOnInfobar(browser(), ALLOW, 0, 0));
672
673 CreateSimpleNotification(browser(), true);
674 EXPECT_EQ(1, GetNotificationCount());
675 }
676
677 IN_PROC_BROWSER_TEST_F(
kkania 2012/11/15 16:29:07 I'm thinking we should perhaps remove this functio
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Agree. It is more like a unit test. Removed. On 2
678 NotificationsPermissionTest,
679 TestOriginPreferencesBasic) {
680 // Tests that we can allow and deny origins.
681 GURL altavista("http://www.altavista.com");
682 GURL gmail("http://www.gmail.com");
683 GURL yahoo("http://www.yahoo.com");
684
685 std::vector<GURL> origins;
686 ContentSettingsForOneType settings;
687
688 origins.push_back(altavista);
689 origins.push_back(gmail);
690
691 SetDeniedOrigins(origins);
692 GetDeniedOrigins(&settings);
693 EXPECT_EQ(2U, settings.size());
694 EXPECT_TRUE(CheckOriginInSetting(settings, altavista));
695 EXPECT_TRUE(CheckOriginInSetting(settings, gmail));
696 DenyOrigin(yahoo);
697 GetDeniedOrigins(&settings);
698 EXPECT_EQ(3U, settings.size());
699 EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
700 DropOriginPreference(gmail);
701 GetDeniedOrigins(&settings);
702 EXPECT_EQ(2U, settings.size());
703 EXPECT_FALSE(CheckOriginInSetting(settings, gmail));
704
705 AllowOrigin(yahoo);
706 GetDeniedOrigins(&settings);
707 EXPECT_EQ(1U, settings.size());
708 EXPECT_FALSE(CheckOriginInSetting(settings, yahoo));
709 GetAllowedOrigins(&settings);
710 EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
711
712 origins.clear();
713 origins.push_back(altavista);
714 origins.push_back(gmail);
715 SetAllowedOrigins(origins);
716 origins.clear();
717 SetDeniedOrigins(origins);
718 GetAllowedOrigins(&settings);
719 EXPECT_TRUE(CheckOriginInSetting(settings, altavista));
720 EXPECT_TRUE(CheckOriginInSetting(settings, gmail));
721 AllowOrigin(yahoo);
722 GetAllowedOrigins(&settings);
723 EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
724 EXPECT_EQ(3U, settings.size());
725 DropOriginPreference(gmail);
726 GetAllowedOrigins(&settings);
727 EXPECT_EQ(2U, settings.size());
728 EXPECT_FALSE(CheckOriginInSetting(settings, gmail));
729
730 DenyOrigin(yahoo);
731 GetAllowedOrigins(&settings);
732 EXPECT_EQ(1U, settings.size());
733 EXPECT_FALSE(CheckOriginInSetting(settings, yahoo));
734 GetDeniedOrigins(&settings);
735 EXPECT_TRUE(CheckOriginInSetting(settings, yahoo));
736 }
737
738 IN_PROC_BROWSER_TEST_F(
739 NotificationsPermissionTest,
740 TestDenyOnPermissionInfobar) {
741 // Test that no notification is created
742 // when Deny is chosen from permission infobar.
743 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
744 ASSERT_TRUE(RequestPermission(browser()));
745 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
746 PerformActionOnInfobar(browser(), DENY, 0, 0);
747 CreateSimpleNotification(browser(), false);
748 ASSERT_EQ(0, GetNotificationCount());
749 ContentSettingsForOneType settings;
750 GetDeniedOrigins(&settings);
751 EXPECT_TRUE(CheckOriginInSetting(settings, TEST_PAGE_URL));
752 }
753
754 IN_PROC_BROWSER_TEST_F(
755 NotificationsPermissionTest,
756 TestClosePermissionInfobar) {
757 // Test that no notification is created when permission infobar is dismissed.
758 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
759 ASSERT_TRUE(RequestPermission(browser()));
760 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
761 PerformActionOnInfobar(browser(), DISMISS, 0, 0);
762 CreateSimpleNotification(browser(), false);
763 ASSERT_EQ(0, GetNotificationCount());
764 ContentSettingsForOneType settings;
765 GetDeniedOrigins(&settings);
766 EXPECT_EQ(0U, settings.size());
767 }
768
769 IN_PROC_BROWSER_TEST_F(
770 NotificationsPermissionTest,
771 TestNotificationWithPropertyMissing) {
772 // Test that a notification can be created if one property is missing.
773 AllowAllOrigins();
774 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
775
776 std::string result = CreateSimpleNotification(browser(), true);
777 EXPECT_NE("-1", result);
778
779 const std::deque<Balloon*>& balloons = GetActiveBalloons();
780 ASSERT_EQ(1U, balloons.size());
781 Balloon* balloon = balloons[0];
782 const Notification& notification = balloon->notification();
783 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
784 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
785 EXPECT_EQ(ASCIIToUTF16("My Title"), notification.title());
786 }
787
788 IN_PROC_BROWSER_TEST_F(
789 NotificationsPermissionTest,
790 TestAllowNotificationsFromAllSites) {
791 // Verify that all domains can be allowed to show notifications.
792 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW);
793 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
794
795 std::string result = CreateSimpleNotification(browser(), true);
796 EXPECT_NE("-1", result);
797
798 ASSERT_EQ(1, GetNotificationCount());
799 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
800 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount());
801 }
802
803 IN_PROC_BROWSER_TEST_F(
804 NotificationsPermissionTest,
805 TestDenyNotificationsFromAllSites) {
806 // Verify that no domain can show notifications.
807 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK);
808 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
809
810 std::string result = CreateSimpleNotification(browser(), false);
811 EXPECT_EQ("-1", result);
812
813 ASSERT_EQ(0, GetNotificationCount());
814 }
815
816 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestDenyDomainAndAllowAll) {
817 // Verify that denying a domain and allowing all shouldn't show
818 // notifications from the denied domain.
819 DenyOrigin(TEST_PAGE_URL.GetOrigin());
820 SetDefaultPermissionSetting(CONTENT_SETTING_ALLOW);
821
822 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
823
824 std::string result = CreateSimpleNotification(browser(), false);
825 EXPECT_EQ("-1", result);
826
827 ASSERT_EQ(0, GetNotificationCount());
828 }
829
830 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestAllowDomainAndDenyAll) {
831 // Verify that allowing a domain and denying all others should show
832 // notifications from the allowed domain.
833 AllowOrigin(TEST_PAGE_URL.GetOrigin());
834 SetDefaultPermissionSetting(CONTENT_SETTING_BLOCK);
835
836 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
837
838 std::string result = CreateSimpleNotification(browser(), true);
839 EXPECT_NE("-1", result);
840
841 ASSERT_EQ(1, GetNotificationCount());
842 }
843
844 IN_PROC_BROWSER_TEST_F(
845 NotificationsPermissionTest,
846 TestDenyAndThenAllowDomain) {
847 // Verify that denying and again allowing should show notifications.
848 DenyOrigin(TEST_PAGE_URL.GetOrigin());
849
850 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
851
852 std::string result = CreateSimpleNotification(browser(), false);
853 EXPECT_EQ("-1", result);
854
855 ASSERT_EQ(0, GetNotificationCount());
856
857 AllowOrigin(TEST_PAGE_URL.GetOrigin());
858 result = CreateSimpleNotification(browser(), true);
859 EXPECT_NE("-1", result);
860
861 ASSERT_EQ(1, GetNotificationCount());
862 EXPECT_EQ(0U, InfoBarTabHelper::FromWebContents(
863 chrome::GetWebContentsAt(browser(), 0))->GetInfoBarCount());
864 }
865
866 IN_PROC_BROWSER_TEST_F(
867 NotificationsPermissionTest,
868 TestCreateDenyCloseNotifications) {
869 // Verify able to create, deny, and close the notification.
870 AllowAllOrigins();
871 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
872 CreateSimpleNotification(browser(), true);
873 ASSERT_EQ(1, GetNotificationCount());
874
875 DenyOrigin(TEST_PAGE_URL.GetOrigin());
876 ContentSettingsForOneType settings;
877 GetDeniedOrigins(&settings);
878 ASSERT_TRUE(CheckOriginInSetting(settings, TEST_PAGE_URL.GetOrigin()));
879
880 const std::deque<Balloon*>& balloons1 = GetActiveBalloons();
881 EXPECT_EQ(1U, balloons1.size());
882 ASSERT_TRUE(CloseNotificationAndWait(balloons1[0]->notification()));
883 ASSERT_EQ(0, GetNotificationCount());
884 }
885
886 // Crashes on Linux/Win. See http://crbug.com/160657.
887 IN_PROC_BROWSER_TEST_F(
888 NotificationsPermissionTest,
889 DISABLED_TestOriginPrefsNotSavedInIncognito) {
890 // Verify that allow/deny origin preferences are not saved in incognito.
891 Browser* incognito = CreateBrowserWindow(browser(), true);
892 ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL);
893 ASSERT_TRUE(RequestPermission(incognito));
894 ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true));
895 PerformActionOnInfobar(incognito, DENY, 0, 0);
896 CloseBrowserWindow(incognito);
897
898 incognito = CreateBrowserWindow(browser(), true);
899 ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL);
900 ASSERT_TRUE(RequestPermission(incognito));
901 ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true));
902 PerformActionOnInfobar(incognito, ALLOW, 0, 0);
903 CreateSimpleNotification(incognito, true);
904 ASSERT_EQ(1, GetNotificationCount());
905 CloseBrowserWindow(incognito);
906
907 incognito = CreateBrowserWindow(browser(), true);
908 ui_test_utils::NavigateToURL(incognito, TEST_PAGE_URL);
909 ASSERT_TRUE(RequestPermission(incognito));
910 ASSERT_TRUE(WaitForInfoBarCount(incognito, 1, 0, true));
911
912 ContentSettingsForOneType settings;
913 GetDeniedOrigins(&settings);
914 EXPECT_EQ(0U, settings.size());
915 GetAllowedOrigins(&settings);
916 EXPECT_EQ(0U, settings.size());
917 }
918
919 IN_PROC_BROWSER_TEST_F(
920 NotificationsPermissionTest,
921 TestExitBrowserWithInfobar) {
922 // Exit the browser window, when the infobar appears.
923 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
924 ASSERT_TRUE(RequestPermission(browser()));
925 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
926 }
927
928 IN_PROC_BROWSER_TEST_F(
929 NotificationsPermissionTest,
930 TestCrashTabWithPermissionInfobar) {
931 // Test crashing the tab with permission infobar doesn't crash Chrome.
932 ui_test_utils::NavigateToURLWithDisposition(
933 browser(),
934 EMPTY_PAGE_URL,
935 NEW_BACKGROUND_TAB,
936 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
937 chrome::ActivateTabAt(browser(), 0, true);
938 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
939 ASSERT_TRUE(RequestPermission(browser()));
940 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
941 CrashTab(browser(), 0);
942 }
943
944 IN_PROC_BROWSER_TEST_F(
945 NotificationsPermissionTest,
946 TestKillNotificationProcess) {
947 // Test killing a notification doesn't crash Chrome.
948 AllowAllOrigins();
949 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
950 CreateSimpleNotification(browser(), true);
951 ASSERT_EQ(1, GetNotificationCount());
952
953 const std::deque<Balloon*>& balloons = GetActiveBalloons();
954 ASSERT_EQ(1U, balloons.size());
955 CrashNotification(balloons[0]);
956 ASSERT_EQ(0, GetNotificationCount());
957 }
958
959 IN_PROC_BROWSER_TEST_F(NotificationsPermissionTest, TestIncognitoNotification) {
960 // Test notifications in incognito window.
961 Browser* browser = CreateIncognitoBrowser();
962 ui_test_utils::NavigateToURL(browser, TEST_PAGE_URL);
963 chrome::ActivateTabAt(browser, 0, true);
964 ASSERT_TRUE(RequestPermission(browser));
965 ASSERT_TRUE(WaitForInfoBarCount(browser, 1, 0, true));
966 PerformActionOnInfobar(browser, ALLOW, 0, 0);
967 CreateSimpleNotification(browser, true);
968 ASSERT_EQ(1, GetNotificationCount());
969 }
970
971 IN_PROC_BROWSER_TEST_F(
972 NotificationsPermissionTest,
973 TestCloseTabWithPermissionInfobar) {
974 // Test that user can close tab when infobar present.
975 ui_test_utils::NavigateToURLWithDisposition(
976 browser(),
977 GURL("about:blank"),
978 NEW_BACKGROUND_TAB,
979 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
980 chrome::ActivateTabAt(browser(), 0, true);
981 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
982 ASSERT_TRUE(RequestPermission(browser()));
983 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
984 content::WindowedNotificationObserver observer(
985 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
986 content::NotificationService::AllSources());
987 chrome::CloseWebContents(browser(), chrome::GetWebContentsAt(browser(), 0));
988 observer.Wait();
989 }
990
991 IN_PROC_BROWSER_TEST_F(
992 NotificationsPermissionTest,
993 TestNavigateAwayWithPermissionInfobar) {
994 // Test navigating away when an infobar is present,
995 // then trying to create a notification from the same page.
996 ui_test_utils::NavigateToURLWithDisposition(
997 browser(),
998 GURL("about:blank"),
999 NEW_BACKGROUND_TAB,
1000 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1001 chrome::ActivateTabAt(browser(), 0, true);
1002 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
1003 ASSERT_TRUE(RequestPermission(browser()));
1004 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
1005 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
1006 ASSERT_TRUE(RequestPermission(browser()));
1007 ASSERT_TRUE(WaitForInfoBarCount(browser(), 1, 0, true));
1008 PerformActionOnInfobar(browser(), ALLOW, 0, 0);
1009 CreateSimpleNotification(browser(), true);
1010 ASSERT_EQ(1, GetNotificationCount());
1011 }
1012
1013 IN_PROC_BROWSER_TEST_F(
1014 NotificationsPermissionTest,
1015 TestCrashRendererNotificationRemain) {
1016 // Test crashing renderer does not close or crash notification.
1017 AllowAllOrigins();
1018 ui_test_utils::NavigateToURLWithDisposition(
1019 browser(),
1020 GURL("about:blank"),
1021 NEW_BACKGROUND_TAB,
1022 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1023 chrome::ActivateTabAt(browser(), 0, true);
1024 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
1025 CreateSimpleNotification(browser(), true);
1026 ASSERT_EQ(1, GetNotificationCount());
1027 CrashTab(browser(), 0);
1028 ASSERT_EQ(1, GetNotificationCount());
1029 }
1030
1031 IN_PROC_BROWSER_TEST_F(
1032 NotificationsPermissionTest,
1033 TestNotificationOrderAfterClosingOne) {
1034 // Tests that closing a notification leaves the rest
1035 // of the notifications in the correct order.
1036 // Check for Win7.
1037 #if defined(OS_WIN)
1038 if (base::win::GetVersion() == VERSION_WIN7) {
1039 return; // crbug.com/66072
1040 }
1041 #endif
1042
1043 AllowAllOrigins();
1044
1045 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
1046
1047 CreateNotification(browser(), true, "", "Title1", "", "1");
1048 CreateNotification(browser(), true, "", "Title2", "", "2");
1049 CreateNotification(browser(), true, "", "Title3", "", "3");
1050
1051 ASSERT_EQ(3, GetNotificationCount());
1052 const std::deque<Balloon*>& old_balloons = GetActiveBalloons();
1053
1054 ASSERT_TRUE(CloseNotificationAndWait(old_balloons[1]->notification()));
1055
1056 const std::deque<Balloon*>& new_balloons = GetActiveBalloons();
1057 ASSERT_EQ(2U, new_balloons.size());
1058 EXPECT_EQ(old_balloons[0]->notification().notification_id(),
1059 new_balloons[0]->notification().notification_id());
1060 EXPECT_EQ(old_balloons[2]->notification().notification_id(),
1061 new_balloons[1]->notification().notification_id());
1062 }
1063
1064 IN_PROC_BROWSER_TEST_F(
1065 NotificationsPermissionTest,
1066 TestNotificationReplacement) {
1067 // Test that we can replace a notification using the replaceId.
1068 AllowAllOrigins();
1069
1070 ui_test_utils::NavigateToURL(browser(), TEST_PAGE_URL);
1071
1072 std::string result = CreateNotification(
1073 browser(),
kkania 2012/11/15 16:29:07 4, not 5
chrisgao (Use stgao instead) 2012/11/16 00:23:30 Done.
1074 true,
1075 "",
1076 "Title2",
1077 "",
1078 "chat");
1079 EXPECT_NE("-1", result);
1080
1081 ASSERT_EQ(1, GetNotificationCount());
1082
1083 result = CreateNotification(
kkania 2012/11/15 16:29:07 are we guaranteed that this func waits until the r
chrisgao (Use stgao instead) 2012/11/16 00:23:30 According to my test, Chrome supports notification
1084 browser(),
1085 false,
1086 "no_such_file.png",
1087 "",
1088 "",
1089 "chat");
1090 EXPECT_NE("-1", result);
1091
1092 const std::deque<Balloon*>& balloons2 = GetActiveBalloons();
1093 EXPECT_EQ(1U, balloons2.size());
1094 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
1095 const Notification& notification = balloons2[0]->notification();
1096 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
1097 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/notifications/notification_tester.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698