| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/browser_list.h" | 5 #include "chrome/browser/browser_list.h" | 
| 6 #include "chrome/browser/browser_window.h" | 6 #include "chrome/browser/browser_window.h" | 
| 7 #include "chrome/browser/profile.h" | 7 #include "chrome/browser/profile.h" | 
| 8 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" | 
| 9 #include "chrome/browser/tab_contents/tab_contents_view.h" | 9 #include "chrome/browser/tab_contents/tab_contents_view.h" | 
|  | 10 #include "chrome/browser/tab_contents_wrapper.h" | 
| 10 #include "chrome/browser/tabs/tab_strip_model.h" | 11 #include "chrome/browser/tabs/tab_strip_model.h" | 
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" | 
| 12 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" | 
| 13 #include "chrome/test/in_process_browser_test.h" | 14 #include "chrome/test/in_process_browser_test.h" | 
| 14 #include "chrome/test/ui_test_utils.h" | 15 #include "chrome/test/ui_test_utils.h" | 
| 15 #include "ipc/ipc_message.h" | 16 #include "ipc/ipc_message.h" | 
| 16 | 17 | 
| 17 namespace { | 18 namespace { | 
| 18 | 19 | 
| 19 class BrowserNavigatorTest : public InProcessBrowserTest { | 20 class BrowserNavigatorTest : public InProcessBrowserTest { | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 31     params.show_window = true; | 32     params.show_window = true; | 
| 32     return params; | 33     return params; | 
| 33   } | 34   } | 
| 34 | 35 | 
| 35   Browser* CreateEmptyBrowserForType(Browser::Type type, Profile* profile) { | 36   Browser* CreateEmptyBrowserForType(Browser::Type type, Profile* profile) { | 
| 36     Browser* browser = Browser::CreateForType(type, profile); | 37     Browser* browser = Browser::CreateForType(type, profile); | 
| 37     browser->AddBlankTab(true); | 38     browser->AddBlankTab(true); | 
| 38     return browser; | 39     return browser; | 
| 39   } | 40   } | 
| 40 | 41 | 
| 41   TabContents* CreateTabContents() { | 42   TabContentsWrapper* CreateTabContents() { | 
| 42     return new TabContents(browser()->profile(), | 43     return Browser::TabContentsFactory( | 
| 43                            NULL, | 44         browser()->profile(), | 
| 44                            MSG_ROUTING_NONE, | 45         NULL, | 
| 45                            browser()->GetSelectedTabContents(), | 46         MSG_ROUTING_NONE, | 
| 46                            NULL); | 47         browser()->GetSelectedTabContents(), | 
|  | 48         NULL); | 
| 47   } | 49   } | 
| 48 | 50 | 
| 49   void RunSuppressTest(WindowOpenDisposition disposition) { | 51   void RunSuppressTest(WindowOpenDisposition disposition) { | 
| 50     GURL old_url = browser()->GetSelectedTabContents()->GetURL(); | 52     GURL old_url = browser()->GetSelectedTabContents()->GetURL(); | 
| 51     browser::NavigateParams p(MakeNavigateParams()); | 53     browser::NavigateParams p(MakeNavigateParams()); | 
| 52     p.disposition = disposition; | 54     p.disposition = disposition; | 
| 53     browser::Navigate(&p); | 55     browser::Navigate(&p); | 
| 54 | 56 | 
| 55     // Nothing should have happened as a result of Navigate(); | 57     // Nothing should have happened as a result of Navigate(); | 
| 56     EXPECT_EQ(1, browser()->tab_count()); | 58     EXPECT_EQ(1, browser()->tab_count()); | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 117 | 119 | 
| 118 // This test verifies that when a navigation results in a foreground tab, the | 120 // This test verifies that when a navigation results in a foreground tab, the | 
| 119 // tab count of the Browser increases and the selected tab shifts to the new | 121 // tab count of the Browser increases and the selected tab shifts to the new | 
| 120 // foreground tab. | 122 // foreground tab. | 
| 121 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) { | 123 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewForegroundTab) { | 
| 122   TabContents* old_contents = browser()->GetSelectedTabContents(); | 124   TabContents* old_contents = browser()->GetSelectedTabContents(); | 
| 123   browser::NavigateParams p(MakeNavigateParams()); | 125   browser::NavigateParams p(MakeNavigateParams()); | 
| 124   p.disposition = NEW_FOREGROUND_TAB; | 126   p.disposition = NEW_FOREGROUND_TAB; | 
| 125   browser::Navigate(&p); | 127   browser::Navigate(&p); | 
| 126   EXPECT_NE(old_contents, browser()->GetSelectedTabContents()); | 128   EXPECT_NE(old_contents, browser()->GetSelectedTabContents()); | 
| 127   EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); | 129   EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); | 
| 128   EXPECT_EQ(2, browser()->tab_count()); | 130   EXPECT_EQ(2, browser()->tab_count()); | 
| 129 } | 131 } | 
| 130 | 132 | 
| 131 // This test verifies that when a navigation results in a background tab, the | 133 // This test verifies that when a navigation results in a background tab, the | 
| 132 // tab count of the Browser increases but the selected tab remains the same. | 134 // tab count of the Browser increases but the selected tab remains the same. | 
| 133 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) { | 135 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Disposition_NewBackgroundTab) { | 
| 134   TabContents* old_contents = browser()->GetSelectedTabContents(); | 136   TabContents* old_contents = browser()->GetSelectedTabContents(); | 
| 135   browser::NavigateParams p(MakeNavigateParams()); | 137   browser::NavigateParams p(MakeNavigateParams()); | 
| 136   p.disposition = NEW_BACKGROUND_TAB; | 138   p.disposition = NEW_BACKGROUND_TAB; | 
| 137   browser::Navigate(&p); | 139   browser::Navigate(&p); | 
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 333 // This tests adding a foreground tab with a predefined TabContents. | 335 // This tests adding a foreground tab with a predefined TabContents. | 
| 334 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) { | 336 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_ForegroundTab) { | 
| 335   browser::NavigateParams p(MakeNavigateParams()); | 337   browser::NavigateParams p(MakeNavigateParams()); | 
| 336   p.disposition = NEW_FOREGROUND_TAB; | 338   p.disposition = NEW_FOREGROUND_TAB; | 
| 337   p.target_contents = CreateTabContents(); | 339   p.target_contents = CreateTabContents(); | 
| 338   browser::Navigate(&p); | 340   browser::Navigate(&p); | 
| 339 | 341 | 
| 340   // Navigate() should have opened the contents in a new foreground in the | 342   // Navigate() should have opened the contents in a new foreground in the | 
| 341   // current Browser. | 343   // current Browser. | 
| 342   EXPECT_EQ(browser(), p.browser); | 344   EXPECT_EQ(browser(), p.browser); | 
| 343   EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); | 345   EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); | 
| 344 | 346 | 
| 345   // We should have one window, with two tabs. | 347   // We should have one window, with two tabs. | 
| 346   EXPECT_EQ(1u, BrowserList::size()); | 348   EXPECT_EQ(1u, BrowserList::size()); | 
| 347   EXPECT_EQ(2, browser()->tab_count()); | 349   EXPECT_EQ(2, browser()->tab_count()); | 
| 348 } | 350 } | 
| 349 | 351 | 
| 350 #if defined(OS_WIN) | 352 #if defined(OS_WIN) | 
| 351 // This tests adding a popup with a predefined TabContents. | 353 // This tests adding a popup with a predefined TabContents. | 
| 352 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_Popup) { | 354 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, TargetContents_Popup) { | 
| 353   browser::NavigateParams p(MakeNavigateParams()); | 355   browser::NavigateParams p(MakeNavigateParams()); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 368   // p.window_bounds.origin(), but its size will not. We need to match | 370   // p.window_bounds.origin(), but its size will not. We need to match | 
| 369   // the size against the selected tab's view's container size. | 371   // the size against the selected tab's view's container size. | 
| 370   // Only Windows positions the window according to |p.window_bounds.origin()| - | 372   // Only Windows positions the window according to |p.window_bounds.origin()| - | 
| 371   // on Mac the window is offset from the opener and on Linux it always opens | 373   // on Mac the window is offset from the opener and on Linux it always opens | 
| 372   // at 0,0. | 374   // at 0,0. | 
| 373   EXPECT_EQ(p.window_bounds.origin(), | 375   EXPECT_EQ(p.window_bounds.origin(), | 
| 374             p.browser->window()->GetRestoredBounds().origin()); | 376             p.browser->window()->GetRestoredBounds().origin()); | 
| 375   // All platforms should respect size however provided width > 400 (Mac has a | 377   // All platforms should respect size however provided width > 400 (Mac has a | 
| 376   // minimum window width of 400). | 378   // minimum window width of 400). | 
| 377   EXPECT_EQ(p.window_bounds.size(), | 379   EXPECT_EQ(p.window_bounds.size(), | 
| 378             p.target_contents->view()->GetContainerSize()); | 380             p.target_contents->tab_contents()->view()->GetContainerSize()); | 
| 379 | 381 | 
| 380   // We should have two windows, the new popup and the browser() provided by the | 382   // We should have two windows, the new popup and the browser() provided by the | 
| 381   // framework. | 383   // framework. | 
| 382   EXPECT_EQ(2u, BrowserList::size()); | 384   EXPECT_EQ(2u, BrowserList::size()); | 
| 383   EXPECT_EQ(1, browser()->tab_count()); | 385   EXPECT_EQ(1, browser()->tab_count()); | 
| 384   EXPECT_EQ(1, p.browser->tab_count()); | 386   EXPECT_EQ(1, p.browser->tab_count()); | 
| 385 } | 387 } | 
| 386 #endif | 388 #endif | 
| 387 | 389 | 
| 388 // This tests adding a tab at a specific index. | 390 // This tests adding a tab at a specific index. | 
| 389 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) { | 391 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, Tabstrip_InsertAtIndex) { | 
| 390   // This is not meant to be a comprehensive test of whether or not the tab | 392   // This is not meant to be a comprehensive test of whether or not the tab | 
| 391   // implementation of the browser observes the insertion index. That is | 393   // implementation of the browser observes the insertion index. That is | 
| 392   // covered by the unit tests for TabStripModel. This merely verifies that | 394   // covered by the unit tests for TabStripModel. This merely verifies that | 
| 393   // insertion index preference is reflected in common cases. | 395   // insertion index preference is reflected in common cases. | 
| 394   browser::NavigateParams p(MakeNavigateParams()); | 396   browser::NavigateParams p(MakeNavigateParams()); | 
| 395   p.disposition = NEW_FOREGROUND_TAB; | 397   p.disposition = NEW_FOREGROUND_TAB; | 
| 396   p.tabstrip_index = 0; | 398   p.tabstrip_index = 0; | 
| 397   p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX; | 399   p.tabstrip_add_types = TabStripModel::ADD_FORCE_INDEX; | 
| 398   browser::Navigate(&p); | 400   browser::Navigate(&p); | 
| 399 | 401 | 
| 400   // Navigate() should have inserted a new tab at slot 0 in the tabstrip. | 402   // Navigate() should have inserted a new tab at slot 0 in the tabstrip. | 
| 401   EXPECT_EQ(browser(), p.browser); | 403   EXPECT_EQ(browser(), p.browser); | 
| 402   EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents( | 404   EXPECT_EQ(0, browser()->tabstrip_model()->GetIndexOfTabContents( | 
| 403       static_cast<const TabContents*>(p.target_contents))); | 405       static_cast<const TabContentsWrapper*>(p.target_contents))); | 
| 404 | 406 | 
| 405   // We should have one window - the browser() provided by the framework. | 407   // We should have one window - the browser() provided by the framework. | 
| 406   EXPECT_EQ(1u, BrowserList::size()); | 408   EXPECT_EQ(1u, BrowserList::size()); | 
| 407   EXPECT_EQ(2, browser()->tab_count()); | 409   EXPECT_EQ(2, browser()->tab_count()); | 
| 408 } | 410 } | 
| 409 | 411 | 
| 410 // This test verifies that constructing params with a NULL browser has | 412 // This test verifies that constructing params with a NULL browser has | 
| 411 // the same result as navigating to a new foreground tab in the (only) | 413 // the same result as navigating to a new foreground tab in the (only) | 
| 412 // active browser. Tests are the same as for Disposition_NewForegroundTab. | 414 // active browser. Tests are the same as for Disposition_NewForegroundTab. | 
| 413 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) { | 415 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewForegroundTab) { | 
| 414   TabContents* old_contents = browser()->GetSelectedTabContents(); | 416   TabContents* old_contents = browser()->GetSelectedTabContents(); | 
| 415   // Navigate with a NULL browser. | 417   // Navigate with a NULL browser. | 
| 416   browser::NavigateParams p(MakeNavigateParams(NULL)); | 418   browser::NavigateParams p(MakeNavigateParams(NULL)); | 
| 417   p.disposition = NEW_FOREGROUND_TAB; | 419   p.disposition = NEW_FOREGROUND_TAB; | 
| 418   p.profile = browser()->profile(); | 420   p.profile = browser()->profile(); | 
| 419   browser::Navigate(&p); | 421   browser::Navigate(&p); | 
| 420 | 422 | 
| 421   // Navigate() should have found browser() and create a new tab. | 423   // Navigate() should have found browser() and create a new tab. | 
| 422   EXPECT_EQ(browser(), p.browser); | 424   EXPECT_EQ(browser(), p.browser); | 
| 423   EXPECT_NE(old_contents, browser()->GetSelectedTabContents()); | 425   EXPECT_NE(old_contents, browser()->GetSelectedTabContents()); | 
| 424   EXPECT_EQ(browser()->GetSelectedTabContents(), p.target_contents); | 426   EXPECT_EQ(browser()->GetSelectedTabContentsWrapper(), p.target_contents); | 
| 425   EXPECT_EQ(2, browser()->tab_count()); | 427   EXPECT_EQ(2, browser()->tab_count()); | 
| 426 } | 428 } | 
| 427 | 429 | 
| 428 // This test verifies that constructing params with a NULL browser and | 430 // This test verifies that constructing params with a NULL browser and | 
| 429 // a specific profile matches the specified profile. | 431 // a specific profile matches the specified profile. | 
| 430 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) { | 432 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_MatchProfile) { | 
| 431   // Create a new browser with using the incognito profile. | 433   // Create a new browser with using the incognito profile. | 
| 432   Browser* incognito = | 434   Browser* incognito = | 
| 433       Browser::Create(browser()->profile()->GetOffTheRecordProfile()); | 435       Browser::Create(browser()->profile()->GetOffTheRecordProfile()); | 
| 434 | 436 | 
| 435   // Navigate with a NULL browser and the incognito profile. | 437   // Navigate with a NULL browser and the incognito profile. | 
| 436   browser::NavigateParams p(MakeNavigateParams(NULL)); | 438   browser::NavigateParams p(MakeNavigateParams(NULL)); | 
| 437   p.disposition = NEW_FOREGROUND_TAB; | 439   p.disposition = NEW_FOREGROUND_TAB; | 
| 438   p.profile = incognito->profile(); | 440   p.profile = incognito->profile(); | 
| 439   browser::Navigate(&p); | 441   browser::Navigate(&p); | 
| 440 | 442 | 
| 441   // Navigate() should have found incognito, not browser(). | 443   // Navigate() should have found incognito, not browser(). | 
| 442   EXPECT_EQ(incognito, p.browser); | 444   EXPECT_EQ(incognito, p.browser); | 
| 443   EXPECT_EQ(incognito->GetSelectedTabContents(), p.target_contents); | 445   EXPECT_EQ(incognito->GetSelectedTabContentsWrapper(), p.target_contents); | 
| 444   EXPECT_EQ(1, incognito->tab_count()); | 446   EXPECT_EQ(1, incognito->tab_count()); | 
| 445 } | 447 } | 
| 446 | 448 | 
| 447 // This test verifies that constructing params with a NULL browser and | 449 // This test verifies that constructing params with a NULL browser and | 
| 448 // disposition = NEW_WINDOW always opens exactly one new window. | 450 // disposition = NEW_WINDOW always opens exactly one new window. | 
| 449 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) { | 451 IN_PROC_BROWSER_TEST_F(BrowserNavigatorTest, NullBrowser_NewWindow) { | 
| 450   browser::NavigateParams p(MakeNavigateParams(NULL)); | 452   browser::NavigateParams p(MakeNavigateParams(NULL)); | 
| 451   p.disposition = NEW_WINDOW; | 453   p.disposition = NEW_WINDOW; | 
| 452   p.profile = browser()->profile(); | 454   p.profile = browser()->profile(); | 
| 453   browser::Navigate(&p); | 455   browser::Navigate(&p); | 
| 454 | 456 | 
| 455   // Navigate() should have created a new browser. | 457   // Navigate() should have created a new browser. | 
| 456   EXPECT_NE(browser(), p.browser); | 458   EXPECT_NE(browser(), p.browser); | 
| 457   EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type()); | 459   EXPECT_EQ(Browser::TYPE_NORMAL, p.browser->type()); | 
| 458 | 460 | 
| 459   // We should now have two windows, the browser() provided by the framework and | 461   // We should now have two windows, the browser() provided by the framework and | 
| 460   // the new normal window. | 462   // the new normal window. | 
| 461   EXPECT_EQ(2u, BrowserList::size()); | 463   EXPECT_EQ(2u, BrowserList::size()); | 
| 462   EXPECT_EQ(1, browser()->tab_count()); | 464   EXPECT_EQ(1, browser()->tab_count()); | 
| 463   EXPECT_EQ(1, p.browser->tab_count()); | 465   EXPECT_EQ(1, p.browser->tab_count()); | 
| 464 } | 466 } | 
| 465 | 467 | 
| 466 | 468 | 
| 467 }  // namespace | 469 }  // namespace | 
| OLD | NEW | 
|---|