| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 #include "chrome/common/url_constants.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "chrome/test/in_process_browser_test.h" | |
| 8 #include "net/base/mock_host_resolver.h" | |
| 9 | 7 |
| 10 class BrowserTest : public InProcessBrowserTest { | 8 namespace { |
| 11 public: | |
| 12 BrowserTest() { | |
| 13 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); | |
| 14 // Avoid making external DNS lookups. In this test we don't need this | |
| 15 // to succeed. | |
| 16 host_resolver_proc_->AddSimulatedFailure("*.google.com"); | |
| 17 scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); | |
| 18 } | |
| 19 | 9 |
| 20 private: | 10 const struct NavigationScenario { |
| 21 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; | 11 bool pinned; |
| 22 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; | 12 const char* url; |
| 13 const char* referrer; |
| 14 PageTransition::Type transition; |
| 15 WindowOpenDisposition original_disposition; |
| 16 WindowOpenDisposition result_disposition; |
| 17 } kNavigationScenarios[] = { |
| 18 // Disposition changes to new foreground. |
| 19 { true, |
| 20 "http://www.example.com", |
| 21 "http://www.google.com", |
| 22 PageTransition::LINK, |
| 23 CURRENT_TAB, |
| 24 NEW_FOREGROUND_TAB }, |
| 25 // Also works with AUTO_BOOKMARK. |
| 26 { true, |
| 27 "http://www.example.com", |
| 28 "http://www.google.com", |
| 29 PageTransition::AUTO_BOOKMARK, |
| 30 CURRENT_TAB, |
| 31 NEW_FOREGROUND_TAB }, |
| 32 // Also happens if the schemes differ. |
| 33 { true, |
| 34 "ftp://www.example.com", |
| 35 "http://www.example.com", |
| 36 PageTransition::LINK, |
| 37 CURRENT_TAB, |
| 38 NEW_FOREGROUND_TAB }, |
| 39 // Don't choke on an empty referrer. |
| 40 { true, |
| 41 "ftp://www.example.com", |
| 42 "", |
| 43 PageTransition::LINK, |
| 44 CURRENT_TAB, |
| 45 NEW_FOREGROUND_TAB }, |
| 46 // Unpinned tab - no change. |
| 47 { false, |
| 48 "http://www.example.com", |
| 49 "http://www.google.com", |
| 50 PageTransition::LINK, |
| 51 CURRENT_TAB, |
| 52 CURRENT_TAB }, |
| 53 // Original disposition is not CURRENT_TAB - no change. |
| 54 { true, |
| 55 "http://www.example.com", |
| 56 "http://www.google.com", |
| 57 PageTransition::LINK, |
| 58 NEW_BACKGROUND_TAB, |
| 59 NEW_BACKGROUND_TAB }, |
| 60 // Other PageTransition type - no change. |
| 61 { true, |
| 62 "http://www.example.com", |
| 63 "http://www.google.com", |
| 64 PageTransition::TYPED, |
| 65 CURRENT_TAB, |
| 66 CURRENT_TAB }, |
| 67 // Same domain and scheme - no change. |
| 68 { true, |
| 69 "http://www.google.com/reader", |
| 70 "http://www.google.com", |
| 71 PageTransition::LINK, |
| 72 CURRENT_TAB, |
| 73 CURRENT_TAB }, |
| 74 // Switching between http and https - no change. |
| 75 { true, |
| 76 "https://www.example.com", |
| 77 "http://www.example.com", |
| 78 PageTransition::LINK, |
| 79 CURRENT_TAB, |
| 80 CURRENT_TAB }, |
| 81 // Switching between https and http - no change. |
| 82 { true, |
| 83 "http://www.example.com", |
| 84 "https://www.example.com", |
| 85 PageTransition::LINK, |
| 86 CURRENT_TAB, |
| 87 CURRENT_TAB }, |
| 23 }; | 88 }; |
| 24 | 89 |
| 25 /* | 90 } // namespace |
| 26 // This tests that windows without tabstrips can't have new tabs opened in | |
| 27 // them. | |
| 28 IN_PROC_BROWSER_TEST_F(BrowserTest, NoTabsInPopups) { | |
| 29 Browser::RegisterAppPrefs(L"Test"); | |
| 30 | 91 |
| 31 // We start with a normal browser with one tab. | 92 TEST(BrowserTest, PinnedTabDisposition) { |
| 32 EXPECT_EQ(1, browser()->tab_count()); | 93 for (size_t i = 0; i < arraysize(kNavigationScenarios); ++i) { |
| 33 | 94 EXPECT_EQ(kNavigationScenarios[i].result_disposition, |
| 34 // Open a popup browser with a single blank foreground tab. | 95 Browser::AdjustWindowOpenDispositionForTab( |
| 35 Browser* popup_browser = browser()->CreateForPopup(browser()->profile()); | 96 kNavigationScenarios[i].pinned, |
| 36 popup_browser->AddBlankTab(true); | 97 GURL(kNavigationScenarios[i].url), |
| 37 EXPECT_EQ(1, popup_browser->tab_count()); | 98 GURL(kNavigationScenarios[i].referrer), |
| 38 | 99 kNavigationScenarios[i].transition, |
| 39 // Now try opening another tab in the popup browser. | 100 kNavigationScenarios[i].original_disposition)) << i; |
| 40 popup_browser->AddTabWithURL( | 101 } |
| 41 GURL(chrome::kAboutBlankURL), GURL(), PageTransition::TYPED, -1, | |
| 42 Browser::ADD_SELECTED, NULL, std::string()); | |
| 43 | |
| 44 // The popup should still only have one tab. | |
| 45 EXPECT_EQ(1, popup_browser->tab_count()); | |
| 46 | |
| 47 // The normal browser should now have two. | |
| 48 EXPECT_EQ(2, browser()->tab_count()); | |
| 49 | |
| 50 // Open an app frame browser with a single blank foreground tab. | |
| 51 Browser* app_browser = | |
| 52 browser()->CreateForApp(L"Test", browser()->profile(), false); | |
| 53 app_browser->AddBlankTab(true); | |
| 54 EXPECT_EQ(1, app_browser->tab_count()); | |
| 55 | |
| 56 // Now try opening another tab in the app browser. | |
| 57 app_browser->AddTabWithURL( | |
| 58 GURL(chrome::kAboutBlankURL), GURL(), PageTransition::TYPED, -1, | |
| 59 Browser::ADD_SELECTED, NULL, std::string()); | |
| 60 | |
| 61 // The popup should still only have one tab. | |
| 62 EXPECT_EQ(1, app_browser->tab_count()); | |
| 63 | |
| 64 // The normal browser should now have three. | |
| 65 EXPECT_EQ(3, browser()->tab_count()); | |
| 66 | |
| 67 // Open an app frame popup browser with a single blank foreground tab. | |
| 68 Browser* app_popup_browser = | |
| 69 browser()->CreateForApp(L"Test", browser()->profile(), false); | |
| 70 app_popup_browser->AddBlankTab(true); | |
| 71 EXPECT_EQ(1, app_popup_browser->tab_count()); | |
| 72 | |
| 73 // Now try opening another tab in the app popup browser. | |
| 74 app_popup_browser->AddTabWithURL( | |
| 75 GURL(chrome::kAboutBlankURL), GURL(), PageTransition::TYPED, -1, | |
| 76 Browser::ADD_SELECTED, NULL, std::string()); | |
| 77 | |
| 78 // The popup should still only have one tab. | |
| 79 EXPECT_EQ(1, app_popup_browser->tab_count()); | |
| 80 | |
| 81 // The normal browser should now have four. | |
| 82 EXPECT_EQ(4, browser()->tab_count()); | |
| 83 | |
| 84 // Close the additional browsers. | |
| 85 popup_browser->CloseAllTabs(); | |
| 86 app_browser->CloseAllTabs(); | |
| 87 app_popup_browser->CloseAllTabs(); | |
| 88 } | 102 } |
| 89 */ | |
| OLD | NEW |