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