|
4 | 4 | * You can obtain one at http://mozilla.org/MPL/2.0/. */
|
5 | 5 |
|
6 | 6 | #include "brave/browser/ui/brave_browser.h"
|
| 7 | +#include "chrome/browser/ui/browser_finder.h" |
| 8 | +#include "chrome/browser/ui/browser_tabstrip.h" |
| 9 | +#include "chrome/browser/ui/startup/launch_mode_recorder.h" |
| 10 | +#include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 11 | +#include "chrome/browser/ui/startup/startup_browser_creator_impl.h" |
7 | 12 | #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| 13 | +#include "chrome/browser/ui/views/frame/browser_view.h" |
8 | 14 | #include "chrome/test/base/in_process_browser_test.h"
|
9 | 15 | #include "chrome/test/base/ui_test_utils.h"
|
10 | 16 | #include "content/public/test/browser_test.h"
|
| 17 | +#include "content/public/test/test_navigation_observer.h" |
| 18 | +#include "content/public/test/test_utils.h" |
11 | 19 |
|
12 | 20 | using BraveBrowserBrowserTest = InProcessBrowserTest;
|
13 | 21 |
|
| 22 | +namespace { |
| 23 | +Browser* OpenNewBrowser(Profile* profile) { |
| 24 | + base::CommandLine dummy(base::CommandLine::NO_PROGRAM); |
| 25 | + StartupBrowserCreatorImpl creator(base::FilePath(), dummy, |
| 26 | + chrome::startup::IsFirstRun::kYes); |
| 27 | + creator.Launch(profile, chrome::startup::IsProcessStartup::kNo, nullptr); |
| 28 | + return chrome::FindBrowserWithProfile(profile); |
| 29 | +} |
| 30 | +} // namespace |
| 31 | + |
14 | 32 | IN_PROC_BROWSER_TEST_F(BraveBrowserBrowserTest, NTPFaviconTest) {
|
15 | 33 | ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), GURL("brave://newtab/")));
|
16 | 34 |
|
17 | 35 | auto* tab_model = browser()->tab_strip_model();
|
18 | 36 | EXPECT_FALSE(
|
19 | 37 | browser()->ShouldDisplayFavicon(tab_model->GetActiveWebContents()));
|
20 | 38 | }
|
| 39 | + |
| 40 | +IN_PROC_BROWSER_TEST_F(BraveBrowserBrowserTest, OpenNewTabWhenTabStripIsEmpty) { |
| 41 | + ASSERT_TRUE(embedded_test_server()->Start()); |
| 42 | + Browser* new_browser = OpenNewBrowser(browser()->profile()); |
| 43 | + ASSERT_TRUE(new_browser); |
| 44 | + TabStripModel* tab_strip = new_browser->tab_strip_model(); |
| 45 | + auto page_url = embedded_test_server()->GetURL("/empty.html"); |
| 46 | + ASSERT_TRUE(ui_test_utils::NavigateToURL(new_browser, page_url)); |
| 47 | + |
| 48 | + ASSERT_EQ(1, tab_strip->count()); |
| 49 | + EXPECT_EQ(page_url, |
| 50 | + tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec()); |
| 51 | + // Close the last tab. |
| 52 | + tab_strip->GetActiveWebContents()->Close(); |
| 53 | + base::RunLoop().RunUntilIdle(); |
| 54 | + ASSERT_EQ(1, tab_strip->count()); |
| 55 | + // Expecting a new tab is opened. |
| 56 | + EXPECT_EQ(new_browser->GetNewTabURL(), |
| 57 | + tab_strip->GetWebContentsAt(0)->GetURL().possibly_invalid_spec()); |
| 58 | + // Add a couple of more tabs. |
| 59 | + chrome::AddTabAt(new_browser, new_browser->GetNewTabURL(), -1, true); |
| 60 | + chrome::AddTabAt(new_browser, new_browser->GetNewTabURL(), -1, true); |
| 61 | + ASSERT_EQ(3, tab_strip->count()); |
| 62 | + EXPECT_EQ(chrome::GetTotalBrowserCount(), 2u); |
| 63 | + // Close the browser window. |
| 64 | + new_browser->window()->Close(); |
| 65 | + base::RunLoop().RunUntilIdle(); |
| 66 | + EXPECT_EQ(chrome::GetTotalBrowserCount(), 1u); |
| 67 | +} |
0 commit comments