Chromium Code Reviews| 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 wan to release it as soon as | |
|
jennb
2011/08/19 21:46:12
typo: wan
Dmitry Titov
2011/08/22 18:34:56
Done.
| |
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 chrome::NOTIFICATION_BROWSER_CLOSED, | 165 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 144 Source<Browser>(panel5->browser())); | 166 Source<Browser>(panel5->browser())); |
| 145 Panel* panel6 = CreatePanel( | 167 Panel* panel6 = CreatePanel( |
| 146 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), | 168 web_app::GenerateApplicationNameFromExtensionId(extension3->id()), |
| 147 gfx::Rect(0, 0, 500, 200)); | 169 gfx::Rect(0, 0, 500, 200)); |
| 148 signal3.Wait(); | 170 signal3.Wait(); |
| 149 signal4.Wait(); | 171 signal4.Wait(); |
| 150 ASSERT_EQ(2, panel_manager->num_panels()); | 172 ASSERT_EQ(2, panel_manager->num_panels()); |
| 151 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); | 173 EXPECT_LT(panel6->GetBounds().right(), panel1->GetBounds().x()); |
| 152 | 174 |
| 153 panel1->Close(); | 175 CloseWindowAndWait(panel1->browser()); |
|
jennb
2011/08/19 21:46:12
Test doesn't care when close actually happens so n
Dmitry Titov
2011/08/22 18:34:56
Done. Put panel->Close() back.
| |
| 154 panel6->Close(); | 176 CloseWindowAndWait(panel6->browser()); |
| 155 } | 177 } |
| 156 | 178 |
| 157 struct DragTestData { | 179 struct DragTestData { |
| 158 DragTestData(int drag_delta_x, | 180 DragTestData(int drag_delta_x, |
| 159 int drag_delta_y, | 181 int drag_delta_y, |
| 160 bool is_big_delta, | 182 bool is_big_delta, |
| 161 bool should_cancel_drag) | 183 bool should_cancel_drag) |
| 162 : drag_delta_x(drag_delta_x), drag_delta_y(drag_delta_y), | 184 : drag_delta_x(drag_delta_x), drag_delta_y(drag_delta_y), |
| 163 is_big_delta(is_big_delta), should_cancel_drag(should_cancel_drag) {} | 185 is_big_delta(is_big_delta), should_cancel_drag(should_cancel_drag) {} |
| 164 int drag_delta_x; | 186 int drag_delta_x; |
| (...skipping 109 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()); |
|
jennb
2011/08/19 21:46:12
Wait not needed if we remove panel from panel mana
Dmitry Titov
2011/08/22 18:34:56
See comment at the top.
| |
| 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(OS_MACOSX) || defined(OS_CHROMEOS) || defined(TOOLKIT_VIEWS) | 323 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) || defined(TOOLKIT_VIEWS) |
| 308 #define MAYBE_DragPanels DISABLED_DragPanels | 324 #define MAYBE_DragPanels DISABLED_DragPanels |
| 309 #else | 325 #else |
| 310 #define MAYBE_DragPanels DragPanels | 326 #define MAYBE_DragPanels 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 |