| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/mac/scoped_nsautorelease_pool.h" |
| 6 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
| 7 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
| 11 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
| 12 #include "chrome/browser/ui/find_bar/find_bar.h" | 13 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 13 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 14 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 14 #include "chrome/browser/ui/panels/native_panel.h" | 15 #include "chrome/browser/ui/panels/native_panel.h" |
| 15 #include "chrome/browser/ui/panels/panel.h" | 16 #include "chrome/browser/ui/panels/panel.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 38 FindBarBridge::disable_animations_during_testing_ = true; | 39 FindBarBridge::disable_animations_during_testing_ = true; |
| 39 #endif | 40 #endif |
| 40 } | 41 } |
| 41 | 42 |
| 42 virtual void SetUpCommandLine(CommandLine* command_line) { | 43 virtual void SetUpCommandLine(CommandLine* command_line) { |
| 43 command_line->AppendSwitch(switches::kEnablePanels); | 44 command_line->AppendSwitch(switches::kEnablePanels); |
| 44 } | 45 } |
| 45 | 46 |
| 46 protected: | 47 protected: |
| 47 Panel* CreatePanel(const std::string& name, const gfx::Rect& bounds) { | 48 Panel* CreatePanel(const std::string& name, const gfx::Rect& bounds) { |
| 49 // Opening panels on a Mac causes NSWindowController of the Panel window |
| 50 // to be autoreleased. We need a pool drained after it's done so the test |
| 51 // can close correctly. The NSWindowController of the Panel window controls |
| 52 // lifetime of the Browser object so we want to release it as soon as |
| 53 // possible. In real Chrome, this is done by message pump. |
| 54 // On non-Mac platform, this is an empty class. |
| 55 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 56 |
| 48 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, | 57 Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
| 49 name, | 58 name, |
| 50 bounds, | 59 bounds, |
| 51 browser()->profile()); | 60 browser()->profile()); |
| 52 EXPECT_TRUE(panel_browser->is_type_panel()); | 61 EXPECT_TRUE(panel_browser->is_type_panel()); |
| 53 | 62 |
| 54 TabContentsWrapper* tab_contents = | 63 TabContentsWrapper* tab_contents = |
| 55 new TabContentsWrapper(new TestTabContents(browser()->profile(), NULL)); | 64 new TabContentsWrapper(new TestTabContents(browser()->profile(), NULL)); |
| 56 panel_browser->AddTab(tab_contents, PageTransition::LINK); | 65 panel_browser->AddTab(tab_contents, PageTransition::LINK); |
| 57 | 66 |
| 58 Panel* panel = static_cast<Panel*>(panel_browser->window()); | 67 Panel* panel = static_cast<Panel*>(panel_browser->window()); |
| 59 panel->Show(); | 68 panel->Show(); |
| 60 MessageLoopForUI::current()->RunAllPending(); | 69 MessageLoopForUI::current()->RunAllPending(); |
| 61 | 70 |
| 62 return panel; | 71 return panel; |
| 63 } | 72 } |
| 64 | 73 |
| 74 void CloseWindowAndWait(Browser* browser) { |
| 75 // Closing a browser window may involve several async tasks. Need to use |
| 76 // message pump and wait for the notification. |
| 77 size_t browser_count = BrowserList::size(); |
| 78 ui_test_utils::WindowedNotificationObserver signal( |
| 79 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 80 Source<Browser>(browser)); |
| 81 browser->CloseWindow(); |
| 82 signal.Wait(); |
| 83 // Now we have one less browser instance. |
| 84 EXPECT_EQ(browser_count - 1, BrowserList::size()); |
| 85 } |
| 86 |
| 65 // Creates a testing extension. | 87 // Creates a testing extension. |
| 66 scoped_refptr<Extension> CreateExtension(const FilePath::StringType& path) { | 88 scoped_refptr<Extension> CreateExtension(const FilePath::StringType& path) { |
| 67 #if defined(OS_WIN) | 89 #if defined(OS_WIN) |
| 68 FilePath full_path(FILE_PATH_LITERAL("c:\\")); | 90 FilePath full_path(FILE_PATH_LITERAL("c:\\")); |
| 69 #else | 91 #else |
| 70 FilePath full_path(FILE_PATH_LITERAL("/")); | 92 FilePath full_path(FILE_PATH_LITERAL("/")); |
| 71 #endif | 93 #endif |
| 72 full_path = full_path.Append(path); | 94 full_path = full_path.Append(path); |
| 73 DictionaryValue input_value; | 95 DictionaryValue input_value; |
| 74 input_value.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); | 96 input_value.SetString(extension_manifest_keys::kVersion, "1.0.0.0"); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 296 |
| 275 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); | 297 Panel* panel = CreatePanel("PanelTest", gfx::Rect()); |
| 276 EXPECT_EQ(1, panel_manager->num_panels()); | 298 EXPECT_EQ(1, panel_manager->num_panels()); |
| 277 | 299 |
| 278 gfx::Rect bounds = panel->GetBounds(); | 300 gfx::Rect bounds = panel->GetBounds(); |
| 279 EXPECT_GT(bounds.x(), 0); | 301 EXPECT_GT(bounds.x(), 0); |
| 280 EXPECT_GT(bounds.y(), 0); | 302 EXPECT_GT(bounds.y(), 0); |
| 281 EXPECT_GT(bounds.width(), 0); | 303 EXPECT_GT(bounds.width(), 0); |
| 282 EXPECT_GT(bounds.height(), 0); | 304 EXPECT_GT(bounds.height(), 0); |
| 283 | 305 |
| 284 panel->Close(); | 306 CloseWindowAndWait(panel->browser()); |
| 307 |
| 285 EXPECT_EQ(0, panel_manager->num_panels()); | 308 EXPECT_EQ(0, panel_manager->num_panels()); |
| 286 } | 309 } |
| 287 | 310 |
| 288 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { | 311 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, FindBar) { |
| 289 Panel* panel = CreatePanel("PanelTest", gfx::Rect(0, 0, 400, 400)); | 312 Panel* panel = CreatePanel("PanelTest", gfx::Rect(0, 0, 400, 400)); |
| 290 Browser* browser = panel->browser(); | 313 Browser* browser = panel->browser(); |
| 291 browser->ShowFindBar(); | 314 browser->ShowFindBar(); |
| 292 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); | 315 ASSERT_TRUE(browser->GetFindBarController()->find_bar()->IsFindBarVisible()); |
| 293 panel->Close(); | 316 panel->Close(); |
| 294 } | 317 } |
| 295 | 318 |
| 296 // TODO(jianli): Investigate and enable it for Mac. | 319 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanelOnOverflow) { |
| 297 #ifdef OS_MACOSX | |
| 298 #define MAYBE_CreatePanelOnOverflow DISABLED_CreatePanelOnOverflow | |
| 299 #else | |
| 300 #define MAYBE_CreatePanelOnOverflow CreatePanelOnOverflow | |
| 301 #endif | |
| 302 | |
| 303 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_CreatePanelOnOverflow) { | |
| 304 TestCreatePanelOnOverflow(); | 320 TestCreatePanelOnOverflow(); |
| 305 } | 321 } |
| 306 | 322 |
| 307 #if defined(TOOLKIT_GTK) || defined(OS_WIN) | 323 #if defined(TOOLKIT_GTK) || defined(OS_WIN) |
| 308 #define MAYBE_DragPanels DragPanels | 324 #define MAYBE_DragPanels DragPanels |
| 309 #else | 325 #else |
| 310 #define MAYBE_DragPanels DISABLED_DragPanels | 326 #define MAYBE_DragPanels DISABLED_DragPanels |
| 311 #endif | 327 #endif |
| 312 | 328 |
| 313 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { | 329 IN_PROC_BROWSER_TEST_F(PanelBrowserTest, MAYBE_DragPanels) { |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 EXPECT_EQ(1, tabbed_browser->tab_count()); | 517 EXPECT_EQ(1, tabbed_browser->tab_count()); |
| 502 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); | 518 ASSERT_TRUE(tabbed_browser->window()->IsDownloadShelfVisible()); |
| 503 tabbed_browser->CloseWindow(); | 519 tabbed_browser->CloseWindow(); |
| 504 #endif | 520 #endif |
| 505 | 521 |
| 506 EXPECT_EQ(1, panel_browser->tab_count()); | 522 EXPECT_EQ(1, panel_browser->tab_count()); |
| 507 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); | 523 ASSERT_FALSE(panel_browser->window()->IsDownloadShelfVisible()); |
| 508 | 524 |
| 509 panel_browser->CloseWindow(); | 525 panel_browser->CloseWindow(); |
| 510 } | 526 } |
| OLD | NEW |