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

Side by Side Diff: chrome/browser/extensions/extension_browsertest.cc

Issue 10795090: Move ExecuteJavaScript functions from ui_test_utils.h to browser_test_utils.h so they can be reused… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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/extensions/extension_browsertest.h" 5 #include "chrome/browser/extensions/extension_browsertest.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/common/chrome_notification_types.h" 29 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/chrome_switches.h" 31 #include "chrome/common/chrome_switches.h"
32 #include "chrome/common/extensions/features/feature.h" 32 #include "chrome/common/extensions/features/feature.h"
33 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
34 #include "content/public/browser/navigation_controller.h" 34 #include "content/public/browser/navigation_controller.h"
35 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
36 #include "content/public/browser/notification_registrar.h" 36 #include "content/public/browser/notification_registrar.h"
37 #include "content/public/browser/notification_service.h" 37 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
39 #include "content/public/test/browser_test_utils.h"
39 40
40 using extensions::Extension; 41 using extensions::Extension;
41 using extensions::ExtensionCreator; 42 using extensions::ExtensionCreator;
42 43
43 ExtensionBrowserTest::ExtensionBrowserTest() 44 ExtensionBrowserTest::ExtensionBrowserTest()
44 : loaded_(false), 45 : loaded_(false),
45 installed_(false), 46 installed_(false),
46 extension_installs_observed_(0), 47 extension_installs_observed_(0),
47 extension_load_errors_observed_(0), 48 extension_load_errors_observed_(0),
48 target_page_action_count_(-1), 49 target_page_action_count_(-1),
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 return crx_installers_done_observed_ == (before + 1); 487 return crx_installers_done_observed_ == (before + 1);
487 } 488 }
488 489
489 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, 490 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents,
490 const GURL& url, 491 const GURL& url,
491 bool newtab_process_should_equal_opener, 492 bool newtab_process_should_equal_opener,
492 content::WebContents** newtab_result) { 493 content::WebContents** newtab_result) {
493 content::WindowedNotificationObserver observer( 494 content::WindowedNotificationObserver observer(
494 content::NOTIFICATION_LOAD_STOP, 495 content::NOTIFICATION_LOAD_STOP,
495 content::NotificationService::AllSources()); 496 content::NotificationService::AllSources());
496 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 497 ASSERT_TRUE(content::ExecuteJavaScript(
497 contents->GetRenderViewHost(), L"", 498 contents->GetRenderViewHost(), L"",
498 L"window.open('" + UTF8ToWide(url.spec()) + L"');")); 499 L"window.open('" + UTF8ToWide(url.spec()) + L"');"));
499 500
500 // The above window.open call is not user-initiated, so it will create 501 // The above window.open call is not user-initiated, so it will create
501 // a popup window instead of a new tab in current window. 502 // a popup window instead of a new tab in current window.
502 // The stop notification will come from the new tab. 503 // The stop notification will come from the new tab.
503 observer.Wait(); 504 observer.Wait();
504 content::NavigationController* controller = 505 content::NavigationController* controller =
505 content::Source<content::NavigationController>(observer.source()).ptr(); 506 content::Source<content::NavigationController>(observer.source()).ptr();
506 content::WebContents* newtab = controller->GetWebContents(); 507 content::WebContents* newtab = controller->GetWebContents();
507 ASSERT_TRUE(newtab); 508 ASSERT_TRUE(newtab);
508 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL()); 509 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL());
509 if (newtab_process_should_equal_opener) 510 if (newtab_process_should_equal_opener)
510 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); 511 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
511 else 512 else
512 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); 513 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost());
513 514
514 if (newtab_result) 515 if (newtab_result)
515 *newtab_result = newtab; 516 *newtab_result = newtab;
516 } 517 }
517 518
518 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents, 519 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents,
519 const GURL& url) { 520 const GURL& url) {
520 bool result = false; 521 bool result = false;
521 content::WindowedNotificationObserver observer( 522 content::WindowedNotificationObserver observer(
522 content::NOTIFICATION_LOAD_STOP, 523 content::NOTIFICATION_LOAD_STOP,
523 content::NotificationService::AllSources()); 524 content::NotificationService::AllSources());
524 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 525 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool(
525 contents->GetRenderViewHost(), L"", 526 contents->GetRenderViewHost(), L"",
526 L"window.addEventListener('unload', function() {" 527 L"window.addEventListener('unload', function() {"
527 L" window.domAutomationController.send(true);" 528 L" window.domAutomationController.send(true);"
528 L"}, false);" 529 L"}, false);"
529 L"window.location = '" + UTF8ToWide(url.spec()) + L"';", 530 L"window.location = '" + UTF8ToWide(url.spec()) + L"';",
530 &result)); 531 &result));
531 ASSERT_TRUE(result); 532 ASSERT_TRUE(result);
532 observer.Wait(); 533 observer.Wait();
533 EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL()); 534 EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL());
534 } 535 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 case content::NOTIFICATION_LOAD_STOP: 632 case content::NOTIFICATION_LOAD_STOP:
632 VLOG(1) << "Got LOAD_STOP notification."; 633 VLOG(1) << "Got LOAD_STOP notification.";
633 MessageLoopForUI::current()->Quit(); 634 MessageLoopForUI::current()->Quit();
634 break; 635 break;
635 636
636 default: 637 default:
637 NOTREACHED(); 638 NOTREACHED();
638 break; 639 break;
639 } 640 }
640 } 641 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_bindings_apitest.cc ('k') | chrome/browser/extensions/extension_devtools_browsertests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698