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

Side by Side Diff: chrome/browser/ui/browser_browsertest.cc

Issue 2757863002: SearchTabHelper: Find browser/window instead of having them passed in (Closed)
Patch Set: review Created 3 years, 9 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
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "chrome/browser/ui/browser_commands.h" 49 #include "chrome/browser/ui/browser_commands.h"
50 #include "chrome/browser/ui/browser_finder.h" 50 #include "chrome/browser/ui/browser_finder.h"
51 #include "chrome/browser/ui/browser_list.h" 51 #include "chrome/browser/ui/browser_list.h"
52 #include "chrome/browser/ui/browser_tabstrip.h" 52 #include "chrome/browser/ui/browser_tabstrip.h"
53 #include "chrome/browser/ui/browser_ui_prefs.h" 53 #include "chrome/browser/ui/browser_ui_prefs.h"
54 #include "chrome/browser/ui/browser_window.h" 54 #include "chrome/browser/ui/browser_window.h"
55 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h" 55 #include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
56 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" 56 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
57 #include "chrome/browser/ui/extensions/app_launch_params.h" 57 #include "chrome/browser/ui/extensions/app_launch_params.h"
58 #include "chrome/browser/ui/extensions/application_launch.h" 58 #include "chrome/browser/ui/extensions/application_launch.h"
59 #include "chrome/browser/ui/search/search_tab_helper.h"
59 #include "chrome/browser/ui/startup/startup_browser_creator.h" 60 #include "chrome/browser/ui/startup/startup_browser_creator.h"
60 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h" 61 #include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
61 #include "chrome/browser/ui/tabs/pinned_tab_codec.h" 62 #include "chrome/browser/ui/tabs/pinned_tab_codec.h"
62 #include "chrome/browser/ui/tabs/tab_strip_model.h" 63 #include "chrome/browser/ui/tabs/tab_strip_model.h"
63 #include "chrome/common/chrome_paths.h" 64 #include "chrome/common/chrome_paths.h"
64 #include "chrome/common/chrome_switches.h" 65 #include "chrome/common/chrome_switches.h"
65 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 66 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
66 #include "chrome/common/pref_names.h" 67 #include "chrome/common/pref_names.h"
67 #include "chrome/common/url_constants.h" 68 #include "chrome/common/url_constants.h"
68 #include "chrome/grit/chromium_strings.h" 69 #include "chrome/grit/chromium_strings.h"
69 #include "chrome/grit/generated_resources.h" 70 #include "chrome/grit/generated_resources.h"
70 #include "chrome/test/base/in_process_browser_test.h" 71 #include "chrome/test/base/in_process_browser_test.h"
71 #include "chrome/test/base/ui_test_utils.h" 72 #include "chrome/test/base/ui_test_utils.h"
72 #include "components/app_modal/app_modal_dialog.h" 73 #include "components/app_modal/app_modal_dialog.h"
73 #include "components/app_modal/app_modal_dialog_queue.h" 74 #include "components/app_modal/app_modal_dialog_queue.h"
74 #include "components/app_modal/javascript_app_modal_dialog.h" 75 #include "components/app_modal/javascript_app_modal_dialog.h"
75 #include "components/app_modal/native_app_modal_dialog.h" 76 #include "components/app_modal/native_app_modal_dialog.h"
76 #include "components/content_settings/core/browser/host_content_settings_map.h" 77 #include "components/content_settings/core/browser/host_content_settings_map.h"
78 #include "components/omnibox/common/omnibox_focus_state.h"
77 #include "components/prefs/pref_service.h" 79 #include "components/prefs/pref_service.h"
78 #include "components/sessions/core/base_session_service_test_helper.h" 80 #include "components/sessions/core/base_session_service_test_helper.h"
79 #include "components/translate/core/browser/language_state.h" 81 #include "components/translate/core/browser/language_state.h"
80 #include "components/translate/core/common/language_detection_details.h" 82 #include "components/translate/core/common/language_detection_details.h"
81 #include "content/public/browser/favicon_status.h" 83 #include "content/public/browser/favicon_status.h"
82 #include "content/public/browser/host_zoom_map.h" 84 #include "content/public/browser/host_zoom_map.h"
83 #include "content/public/browser/interstitial_page.h" 85 #include "content/public/browser/interstitial_page.h"
84 #include "content/public/browser/interstitial_page_delegate.h" 86 #include "content/public/browser/interstitial_page_delegate.h"
85 #include "content/public/browser/navigation_entry.h" 87 #include "content/public/browser/navigation_entry.h"
86 #include "content/public/browser/navigation_handle.h" 88 #include "content/public/browser/navigation_handle.h"
(...skipping 1421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); 1510 dev_tools_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR));
1509 1511
1510 // App windows can show location bars, for example when they navigate away 1512 // App windows can show location bars, for example when they navigate away
1511 // from their starting origin. 1513 // from their starting origin.
1512 EXPECT_TRUE( 1514 EXPECT_TRUE(
1513 app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR)); 1515 app_browser->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR));
1514 1516
1515 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window); 1517 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
1516 } 1518 }
1517 1519
1520 // Regression test for crbug.com/702505.
1521 IN_PROC_BROWSER_TEST_F(BrowserTest, ReattachDevToolsWindow) {
1522 ASSERT_TRUE(embedded_test_server()->Start());
1523 WebContents* web_contents =
1524 browser()->tab_strip_model()->GetActiveWebContents();
1525 GURL ntp_url(search::GetNewTabPageURL(browser()->profile()));
Peter Kasting 2017/03/20 20:11:10 Nit: Prefer = to () in this case; see https://www.
Marc Treib 2017/03/21 08:49:08 Done.
1526 ui_test_utils::NavigateToURL(browser(), ntp_url);
1527
1528 // Open a devtools window.
1529 DevToolsWindow* devtools_window =
1530 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(),
1531 /*is_docked=*/true);
1532 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile()));
1533
1534 // Grab its main web contents.
1535 content::WebContents* devtools_main_web_contents =
1536 DevToolsWindow::GetInTabWebContents(
1537 devtools_window->GetInspectedWebContents(), nullptr);
1538 ASSERT_NE(web_contents, devtools_main_web_contents);
1539
1540 // Detach the devtools window.
1541 DevToolsUIBindings::Delegate* devtools_delegate =
1542 static_cast<DevToolsUIBindings::Delegate*>(devtools_window);
1543 devtools_delegate->SetIsDocked(false);
1544
1545 // This should have created a new dev tools browser.
1546 ASSERT_EQ(2u, chrome::GetBrowserCount(browser()->profile()));
1547
1548 // Re-attach the dev tools window. This resets its Browser*.
1549 devtools_delegate->SetIsDocked(true);
1550 // Wait until the browser actually gets closed.
1551 content::RunAllPendingInMessageLoop();
1552 ASSERT_EQ(1u, chrome::GetBrowserCount(browser()->profile()));
1553
1554 // Do something that will make SearchTabHelper access its OmniboxView. This
1555 // should not crash, even though the Browser association and thus the
1556 // OmniboxView* has changed, and the old OmniboxVie has been deleted.
Peter Kasting 2017/03/20 20:11:10 Nit: old OmniboxView
Marc Treib 2017/03/21 08:49:08 Done.
1557 SearchTabHelper* search_tab_helper =
1558 SearchTabHelper::FromWebContents(devtools_main_web_contents);
1559 SearchIPCRouter::Delegate* search_ipc_router_delegate =
1560 static_cast<SearchIPCRouter::Delegate*>(search_tab_helper);
1561 search_ipc_router_delegate->FocusOmnibox(OMNIBOX_FOCUS_INVISIBLE);
1562
1563 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
1564 }
1565
1518 // Chromeos defaults to restoring the last session, so this test isn't 1566 // Chromeos defaults to restoring the last session, so this test isn't
1519 // applicable. 1567 // applicable.
1520 #if !defined(OS_CHROMEOS) 1568 #if !defined(OS_CHROMEOS)
1521 // Makes sure pinned tabs are restored correctly on start. 1569 // Makes sure pinned tabs are restored correctly on start.
1522 IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { 1570 IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) {
1523 ASSERT_TRUE(embedded_test_server()->Start()); 1571 ASSERT_TRUE(embedded_test_server()->Start());
1524 1572
1525 // Add a pinned tab. 1573 // Add a pinned tab.
1526 host_resolver()->AddRule("www.example.com", "127.0.0.1"); 1574 host_resolver()->AddRule("www.example.com", "127.0.0.1");
1527 GURL url(embedded_test_server()->GetURL("/empty.html")); 1575 GURL url(embedded_test_server()->GetURL("/empty.html"));
(...skipping 1405 matching lines...) Expand 10 before | Expand all | Expand 10 after
2933 Browser* browser = new Browser(params); 2981 Browser* browser = new Browser(params);
2934 gfx::Rect bounds = browser->window()->GetBounds(); 2982 gfx::Rect bounds = browser->window()->GetBounds();
2935 2983
2936 // Should be EXPECT_EQ, but this width is inconsistent across platforms. 2984 // Should be EXPECT_EQ, but this width is inconsistent across platforms.
2937 // See https://crbug.com/567925. 2985 // See https://crbug.com/567925.
2938 EXPECT_GE(bounds.width(), 100); 2986 EXPECT_GE(bounds.width(), 100);
2939 EXPECT_EQ(122, bounds.height()); 2987 EXPECT_EQ(122, bounds.height());
2940 browser->window()->Close(); 2988 browser->window()->Close();
2941 } 2989 }
2942 } 2990 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/search/search_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698