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

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

Issue 11753009: Simplify ExecuteJavaScript* functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update prerender_browsertest.cc. Created 7 years, 11 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 <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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 const char* icon, 265 const char* icon,
266 const char* title, 266 const char* title,
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::ExecuteScriptAndExtractString(
276 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), 276 browser->tab_strip_model()->GetActiveWebContents(),
277 "",
278 script, 277 script,
279 &result); 278 &result);
280 if (success && result != "-1" && wait_for_new_balloon) 279 if (success && result != "-1" && wait_for_new_balloon)
281 success = observer.Wait(); 280 success = observer.Wait();
282 EXPECT_TRUE(success); 281 EXPECT_TRUE(success);
283 282
284 return result; 283 return result;
285 } 284 }
286 285
287 std::string NotificationsTest::CreateSimpleNotification( 286 std::string NotificationsTest::CreateSimpleNotification(
288 Browser* browser, 287 Browser* browser,
289 bool wait_for_new_balloon) { 288 bool wait_for_new_balloon) {
290 return CreateNotification( 289 return CreateNotification(
291 browser, wait_for_new_balloon, 290 browser, wait_for_new_balloon,
292 "no_such_file.png", "My Title", "My Body", ""); 291 "no_such_file.png", "My Title", "My Body", "");
293 } 292 }
294 293
295 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) { 294 bool NotificationsTest::RequestPermissionAndWait(Browser* browser) {
296 InfoBarService* infobar_service = InfoBarService::FromWebContents( 295 InfoBarService* infobar_service = InfoBarService::FromWebContents(
297 browser->tab_strip_model()->GetActiveWebContents()); 296 browser->tab_strip_model()->GetActiveWebContents());
298 content::WindowedNotificationObserver observer( 297 content::WindowedNotificationObserver observer(
299 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, 298 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
300 content::Source<InfoBarService>(infobar_service)); 299 content::Source<InfoBarService>(infobar_service));
301 std::string result; 300 std::string result;
302 bool success = content::ExecuteJavaScriptAndExtractString( 301 bool success = content::ExecuteScriptAndExtractString(
303 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), 302 browser->tab_strip_model()->GetActiveWebContents(),
304 "",
305 "requestPermission();", 303 "requestPermission();",
306 &result); 304 &result);
307 if (!success || result != "1") 305 if (!success || result != "1")
308 return false; 306 return false;
309 observer.Wait(); 307 observer.Wait();
310 return true; 308 return true;
311 } 309 }
312 310
313 bool NotificationsTest::CancelNotification( 311 bool NotificationsTest::CancelNotification(
314 const char* notification_id, 312 const char* notification_id,
315 Browser* browser) { 313 Browser* browser) {
316 std::string script = base::StringPrintf( 314 std::string script = base::StringPrintf(
317 "cancelNotification('%s');", 315 "cancelNotification('%s');",
318 notification_id); 316 notification_id);
319 317
320 NotificationBalloonChangeObserver observer; 318 NotificationBalloonChangeObserver observer;
321 std::string result; 319 std::string result;
322 bool success = content::ExecuteJavaScriptAndExtractString( 320 bool success = content::ExecuteScriptAndExtractString(
323 browser->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), 321 browser->tab_strip_model()->GetActiveWebContents(),
324 "",
325 script, 322 script,
326 &result); 323 &result);
327 if (!success || result != "1") 324 if (!success || result != "1")
328 return false; 325 return false;
329 return observer.Wait(); 326 return observer.Wait();
330 } 327 }
331 328
332 bool NotificationsTest::PerformActionOnInfobar( 329 bool NotificationsTest::PerformActionOnInfobar(
333 Browser* browser, 330 Browser* browser,
334 InfobarAction action, 331 InfobarAction action,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428. 402 // If this flakes, use http://crbug.com/62311 and http://crbug.com/74428.
406 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) { 403 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestUserGestureInfobar) {
407 ui_test_utils::NavigateToURL( 404 ui_test_utils::NavigateToURL(
408 browser(), 405 browser(),
409 test_server()->GetURL( 406 test_server()->GetURL(
410 "files/notifications/notifications_request_function.html")); 407 "files/notifications/notifications_request_function.html"));
411 408
412 // Request permission by calling request() while eval'ing an inline script; 409 // 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. 410 // That's considered a user gesture to webkit, and should produce an infobar.
414 bool result; 411 bool result;
415 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( 412 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
416 browser()->tab_strip_model()->GetActiveWebContents()->GetRenderViewHost(), 413 browser()->tab_strip_model()->GetActiveWebContents(),
417 "",
418 "window.domAutomationController.send(request());", 414 "window.domAutomationController.send(request());",
419 &result)); 415 &result));
420 EXPECT_TRUE(result); 416 EXPECT_TRUE(result);
421 417
422 EXPECT_EQ(1U, InfoBarService::FromWebContents( 418 EXPECT_EQ(1U, InfoBarService::FromWebContents(
423 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount()); 419 browser()->tab_strip_model()->GetWebContentsAt(0))->GetInfoBarCount());
424 } 420 }
425 421
426 // If this flakes, use http://crbug.com/62311. 422 // If this flakes, use http://crbug.com/62311.
427 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) { 423 IN_PROC_BROWSER_TEST_F(NotificationsTest, TestNoUserGestureInfobar) {
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 const std::deque<Balloon*>& balloons = GetActiveBalloons(); 781 const std::deque<Balloon*>& balloons = GetActiveBalloons();
786 EXPECT_EQ(1U, balloons.size()); 782 EXPECT_EQ(1U, balloons.size());
787 const Notification& notification = balloons[0]->notification(); 783 const Notification& notification = balloons[0]->notification();
788 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl); 784 GURL EXPECTED_ICON_URL = test_server()->GetURL(kExpectedIconUrl);
789 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url()); 785 EXPECT_EQ(EXPECTED_ICON_URL, notification.icon_url());
790 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title()); 786 EXPECT_EQ(ASCIIToUTF16("Title2"), notification.title());
791 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body()); 787 EXPECT_EQ(ASCIIToUTF16("Body2"), notification.body());
792 } 788 }
793 789
794 #endif // !defined(OS_CHROMEOS) 790 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/browser/net/load_timing_observer_browsertest.cc ('k') | chrome/browser/policy/policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698