OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/bind.h" | |
6 #include "base/memory/ref_counted.h" | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "base/message_loop.h" | |
9 #include "base/string16.h" | |
10 #include "base/string_util.h" | |
11 #include "base/stringprintf.h" | |
12 #include "base/utf_string_conversions.h" | |
13 #include "chrome/browser/browser_process.h" | |
14 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h" | |
15 #include "chrome/browser/chromeos/notifications/balloon_view.h" | |
16 #include "chrome/browser/chromeos/notifications/notification_panel.h" | |
17 #include "chrome/browser/chromeos/notifications/system_notification_factory.h" | |
18 #include "chrome/browser/notifications/notification_test_util.h" | |
19 #include "chrome/browser/notifications/notification_ui_manager.h" | |
20 #include "chrome/browser/ui/browser.h" | |
21 #include "chrome/common/chrome_notification_types.h" | |
22 #include "chrome/test/base/in_process_browser_test.h" | |
23 #include "chrome/test/base/ui_test_utils.h" | |
24 #include "content/public/browser/notification_service.h" | |
25 #include "ui/base/x/x11_util.h" | |
26 | |
27 namespace chromeos { | |
28 | |
29 class NotificationTest : public InProcessBrowserTest, | |
30 public content::NotificationObserver { | |
31 public: | |
32 NotificationTest() | |
33 : under_chromeos_(false), | |
34 state_(PanelController::INITIAL), | |
35 expected_(PanelController::INITIAL) { | |
36 } | |
37 | |
38 void HandleWebUIMessage(const ListValue* value) { | |
39 MessageLoop::current()->Quit(); | |
40 } | |
41 | |
42 protected: | |
43 virtual void SetUp() { | |
44 // Detect if we're running under ChromeOS WindowManager. See | |
45 // the description for "under_chromeos_" below for why we need this. | |
46 ui::WindowManagerName wm_type = ui::GuessWindowManager(); | |
47 // NOTE: On Chrome OS the wm and Chrome are started in parallel. This | |
48 // means it's possible for us not to be able to get the name of the window | |
49 // manager. We assume that when this happens we're on Chrome OS. | |
50 under_chromeos_ = (wm_type == ui::WM_CHROME_OS || | |
51 wm_type == ui::WM_UNKNOWN); | |
52 InProcessBrowserTest::SetUp(); | |
53 } | |
54 | |
55 BalloonCollectionImpl* GetBalloonCollectionImpl() { | |
56 return static_cast<BalloonCollectionImpl*>( | |
57 g_browser_process->notification_ui_manager()->balloon_collection()); | |
58 } | |
59 | |
60 NotificationPanel* GetNotificationPanel() { | |
61 return static_cast<NotificationPanel*>( | |
62 GetBalloonCollectionImpl()->notification_ui()); | |
63 } | |
64 | |
65 Notification NewMockNotification(const std::string& id) { | |
66 return NewMockNotification(new MockNotificationDelegate(id)); | |
67 } | |
68 | |
69 Notification NewMockNotification(NotificationDelegate* delegate) { | |
70 std::string text = delegate->id(); | |
71 return SystemNotificationFactory::Create( | |
72 GURL(), ASCIIToUTF16(text.c_str()), ASCIIToUTF16(text.c_str()), | |
73 delegate); | |
74 } | |
75 | |
76 void MarkStale(const char* id) { | |
77 GetNotificationPanel()->GetTester()->MarkStale(NewMockNotification(id)); | |
78 } | |
79 | |
80 // Waits untilt the panel's state becomes the specified state. | |
81 // Does nothing if it's not running with ChromeOS Window Manager. | |
82 void WaitForPanelState(NotificationPanelTester* tester, | |
83 PanelController::State state) { | |
84 if (under_chromeos_ && state != state_) { | |
85 expected_ = state; | |
86 ui_test_utils::RunAllPendingInMessageLoop(); | |
87 } | |
88 } | |
89 | |
90 // Busy loop to wait until the view becomes visible in the panel. | |
91 void WaitForVisible(BalloonViewImpl* view) { | |
92 WaitForResize(view); | |
93 NotificationPanelTester* tester = GetNotificationPanel()->GetTester(); | |
94 while (!tester->IsVisible(view)) { | |
95 ui_test_utils::RunAllPendingInMessageLoop(); | |
96 } | |
97 } | |
98 | |
99 // Busy loop to wait until the webkit give some size to the notification. | |
100 void WaitForResize(BalloonViewImpl* view) { | |
101 while (view->bounds().IsEmpty()) { | |
102 ui_test_utils::RunAllPendingInMessageLoop(); | |
103 } | |
104 } | |
105 | |
106 // NotificationObserver overrides. | |
107 virtual void Observe(int type, | |
108 const content::NotificationSource& source, | |
109 const content::NotificationDetails& details) { | |
110 ASSERT_TRUE(chrome::NOTIFICATION_PANEL_STATE_CHANGED == type); | |
111 PanelController::State* state = | |
112 reinterpret_cast<PanelController::State*>(details.map_key()); | |
113 state_ = *state; | |
114 if (under_chromeos_ && expected_ == state_) { | |
115 expected_ = PanelController::INITIAL; | |
116 MessageLoop::current()->Quit(); | |
117 } | |
118 } | |
119 | |
120 private: | |
121 // ChromeOS build of chrome communicates with ChromeOS's | |
122 // WindowManager, and behaves differently if it runs under a | |
123 // chromeos window manager. ChromeOS WindowManager sends | |
124 // EXPANDED/MINIMIED state change message when the panels's state | |
125 // changed (regardless of who changed it), and to avoid | |
126 // mis-recognizing such events as user-initiated actions, we need to | |
127 // wait and eat them before moving to a next step. | |
128 bool under_chromeos_; | |
129 PanelController::State state_; | |
130 PanelController::State expected_; | |
131 }; | |
132 | |
133 IN_PROC_BROWSER_TEST_F(NotificationTest, TestBasic) { | |
134 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
135 NotificationPanel* panel = GetNotificationPanel(); | |
136 NotificationPanelTester* tester = panel->GetTester(); | |
137 | |
138 // Using system notification as regular notification. | |
139 collection->Add(NewMockNotification("1"), browser()->profile()); | |
140 | |
141 EXPECT_EQ(1, tester->GetNewNotificationCount()); | |
142 EXPECT_EQ(1, tester->GetNotificationCount()); | |
143 EXPECT_EQ(0, tester->GetStickyNotificationCount()); | |
144 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
145 | |
146 collection->Add(NewMockNotification("2"), browser()->profile()); | |
147 | |
148 EXPECT_EQ(2, tester->GetNewNotificationCount()); | |
149 EXPECT_EQ(2, tester->GetNotificationCount()); | |
150 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
151 | |
152 collection->RemoveById("1"); | |
153 ui_test_utils::RunAllPendingInMessageLoop(); | |
154 | |
155 EXPECT_EQ(1, tester->GetNewNotificationCount()); | |
156 EXPECT_EQ(1, tester->GetNotificationCount()); | |
157 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
158 | |
159 collection->RemoveById("2"); | |
160 ui_test_utils::RunAllPendingInMessageLoop(); | |
161 EXPECT_EQ(0, tester->GetNewNotificationCount()); | |
162 EXPECT_EQ(0, tester->GetNotificationCount()); | |
163 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
164 | |
165 // CLOSE is asynchronous. Run the all pending tasks to finish closing | |
166 // task. | |
167 ui_test_utils::RunAllPendingInMessageLoop(); | |
168 } | |
169 | |
170 // [CLOSED] -add->[STICKY_AND_NEW] -mouse-> [STICKY_AND_NEW] -remove/add-> | |
171 // [STICKY_AND_NEW] -remove-> [CLOSED] -add-> [STICKY_AND_NEW] -remove-> | |
172 // [CLOSED] | |
173 IN_PROC_BROWSER_TEST_F(NotificationTest, TestKeepSizeState) { | |
174 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
175 NotificationPanel* panel = GetNotificationPanel(); | |
176 NotificationPanelTester* tester = panel->GetTester(); | |
177 | |
178 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
179 | |
180 // Using system notification as regular notification. | |
181 collection->Add(NewMockNotification("1"), browser()->profile()); | |
182 collection->Add(NewMockNotification("2"), browser()->profile()); | |
183 | |
184 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
185 | |
186 panel->OnMouseMotion(gfx::Point(10, 10)); | |
187 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
188 | |
189 collection->RemoveById("1"); | |
190 ui_test_utils::RunAllPendingInMessageLoop(); | |
191 EXPECT_EQ(1, tester->GetNewNotificationCount()); | |
192 EXPECT_EQ(1, tester->GetNotificationCount()); | |
193 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
194 | |
195 collection->Add(NewMockNotification("1"), browser()->profile()); | |
196 ui_test_utils::RunAllPendingInMessageLoop(); | |
197 EXPECT_EQ(2, tester->GetNewNotificationCount()); | |
198 EXPECT_EQ(2, tester->GetNotificationCount()); | |
199 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
200 | |
201 collection->RemoveById("1"); | |
202 ui_test_utils::RunAllPendingInMessageLoop(); | |
203 EXPECT_EQ(1, tester->GetNewNotificationCount()); | |
204 EXPECT_EQ(1, tester->GetNotificationCount()); | |
205 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
206 | |
207 collection->RemoveById("2"); | |
208 ui_test_utils::RunAllPendingInMessageLoop(); | |
209 EXPECT_EQ(0, tester->GetNotificationCount()); | |
210 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
211 | |
212 collection->Add(NewMockNotification("3"), browser()->profile()); | |
213 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
214 collection->RemoveById("3"); | |
215 | |
216 ui_test_utils::RunAllPendingInMessageLoop(); | |
217 EXPECT_EQ(0, tester->GetNotificationCount()); | |
218 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
219 } | |
220 | |
221 IN_PROC_BROWSER_TEST_F(NotificationTest, TestSystemNotification) { | |
222 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
223 NotificationPanel* panel = GetNotificationPanel(); | |
224 scoped_refptr<MockNotificationDelegate> delegate( | |
225 new MockNotificationDelegate("power")); | |
226 NotificationPanelTester* tester = panel->GetTester(); | |
227 | |
228 Notification notify = NewMockNotification(delegate.get()); | |
229 collection->AddSystemNotification(notify, browser()->profile(), true); | |
230 | |
231 EXPECT_EQ(1, tester->GetNewNotificationCount()); | |
232 EXPECT_EQ(1, tester->GetStickyNotificationCount()); | |
233 | |
234 Notification update = SystemNotificationFactory::Create( | |
235 GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated"), delegate.get()); | |
236 collection->UpdateNotification(update); | |
237 | |
238 EXPECT_EQ(1, tester->GetStickyNotificationCount()); | |
239 | |
240 Notification update_and_show = SystemNotificationFactory::Create( | |
241 GURL(), ASCIIToUTF16("Title"), ASCIIToUTF16("updated and shown"), | |
242 delegate.get()); | |
243 collection->UpdateAndShowNotification(update_and_show); | |
244 | |
245 EXPECT_EQ(1, tester->GetStickyNotificationCount()); | |
246 | |
247 // Dismiss the notification. | |
248 collection->RemoveById(delegate->id()); | |
249 ui_test_utils::RunAllPendingInMessageLoop(); | |
250 | |
251 EXPECT_EQ(0, tester->GetStickyNotificationCount()); | |
252 EXPECT_EQ(0, tester->GetNewNotificationCount()); | |
253 // TODO(oshima): check content, etc.. | |
254 } | |
255 | |
256 // [CLOSED] -add,add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -remove-> | |
257 // [MINIMIZED] -remove-> [CLOSED] | |
258 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition1) { | |
259 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
260 NotificationPanel* panel = GetNotificationPanel(); | |
261 NotificationPanelTester* tester = panel->GetTester(); | |
262 | |
263 tester->SetStaleTimeout(0); | |
264 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
265 | |
266 collection->Add(NewMockNotification("1"), browser()->profile()); | |
267 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
268 | |
269 collection->Add(NewMockNotification("2"), browser()->profile()); | |
270 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
271 | |
272 ui_test_utils::RunAllPendingInMessageLoop(); | |
273 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | |
274 | |
275 collection->RemoveById("2"); | |
276 ui_test_utils::RunAllPendingInMessageLoop(); | |
277 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | |
278 | |
279 collection->RemoveById("1"); | |
280 ui_test_utils::RunAllPendingInMessageLoop(); | |
281 EXPECT_EQ(0, tester->GetNotificationCount()); | |
282 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
283 | |
284 ui_test_utils::RunAllPendingInMessageLoop(); | |
285 } | |
286 | |
287 // [CLOSED] -add->[STICKY_AND_NEW] -stale-> [MINIMIZED] -add-> | |
288 // [STICKY_AND_NEW] -stale-> [MINIMIZED] -add sys-> [STICKY_NEW] | |
289 // -stale-> [STICKY_NEW] -remove-> [STICKY_NEW] -remove sys-> | |
290 // [MINIMIZED] -remove-> [CLOSED] | |
291 // | |
292 // This test depends on the fact that the panel state change occurs | |
293 // quicker than stale timeout, thus the stale timeout cannot be set to | |
294 // 0. This test explicitly controls the stale state instead. | |
295 IN_PROC_BROWSER_TEST_F(NotificationTest, TestStateTransition2) { | |
296 // Register observer here as the registration does not work in SetUp(). | |
297 content::NotificationRegistrar registrar; | |
298 registrar.Add(this, | |
299 chrome::NOTIFICATION_PANEL_STATE_CHANGED, | |
300 content::NotificationService::AllSources()); | |
301 | |
302 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
303 NotificationPanel* panel = GetNotificationPanel(); | |
304 NotificationPanelTester* tester = panel->GetTester(); | |
305 | |
306 // See description above. | |
307 tester->SetStaleTimeout(100000); | |
308 | |
309 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
310 | |
311 collection->Add(NewMockNotification("1"), browser()->profile()); | |
312 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
313 ui_test_utils::RunAllPendingInMessageLoop(); | |
314 | |
315 // Make the notification stale and make sure panel is minimized state. | |
316 MarkStale("1"); | |
317 ui_test_utils::RunAllPendingInMessageLoop(); | |
318 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | |
319 WaitForPanelState(tester, PanelController::MINIMIZED); | |
320 | |
321 // Adding new notification expands the panel. | |
322 collection->Add(NewMockNotification("2"), browser()->profile()); | |
323 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
324 WaitForPanelState(tester, PanelController::EXPANDED); | |
325 | |
326 // The panel must be minimzied when the new notification becomes stale. | |
327 MarkStale("2"); | |
328 ui_test_utils::RunAllPendingInMessageLoop(); | |
329 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | |
330 WaitForPanelState(tester, PanelController::MINIMIZED); | |
331 | |
332 // The panel must be expanded again when a new system notification is added. | |
333 collection->AddSystemNotification( | |
334 NewMockNotification("3"), browser()->profile(), true); | |
335 EXPECT_EQ(3, tester->GetNotificationCount()); | |
336 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
337 WaitForPanelState(tester, PanelController::EXPANDED); | |
338 | |
339 // Running all events nor removing non sticky should not change the state. | |
340 ui_test_utils::RunAllPendingInMessageLoop(); | |
341 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
342 | |
343 collection->RemoveById("1"); | |
344 ui_test_utils::RunAllPendingInMessageLoop(); | |
345 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
346 | |
347 // Removing the system notification should minimize the panel. | |
348 collection->RemoveById("3"); | |
349 ui_test_utils::RunAllPendingInMessageLoop(); | |
350 EXPECT_EQ(1, tester->GetNotificationCount()); | |
351 EXPECT_EQ(NotificationPanel::MINIMIZED, tester->state()); | |
352 WaitForPanelState(tester, PanelController::MINIMIZED); | |
353 | |
354 // Removing the last notification. Should close the panel. | |
355 collection->RemoveById("2"); | |
356 ui_test_utils::RunAllPendingInMessageLoop(); | |
357 EXPECT_EQ(0, tester->GetNotificationCount()); | |
358 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
359 | |
360 ui_test_utils::RunAllPendingInMessageLoop(); | |
361 } | |
362 | |
363 IN_PROC_BROWSER_TEST_F(NotificationTest, TestCleanupOnExit) { | |
364 content::NotificationRegistrar registrar; | |
365 registrar.Add(this, | |
366 chrome::NOTIFICATION_PANEL_STATE_CHANGED, | |
367 content::NotificationService::AllSources()); | |
368 | |
369 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
370 NotificationPanel* panel = GetNotificationPanel(); | |
371 NotificationPanelTester* tester = panel->GetTester(); | |
372 | |
373 // Don't become stale. | |
374 tester->SetStaleTimeout(100000); | |
375 | |
376 collection->Add(NewMockNotification("1"), browser()->profile()); | |
377 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
378 WaitForPanelState(tester, PanelController::EXPANDED); | |
379 // end without closing. | |
380 } | |
381 | |
382 IN_PROC_BROWSER_TEST_F(NotificationTest, TestCloseOpen) { | |
383 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
384 NotificationPanel* panel = GetNotificationPanel(); | |
385 NotificationPanelTester* tester = panel->GetTester(); | |
386 Profile* profile = browser()->profile(); | |
387 | |
388 collection->Add(NewMockNotification("1"), profile); | |
389 collection->Add(NewMockNotification("2"), profile); | |
390 ui_test_utils::RunAllPendingInMessageLoop(); | |
391 WaitForPanelState(tester, PanelController::EXPANDED); | |
392 PanelController* controller = tester->GetPanelController(); | |
393 // close now | |
394 panel->ClosePanel(); | |
395 controller->Close(); | |
396 ui_test_utils::RunAllPendingInMessageLoop(); | |
397 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
398 // open again | |
399 collection->Add(NewMockNotification("3"), profile); | |
400 WaitForPanelState(tester, PanelController::EXPANDED); | |
401 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
402 | |
403 // close again | |
404 controller = tester->GetPanelController(); | |
405 panel->ClosePanel(); | |
406 controller->Close(); | |
407 ui_test_utils::RunAllPendingInMessageLoop(); | |
408 EXPECT_EQ(NotificationPanel::CLOSED, tester->state()); | |
409 } | |
410 | |
411 // TODO(lipalani): http://crbug.com/83123 | |
412 IN_PROC_BROWSER_TEST_F(NotificationTest, DISABLED_TestScrollBalloonToVisible) { | |
413 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
414 NotificationPanel* panel = GetNotificationPanel(); | |
415 NotificationPanelTester* tester = panel->GetTester(); | |
416 Profile* profile = browser()->profile(); | |
417 | |
418 // Create notifications enough to overflow the panel size. | |
419 const int create_count = 15; | |
420 | |
421 // new notification is always visible | |
422 for (int i = 0; i < create_count; i++) { | |
423 { | |
424 SCOPED_TRACE(base::StringPrintf("new normal %d", i)); | |
425 std::string id = base::StringPrintf("n%d", i); | |
426 collection->Add(NewMockNotification(id), profile); | |
427 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
428 BalloonViewImpl* view = | |
429 tester->GetBalloonView(collection, NewMockNotification(id)); | |
430 WaitForVisible(view); | |
431 } | |
432 { | |
433 SCOPED_TRACE(base::StringPrintf("new system %d", i)); | |
434 std::string id = base::StringPrintf("s%d", i); | |
435 collection->AddSystemNotification( | |
436 NewMockNotification(id), browser()->profile(), true); | |
437 BalloonViewImpl* view = | |
438 tester->GetBalloonView(collection, NewMockNotification(id)); | |
439 WaitForVisible(view); | |
440 } | |
441 } | |
442 | |
443 // Update should not change the visibility | |
444 for (int i = 0; i < create_count; i++) { | |
445 { | |
446 SCOPED_TRACE(base::StringPrintf("update n%d", i)); | |
447 Notification notify = NewMockNotification(base::StringPrintf("n%d", i)); | |
448 // The last shown notification is sticky, which makes all non sticky | |
449 // invisible. | |
450 EXPECT_TRUE(collection->UpdateNotification(notify)); | |
451 ui_test_utils::RunAllPendingInMessageLoop(); | |
452 BalloonViewImpl* view = tester->GetBalloonView(collection, notify); | |
453 EXPECT_FALSE(tester->IsVisible(view)); | |
454 } | |
455 { | |
456 SCOPED_TRACE(base::StringPrintf("update s%d", i)); | |
457 Notification notify = NewMockNotification(base::StringPrintf("s%d", i)); | |
458 BalloonViewImpl* view = tester->GetBalloonView(collection, notify); | |
459 bool currently_visible = tester->IsVisible(view); | |
460 EXPECT_TRUE(collection->UpdateNotification(notify)); | |
461 ui_test_utils::RunAllPendingInMessageLoop(); | |
462 EXPECT_EQ(view, tester->GetBalloonView(collection, notify)); | |
463 EXPECT_EQ(currently_visible, tester->IsVisible(view)); | |
464 } | |
465 } | |
466 // UpdateAndShowNotification makes notification visible | |
467 for (int i = 0; i < create_count; i++) { | |
468 { | |
469 SCOPED_TRACE(base::StringPrintf("update and show n%d", i)); | |
470 Notification notify = NewMockNotification(base::StringPrintf("n%d", i)); | |
471 EXPECT_TRUE(collection->UpdateAndShowNotification(notify)); | |
472 ui_test_utils::RunAllPendingInMessageLoop(); | |
473 BalloonViewImpl* view = tester->GetBalloonView(collection, notify); | |
474 EXPECT_TRUE(tester->IsVisible(view)); | |
475 } | |
476 { | |
477 SCOPED_TRACE(base::StringPrintf("update and show s%d", i)); | |
478 Notification notify = NewMockNotification(base::StringPrintf("s%d", i)); | |
479 EXPECT_TRUE(collection->UpdateAndShowNotification(notify)); | |
480 ui_test_utils::RunAllPendingInMessageLoop(); | |
481 BalloonViewImpl* view = tester->GetBalloonView(collection, notify); | |
482 EXPECT_TRUE(tester->IsVisible(view)); | |
483 } | |
484 } | |
485 } | |
486 | |
487 // Seems to be flaky. http://crbug.com/84427 | |
488 IN_PROC_BROWSER_TEST_F(NotificationTest, DISABLED_TestActivateDeactivate) { | |
489 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
490 NotificationPanel* panel = GetNotificationPanel(); | |
491 NotificationPanelTester* tester = panel->GetTester(); | |
492 Profile* profile = browser()->profile(); | |
493 | |
494 collection->Add(NewMockNotification("1"), profile); | |
495 collection->AddSystemNotification( | |
496 NewMockNotification("2"), profile, true); | |
497 ui_test_utils::RunAllPendingInMessageLoop(); | |
498 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
499 BalloonViewImpl* view1 = | |
500 tester->GetBalloonView(collection, NewMockNotification("1")); | |
501 BalloonViewImpl* view2 = | |
502 tester->GetBalloonView(collection, NewMockNotification("2")); | |
503 // Wait until all renderers get size. | |
504 WaitForResize(view1); | |
505 WaitForResize(view2); | |
506 EXPECT_LT(view2->size().height(), 50) << "view size is bigger than expected"; | |
507 | |
508 panel->OnMouseMotion(gfx::Point(10, 50)); | |
509 EXPECT_TRUE(tester->IsActive(view1)); | |
510 EXPECT_FALSE(tester->IsActive(view2)); | |
511 | |
512 panel->OnMouseMotion(gfx::Point(10, 10)); | |
513 EXPECT_FALSE(tester->IsActive(view1)); | |
514 EXPECT_TRUE(tester->IsActive(view2)); | |
515 | |
516 panel->OnMouseMotion(gfx::Point(500, 500)); | |
517 EXPECT_FALSE(tester->IsActive(view1)); | |
518 EXPECT_FALSE(tester->IsActive(view2)); | |
519 } | |
520 | |
521 IN_PROC_BROWSER_TEST_F(NotificationTest, TestCloseDismissAllNonSticky) { | |
522 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
523 NotificationPanel* panel = GetNotificationPanel(); | |
524 NotificationPanelTester* tester = panel->GetTester(); | |
525 Profile* profile = browser()->profile(); | |
526 | |
527 collection->Add(NewMockNotification("1"), profile); | |
528 collection->AddSystemNotification( | |
529 NewMockNotification("2"), profile, true); | |
530 collection->Add(NewMockNotification("3"), profile); | |
531 | |
532 ui_test_utils::RunAllPendingInMessageLoop(); | |
533 EXPECT_EQ(NotificationPanel::STICKY_AND_NEW, tester->state()); | |
534 EXPECT_EQ(3, tester->GetNotificationCount()); | |
535 EXPECT_EQ(1, tester->GetStickyNotificationCount()); | |
536 | |
537 // Hide | |
538 panel->Hide(); | |
539 ui_test_utils::RunAllPendingInMessageLoop(); | |
540 EXPECT_EQ(1, tester->GetNotificationCount()); | |
541 EXPECT_EQ(1, tester->GetStickyNotificationCount()); | |
542 } | |
543 | |
544 IN_PROC_BROWSER_TEST_F(NotificationTest, TestAddWebUIMessageCallback) { | |
545 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
546 Profile* profile = browser()->profile(); | |
547 | |
548 collection->AddSystemNotification( | |
549 NewMockNotification("1"), profile, false); | |
550 | |
551 EXPECT_TRUE(collection->AddWebUIMessageCallback( | |
552 NewMockNotification("1"), | |
553 "test", | |
554 base::Bind(&NotificationTest::HandleWebUIMessage, | |
555 base::Unretained(static_cast<NotificationTest*>(this))))); | |
556 | |
557 // Adding callback for the same message twice should fail. | |
558 EXPECT_FALSE(collection->AddWebUIMessageCallback( | |
559 NewMockNotification("1"), | |
560 "test", | |
561 base::Bind(&NotificationTest::HandleWebUIMessage, | |
562 base::Unretained(static_cast<NotificationTest*>(this))))); | |
563 | |
564 // Adding callback to nonexistent notification should fail. | |
565 EXPECT_FALSE(collection->AddWebUIMessageCallback( | |
566 NewMockNotification("2"), | |
567 "test1", | |
568 base::Bind(&NotificationTest::HandleWebUIMessage, | |
569 base::Unretained(static_cast<NotificationTest*>(this))))); | |
570 } | |
571 | |
572 // Occasional crash: http://crbug.com/96461 | |
573 IN_PROC_BROWSER_TEST_F(NotificationTest, TestWebUIMessageCallback) { | |
574 BalloonCollectionImpl* collection = GetBalloonCollectionImpl(); | |
575 Profile* profile = browser()->profile(); | |
576 // A notification that sends 'test' WebUI message back to chrome. | |
577 const GURL content_url( | |
578 "data:text/html;charset=utf-8," | |
579 "<html><script>function send() { chrome.send('test', ['']); }</script>" | |
580 "<body onload='send()'></body></html>"); | |
581 collection->AddSystemNotification( | |
582 Notification(GURL(), content_url, string16(), string16(), | |
583 new MockNotificationDelegate("1")), | |
584 profile, | |
585 false); | |
586 EXPECT_TRUE(collection->AddWebUIMessageCallback( | |
587 NewMockNotification("1"), | |
588 "test", | |
589 base::Bind(&NotificationTest::HandleWebUIMessage, | |
590 base::Unretained(static_cast<NotificationTest*>(this))))); | |
591 MessageLoop::current()->Run(); | |
592 } | |
593 | |
594 } // namespace chromeos | |
OLD | NEW |