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 "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 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 return crx_installers_done_observed_ == (before + 1); | 545 return crx_installers_done_observed_ == (before + 1); |
546 } | 546 } |
547 | 547 |
548 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, | 548 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, |
549 const GURL& url, | 549 const GURL& url, |
550 bool newtab_process_should_equal_opener, | 550 bool newtab_process_should_equal_opener, |
551 content::WebContents** newtab_result) { | 551 content::WebContents** newtab_result) { |
552 content::WindowedNotificationObserver observer( | 552 content::WindowedNotificationObserver observer( |
553 content::NOTIFICATION_LOAD_STOP, | 553 content::NOTIFICATION_LOAD_STOP, |
554 content::NotificationService::AllSources()); | 554 content::NotificationService::AllSources()); |
555 ASSERT_TRUE(content::ExecuteJavaScript( | 555 ASSERT_TRUE(content::ExecuteScript(contents, |
556 contents->GetRenderViewHost(), | 556 "window.open('" + url.spec() + "');")); |
557 "", | |
558 "window.open('" + url.spec() + "');")); | |
559 | 557 |
560 // The above window.open call is not user-initiated, so it will create | 558 // The above window.open call is not user-initiated, so it will create |
561 // a popup window instead of a new tab in current window. | 559 // a popup window instead of a new tab in current window. |
562 // The stop notification will come from the new tab. | 560 // The stop notification will come from the new tab. |
563 observer.Wait(); | 561 observer.Wait(); |
564 content::NavigationController* controller = | 562 content::NavigationController* controller = |
565 content::Source<content::NavigationController>(observer.source()).ptr(); | 563 content::Source<content::NavigationController>(observer.source()).ptr(); |
566 content::WebContents* newtab = controller->GetWebContents(); | 564 content::WebContents* newtab = controller->GetWebContents(); |
567 ASSERT_TRUE(newtab); | 565 ASSERT_TRUE(newtab); |
568 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL()); | 566 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL()); |
569 if (newtab_process_should_equal_opener) | 567 if (newtab_process_should_equal_opener) |
570 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); | 568 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); |
571 else | 569 else |
572 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); | 570 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); |
573 | 571 |
574 if (newtab_result) | 572 if (newtab_result) |
575 *newtab_result = newtab; | 573 *newtab_result = newtab; |
576 } | 574 } |
577 | 575 |
578 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents, | 576 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents, |
579 const GURL& url) { | 577 const GURL& url) { |
580 bool result = false; | 578 bool result = false; |
581 content::WindowedNotificationObserver observer( | 579 content::WindowedNotificationObserver observer( |
582 content::NOTIFICATION_LOAD_STOP, | 580 content::NOTIFICATION_LOAD_STOP, |
583 content::NotificationService::AllSources()); | 581 content::NotificationService::AllSources()); |
584 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 582 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
585 contents->GetRenderViewHost(), | 583 contents, |
586 "", | |
587 "window.addEventListener('unload', function() {" | 584 "window.addEventListener('unload', function() {" |
588 " window.domAutomationController.send(true);" | 585 " window.domAutomationController.send(true);" |
589 "}, false);" | 586 "}, false);" |
590 "window.location = '" + url.spec() + "';", | 587 "window.location = '" + url.spec() + "';", |
591 &result)); | 588 &result)); |
592 ASSERT_TRUE(result); | 589 ASSERT_TRUE(result); |
593 observer.Wait(); | 590 observer.Wait(); |
594 EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL()); | 591 EXPECT_EQ(url, contents->GetController().GetLastCommittedEntry()->GetURL()); |
595 } | 592 } |
596 | 593 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 case content::NOTIFICATION_LOAD_STOP: | 689 case content::NOTIFICATION_LOAD_STOP: |
693 VLOG(1) << "Got LOAD_STOP notification."; | 690 VLOG(1) << "Got LOAD_STOP notification."; |
694 MessageLoopForUI::current()->Quit(); | 691 MessageLoopForUI::current()->Quit(); |
695 break; | 692 break; |
696 | 693 |
697 default: | 694 default: |
698 NOTREACHED(); | 695 NOTREACHED(); |
699 break; | 696 break; |
700 } | 697 } |
701 } | 698 } |
OLD | NEW |