| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" | 41 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" |
| 42 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 42 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 43 #include "chrome/common/chrome_paths.h" | 43 #include "chrome/common/chrome_paths.h" |
| 44 #include "chrome/common/chrome_switches.h" | 44 #include "chrome/common/chrome_switches.h" |
| 45 #include "components/sync/model/string_ordinal.h" | 45 #include "components/sync/model/string_ordinal.h" |
| 46 #include "components/version_info/version_info.h" | 46 #include "components/version_info/version_info.h" |
| 47 #include "content/public/browser/navigation_controller.h" | 47 #include "content/public/browser/navigation_controller.h" |
| 48 #include "content/public/browser/navigation_entry.h" | 48 #include "content/public/browser/navigation_entry.h" |
| 49 #include "content/public/browser/notification_registrar.h" | 49 #include "content/public/browser/notification_registrar.h" |
| 50 #include "content/public/browser/notification_service.h" | 50 #include "content/public/browser/notification_service.h" |
| 51 #include "content/public/browser/render_frame_host.h" |
| 51 #include "content/public/browser/render_view_host.h" | 52 #include "content/public/browser/render_view_host.h" |
| 52 #include "content/public/test/browser_test_utils.h" | 53 #include "content/public/test/browser_test_utils.h" |
| 53 #include "content/public/test/test_utils.h" | 54 #include "content/public/test/test_utils.h" |
| 54 #include "extensions/browser/extension_dialog_auto_confirm.h" | 55 #include "extensions/browser/extension_dialog_auto_confirm.h" |
| 55 #include "extensions/browser/extension_host.h" | 56 #include "extensions/browser/extension_host.h" |
| 56 #include "extensions/browser/extension_prefs.h" | 57 #include "extensions/browser/extension_prefs.h" |
| 57 #include "extensions/browser/extension_registry.h" | 58 #include "extensions/browser/extension_registry.h" |
| 58 #include "extensions/browser/extension_system.h" | 59 #include "extensions/browser/extension_system.h" |
| 59 #include "extensions/browser/notification_types.h" | 60 #include "extensions/browser/notification_types.h" |
| 60 #include "extensions/browser/test_extension_registry_observer.h" | 61 #include "extensions/browser/test_extension_registry_observer.h" |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { | 534 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { |
| 534 ExtensionService* service = extensions::ExtensionSystem::Get( | 535 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 535 profile())->extension_service(); | 536 profile())->extension_service(); |
| 536 service->EnableExtension(extension_id); | 537 service->EnableExtension(extension_id); |
| 537 } | 538 } |
| 538 | 539 |
| 539 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, | 540 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, |
| 540 const GURL& url, | 541 const GURL& url, |
| 541 bool newtab_process_should_equal_opener, | 542 bool newtab_process_should_equal_opener, |
| 542 content::WebContents** newtab_result) { | 543 content::WebContents** newtab_result) { |
| 543 content::WindowedNotificationObserver windowed_observer( | 544 content::WebContentsAddedObserver tab_added_observer; |
| 544 content::NOTIFICATION_LOAD_STOP, | |
| 545 content::NotificationService::AllSources()); | |
| 546 ASSERT_TRUE(content::ExecuteScript(contents, | 545 ASSERT_TRUE(content::ExecuteScript(contents, |
| 547 "window.open('" + url.spec() + "');")); | 546 "window.open('" + url.spec() + "');")); |
| 548 | 547 content::WebContents* newtab = tab_added_observer.GetWebContents(); |
| 549 // The above window.open call is not user-initiated, so it will create | |
| 550 // a popup window instead of a new tab in current window. | |
| 551 // The stop notification will come from the new tab. | |
| 552 windowed_observer.Wait(); | |
| 553 content::NavigationController* controller = | |
| 554 content::Source<content::NavigationController>( | |
| 555 windowed_observer.source()).ptr(); | |
| 556 content::WebContents* newtab = controller->GetWebContents(); | |
| 557 ASSERT_TRUE(newtab); | 548 ASSERT_TRUE(newtab); |
| 558 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL()); | 549 WaitForLoadStop(newtab); |
| 559 if (newtab_process_should_equal_opener) | 550 EXPECT_EQ(url, newtab->GetLastCommittedURL()); |
| 560 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); | 551 if (newtab_process_should_equal_opener) { |
| 561 else | 552 EXPECT_EQ(contents->GetMainFrame()->GetSiteInstance(), |
| 562 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); | 553 newtab->GetMainFrame()->GetSiteInstance()); |
| 554 } else { |
| 555 EXPECT_NE(contents->GetMainFrame()->GetSiteInstance(), |
| 556 newtab->GetMainFrame()->GetSiteInstance()); |
| 557 } |
| 563 | 558 |
| 564 if (newtab_result) | 559 if (newtab_result) |
| 565 *newtab_result = newtab; | 560 *newtab_result = newtab; |
| 566 } | 561 } |
| 567 | 562 |
| 568 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents, | 563 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents, |
| 569 const GURL& url) { | 564 const GURL& url) { |
| 570 // Ensure any existing navigations complete before trying to navigate anew, to | 565 // Ensure any existing navigations complete before trying to navigate anew, to |
| 571 // avoid triggering of the unload event for the wrong navigation. | 566 // avoid triggering of the unload event for the wrong navigation. |
| 572 content::WaitForLoadStop(contents); | 567 content::WaitForLoadStop(contents); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 604 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
| 610 profile(), extension_id, script); | 605 profile(), extension_id, script); |
| 611 } | 606 } |
| 612 | 607 |
| 613 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( | 608 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( |
| 614 const std::string& extension_id, | 609 const std::string& extension_id, |
| 615 const std::string& script) { | 610 const std::string& script) { |
| 616 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( | 611 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( |
| 617 profile(), extension_id, script); | 612 profile(), extension_id, script); |
| 618 } | 613 } |
| OLD | NEW |