1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/test/base/in_process_browser_test.h"
7 #include "base/mac/scoped_nsautorelease_pool.h"
8 #include "chrome/browser/devtools/devtools_window.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "content/public/test/test_navigation_observer.h"
16 void InProcessBrowserTest::OpenDevToolsWindow(
17 content::WebContents
* web_contents
) {
18 // Opening a Devtools Window can cause AppKit to throw objects into the
19 // autorelease pool. Flush the pool when this function returns.
20 base::mac::ScopedNSAutoreleasePool pool
;
22 ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents
));
23 DevToolsWindow::OpenDevToolsWindow(web_contents
);
24 ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents
));
27 Browser
* InProcessBrowserTest::OpenURLOffTheRecord(Profile
* profile
,
29 // Opening an incognito window can cause AppKit to throw objects into the
30 // autorelease pool. Flush the pool when this function returns.
31 base::mac::ScopedNSAutoreleasePool pool
;
33 chrome::HostDesktopType active_desktop
= chrome::GetActiveDesktop();
34 chrome::OpenURLOffTheRecord(profile
, url
, active_desktop
);
35 Browser
* browser
= chrome::FindTabbedBrowser(
36 profile
->GetOffTheRecordProfile(), false, active_desktop
);
37 content::TestNavigationObserver
observer(
38 browser
->tab_strip_model()->GetActiveWebContents());
43 // Creates a browser with a single tab (about:blank), waits for the tab to
44 // finish loading and shows the browser.
45 Browser
* InProcessBrowserTest::CreateBrowser(Profile
* profile
) {
46 // Making a browser window can cause AppKit to throw objects into the
47 // autorelease pool. Flush the pool when this function returns.
48 base::mac::ScopedNSAutoreleasePool pool
;
50 Browser
* browser
= new Browser(
51 Browser::CreateParams(profile
, chrome::GetActiveDesktop()));
52 AddBlankTabAndShow(browser
);
56 Browser
* InProcessBrowserTest::CreateIncognitoBrowser() {
57 // Making a browser window can cause AppKit to throw objects into the
58 // autorelease pool. Flush the pool when this function returns.
59 base::mac::ScopedNSAutoreleasePool pool
;
61 // Create a new browser with using the incognito profile.
62 Browser
* incognito
= new Browser(
63 Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(),
64 chrome::GetActiveDesktop()));
65 AddBlankTabAndShow(incognito
);
69 Browser
* InProcessBrowserTest::CreateBrowserForPopup(Profile
* profile
) {
70 // Making a browser window can cause AppKit to throw objects into the
71 // autorelease pool. Flush the pool when this function returns.
72 base::mac::ScopedNSAutoreleasePool pool
;
75 new Browser(Browser::CreateParams(Browser::TYPE_POPUP
, profile
,
76 chrome::GetActiveDesktop()));
77 AddBlankTabAndShow(browser
);
81 Browser
* InProcessBrowserTest::CreateBrowserForApp(
82 const std::string
& app_name
,
84 // Making a browser window can cause AppKit to throw objects into the
85 // autorelease pool. Flush the pool when this function returns.
86 base::mac::ScopedNSAutoreleasePool pool
;
88 Browser
* browser
= new Browser(
89 Browser::CreateParams::CreateForApp(
90 app_name
, false /* trusted_source */, gfx::Rect(), profile
,
91 chrome::GetActiveDesktop()));
92 AddBlankTabAndShow(browser
);