| OLD | NEW |
| 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 <deque> | 5 #include <deque> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 const char* body, | 267 const char* body, |
| 268 const char* replace_id) { | 268 const char* replace_id) { |
| 269 std::string script = base::StringPrintf( | 269 std::string script = base::StringPrintf( |
| 270 "createNotification('%s', '%s', '%s', '%s');", | 270 "createNotification('%s', '%s', '%s', '%s');", |
| 271 icon, title, body, replace_id); | 271 icon, title, body, replace_id); |
| 272 | 272 |
| 273 NotificationBalloonChangeObserver observer; | 273 NotificationBalloonChangeObserver observer; |
| 274 std::string result; | 274 std::string result; |
| 275 bool success = content::ExecuteJavaScriptAndExtractString( | 275 bool success = content::ExecuteJavaScriptAndExtractString( |
| 276 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 276 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
| 277 "", | 277 L"", |
| 278 script, | 278 UTF8ToWide(script), |
| 279 &result); | 279 &result); |
| 280 if (success && result != "-1" && wait_for_new_balloon) | 280 if (success && result != "-1" && wait_for_new_balloon) |
| 281 success = observer.Wait(); | 281 success = observer.Wait(); |
| 282 EXPECT_TRUE(success); | 282 EXPECT_TRUE(success); |
| 283 | 283 |
| 284 return result; | 284 return result; |
| 285 } | 285 } |
| 286 | 286 |
| 287 std::string NotificationsTest::CreateSimpleNotification( | 287 std::string NotificationsTest::CreateSimpleNotification( |
| 288 Browser* browser, | 288 Browser* browser, |
| 289 bool wait_for_new_balloon) { | 289 bool wait_for_new_balloon) { |
| 290 return CreateNotification( | 290 return CreateNotification( |
| 291 browser, wait_for_new_balloon, | 291 browser, wait_for_new_balloon, |
| 292 "no_such_file.png", "My Title", "My Body", ""); | 292 "no_such_file.png", "My Title", "My Body", ""); |
| 293 } | 293 } |
| 294 | 294 |
| 295 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) { | 295 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) { |
| 296 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 296 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 297 browser->tab_strip_model()->GetActiveWebContents()); | 297 browser->tab_strip_model()->GetActiveWebContents()); |
| 298 content::WindowedNotificationObserver observer( | 298 content::WindowedNotificationObserver observer( |
| 299 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 299 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 300 content::Source<InfoBarService>(infobar_service)); | 300 content::Source<InfoBarService>(infobar_service)); |
| 301 std::string result; | 301 std::string result; |
| 302 bool success = content::ExecuteJavaScriptAndExtractString( | 302 bool success = content::ExecuteJavaScriptAndExtractString( |
| 303 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 303 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
| 304 "", | 304 L"", |
| 305 "requestPermission();", | 305 L"requestPermission();", |
| 306 &result); | 306 &result); |
| 307 if (!success || result != "1") | 307 if (!success || result != "1") |
| 308 return false; | 308 return false; |
| 309 observer.Wait(); | 309 observer.Wait(); |
| 310 return true; | 310 return true; |
| 311 } | 311 } |
| 312 | 312 |
| 313 bool NotificationsTest::CancelNotification( | 313 bool NotificationsTest::CancelNotification( |
| 314 const char* notification_id, | 314 const char* notification_id, |
| 315 Browser* browser) { | 315 Browser* browser) { |
| 316 std::string script = base::StringPrintf( | 316 std::string script = base::StringPrintf( |
| 317 "cancelNotification('%s');", | 317 "cancelNotification('%s');", |
| 318 notification_id); | 318 notification_id); |
| 319 | 319 |
| 320 NotificationBalloonChangeObserver observer; | 320 NotificationBalloonChangeObserver observer; |
| 321 std::string result; | 321 std::string result; |
| 322 bool success = content::ExecuteJavaScriptAndExtractString( | 322 bool success = content::ExecuteJavaScriptAndExtractString( |
| 323 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 323 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
| 324 "", | 324 L"", |
| 325 script, | 325 UTF8ToWide(script), |
| 326 &result); | 326 &result); |
| 327 if (!success || result != "1") | 327 if (!success || result != "1") |
| 328 return false; | 328 return false; |
| 329 return observer.Wait(); | 329 return observer.Wait(); |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool NotificationsTest::PerformActionOnInfobar( | 332 bool NotificationsTest::PerformActionOnInfobar( |
| 333 Browser* browser, | 333 Browser* browser, |
| 334 InfobarAction action, | 334 InfobarAction action, |
| 335 int infobar_index, | 335 int infobar_index, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 ui_test_utils::NavigateToURL( | 407 ui_test_utils::NavigateToURL( |
| 408 browser(), | 408 browser(), |
| 409 test_server()->GetURL( | 409 test_server()->GetURL( |
| 410 "files/notifications/notifications_request_function.html")); | 410 "files/notifications/notifications_request_function.html")); |
| 411 | 411 |
| 412 // Request permission by calling request() while eval'ing an inline script; | 412 // Request permission by calling request() while eval'ing an inline script; |
| 413 // That's considered a user gesture to webkit, and should produce an infobar. | 413 // That's considered a user gesture to webkit, and should produce an infobar. |
| 414 bool result; | 414 bool result; |
| 415 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 415 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 416 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), | 416 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), |
| 417 "", | 417 L"", |
| 418 "window.domAutomationController.send(request());", | 418 L"window.domAutomationController.send(request());", |
| 419 &result)); | 419 &result)); |
| 420 EXPECT_TRUE(result); | 420 EXPECT_TRUE(result); |
| 421 | 421 |
| 422 EXPECT_EQ(1U, InfoBarService::FromWebContents( | 422 EXPECT_EQ(1U, InfoBarService::FromWebContents( |
| 423 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); | 423 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); |
| 424 } | 424 } |
| 425 | 425 |
| 426 // If this flakes, use http://crbug.com/62311. | 426 // If this flakes, use http://crbug.com/62311. |
| 427 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { | 427 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { |
| 428 // Load a page which just does a request; no user gesture should result | 428 // Load a page which just does a request; no user gesture should result |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 const std::deque<Balloon*>& balloons = GetActiveBalloons(); | 785 const std::deque<Balloon*>& balloons = GetActiveBalloons(); |
| 786 EXPECT_EQ(1U, balloons.size()); | 786 EXPECT_EQ(1U, balloons.size()); |
| 787 const Notification& notification = balloons[0]->notification(); | 787 const Notification& notification = balloons[0]->notification(); |
| 788 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); | 788 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); |
| 789 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); | 789 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); |
| 790 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); | 790 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); |
| 791 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); | 791 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); |
| 792 } | 792 } |
| 793 | 793 |
| 794 #endif // !defined(OS_CHROMEOS) | 794 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |