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

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

Issue 2830893002: Refactor of ExtensionNavigationThrottle (Closed)
Patch Set: Fix ExtensionBrowserTest.WindowOpenInvalidExtension under PlzNavigate Created 3 years, 7 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 29 matching lines...) Expand all
40 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" 40 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h"
41 #include "chrome/browser/ui/tabs/tab_strip_model.h" 41 #include "chrome/browser/ui/tabs/tab_strip_model.h"
42 #include "chrome/common/chrome_paths.h" 42 #include "chrome/common/chrome_paths.h"
43 #include "chrome/common/chrome_switches.h" 43 #include "chrome/common/chrome_switches.h"
44 #include "components/sync/model/string_ordinal.h" 44 #include "components/sync/model/string_ordinal.h"
45 #include "components/version_info/version_info.h" 45 #include "components/version_info/version_info.h"
46 #include "content/public/browser/navigation_controller.h" 46 #include "content/public/browser/navigation_controller.h"
47 #include "content/public/browser/navigation_entry.h" 47 #include "content/public/browser/navigation_entry.h"
48 #include "content/public/browser/notification_registrar.h" 48 #include "content/public/browser/notification_registrar.h"
49 #include "content/public/browser/notification_service.h" 49 #include "content/public/browser/notification_service.h"
50 #include "content/public/browser/render_frame_host.h"
50 #include "content/public/browser/render_view_host.h" 51 #include "content/public/browser/render_view_host.h"
51 #include "content/public/test/browser_test_utils.h" 52 #include "content/public/test/browser_test_utils.h"
52 #include "content/public/test/test_utils.h" 53 #include "content/public/test/test_utils.h"
53 #include "extensions/browser/extension_dialog_auto_confirm.h" 54 #include "extensions/browser/extension_dialog_auto_confirm.h"
54 #include "extensions/browser/extension_host.h" 55 #include "extensions/browser/extension_host.h"
55 #include "extensions/browser/extension_prefs.h" 56 #include "extensions/browser/extension_prefs.h"
56 #include "extensions/browser/extension_registry.h" 57 #include "extensions/browser/extension_registry.h"
57 #include "extensions/browser/extension_system.h" 58 #include "extensions/browser/extension_system.h"
58 #include "extensions/browser/notification_types.h" 59 #include "extensions/browser/notification_types.h"
59 #include "extensions/browser/test_extension_registry_observer.h" 60 #include "extensions/browser/test_extension_registry_observer.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 528
528 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) { 529 void ExtensionBrowserTest::EnableExtension(const std::string& extension_id) {
529 ExtensionService* service = extensions::ExtensionSystem::Get( 530 ExtensionService* service = extensions::ExtensionSystem::Get(
530 profile())->extension_service(); 531 profile())->extension_service();
531 service->EnableExtension(extension_id); 532 service->EnableExtension(extension_id);
532 } 533 }
533 534
534 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents, 535 void ExtensionBrowserTest::OpenWindow(content::WebContents* contents,
535 const GURL& url, 536 const GURL& url,
536 bool newtab_process_should_equal_opener, 537 bool newtab_process_should_equal_opener,
537 content::WebContents** newtab_result) { 538 content::WebContents** newtab_result) {
ncarter (slow) 2017/05/01 21:50:37 I did some robustness/readability cleanup here whi
538 content::WindowedNotificationObserver windowed_observer( 539 content::WebContentsAddedObserver tab_added_observer;
539 content::NOTIFICATION_LOAD_STOP,
540 content::NotificationService::AllSources());
541 ASSERT_TRUE(content::ExecuteScript(contents, 540 ASSERT_TRUE(content::ExecuteScript(contents,
542 "window.open('" + url.spec() + "');")); 541 "window.open('" + url.spec() + "');"));
543 542 content::WebContents* newtab = tab_added_observer.GetWebContents();
544 // The above window.open call is not user-initiated, so it will create
545 // a popup window instead of a new tab in current window.
546 // The stop notification will come from the new tab.
547 windowed_observer.Wait();
548 content::NavigationController* controller =
549 content::Source<content::NavigationController>(
550 windowed_observer.source()).ptr();
551 content::WebContents* newtab = controller->GetWebContents();
552 ASSERT_TRUE(newtab); 543 ASSERT_TRUE(newtab);
553 EXPECT_EQ(url, controller->GetLastCommittedEntry()->GetURL()); 544 WaitForLoadStop(newtab);
554 if (newtab_process_should_equal_opener) 545 EXPECT_EQ(url, newtab->GetLastCommittedURL());
555 EXPECT_EQ(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); 546 if (newtab_process_should_equal_opener) {
556 else 547 EXPECT_EQ(contents->GetMainFrame()->GetSiteInstance(),
557 EXPECT_NE(contents->GetRenderProcessHost(), newtab->GetRenderProcessHost()); 548 newtab->GetMainFrame()->GetSiteInstance());
549 } else {
550 EXPECT_NE(contents->GetMainFrame()->GetSiteInstance(),
551 newtab->GetMainFrame()->GetSiteInstance());
552 }
558 553
559 if (newtab_result) 554 if (newtab_result)
560 *newtab_result = newtab; 555 *newtab_result = newtab;
561 } 556 }
562 557
563 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents, 558 void ExtensionBrowserTest::NavigateInRenderer(content::WebContents* contents,
564 const GURL& url) { 559 const GURL& url) {
565 // Ensure any existing navigations complete before trying to navigate anew, to 560 // Ensure any existing navigations complete before trying to navigate anew, to
566 // avoid triggering of the unload event for the wrong navigation. 561 // avoid triggering of the unload event for the wrong navigation.
567 content::WaitForLoadStop(contents); 562 content::WaitForLoadStop(contents);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 return extensions::browsertest_util::ExecuteScriptInBackgroundPage( 599 return extensions::browsertest_util::ExecuteScriptInBackgroundPage(
605 profile(), extension_id, script); 600 profile(), extension_id, script);
606 } 601 }
607 602
608 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait( 603 bool ExtensionBrowserTest::ExecuteScriptInBackgroundPageNoWait(
609 const std::string& extension_id, 604 const std::string& extension_id,
610 const std::string& script) { 605 const std::string& script) {
611 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait( 606 return extensions::browsertest_util::ExecuteScriptInBackgroundPageNoWait(
612 profile(), extension_id, script); 607 profile(), extension_id, script);
613 } 608 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698