| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <Carbon/Carbon.h> | 5 #include <Carbon/Carbon.h> |
| 6 #import <Cocoa/Cocoa.h> | 6 #import <Cocoa/Cocoa.h> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/debugger.h" | 9 #include "base/debug/debugger.h" |
| 10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "chrome/app/chrome_command_ids.h" // IDC_* | 13 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 14 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 15 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 16 #import "chrome/browser/ui/cocoa/run_loop_testing.h" | 16 #import "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 17 #include "chrome/browser/ui/panels/panel.h" | 17 #include "chrome/browser/ui/panels/panel.h" |
| 18 #import "chrome/browser/ui/panels/panel_cocoa.h" | 18 #import "chrome/browser/ui/panels/panel_cocoa.h" |
| 19 #include "chrome/browser/ui/panels/panel_manager.h" | 19 #include "chrome/browser/ui/panels/panel_manager.h" |
| 20 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" | 20 #import "chrome/browser/ui/panels/panel_titlebar_view_cocoa.h" |
| 21 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" | 21 #import "chrome/browser/ui/panels/panel_window_controller_cocoa.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/test/base/ui_test_utils.h" | 24 #include "content/public/test/test_utils.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "testing/gtest_mac.h" | 26 #include "testing/gtest_mac.h" |
| 27 | 27 |
| 28 class PanelAnimatedBoundsObserver : | 28 class PanelAnimatedBoundsObserver : |
| 29 public ui_test_utils::WindowedNotificationObserver { | 29 public content::WindowedNotificationObserver { |
| 30 public: | 30 public: |
| 31 PanelAnimatedBoundsObserver(Panel* panel) | 31 PanelAnimatedBoundsObserver(Panel* panel) |
| 32 : ui_test_utils::WindowedNotificationObserver( | 32 : content::WindowedNotificationObserver( |
| 33 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, | 33 chrome::NOTIFICATION_PANEL_BOUNDS_ANIMATIONS_FINISHED, |
| 34 content::Source<Panel>(panel)) { } | 34 content::Source<Panel>(panel)) { } |
| 35 virtual ~PanelAnimatedBoundsObserver() { } | 35 virtual ~PanelAnimatedBoundsObserver() { } |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 // Main test class. | 38 // Main test class. |
| 39 class PanelCocoaTest : public CocoaProfileTest { | 39 class PanelCocoaTest : public CocoaProfileTest { |
| 40 public: | 40 public: |
| 41 virtual void SetUp() { | 41 virtual void SetUp() { |
| 42 CocoaProfileTest::SetUp(); | 42 CocoaProfileTest::SetUp(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 EXPECT_EQ(NSWidth(content_frame), NSWidth(titlebar_frame)); | 87 EXPECT_EQ(NSWidth(content_frame), NSWidth(titlebar_frame)); |
| 88 EXPECT_EQ(NSHeight([[titlebar superview] bounds]), NSMaxY(titlebar_frame)); | 88 EXPECT_EQ(NSHeight([[titlebar superview] bounds]), NSMaxY(titlebar_frame)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void ClosePanelAndWait(Panel* panel) { | 91 void ClosePanelAndWait(Panel* panel) { |
| 92 EXPECT_TRUE(panel); | 92 EXPECT_TRUE(panel); |
| 93 // Closing a panel may involve several async tasks. Need to use | 93 // Closing a panel may involve several async tasks. Need to use |
| 94 // message pump and wait for the notification. | 94 // message pump and wait for the notification. |
| 95 PanelManager* manager = PanelManager::GetInstance(); | 95 PanelManager* manager = PanelManager::GetInstance(); |
| 96 int panel_count = manager->num_panels(); | 96 int panel_count = manager->num_panels(); |
| 97 ui_test_utils::WindowedNotificationObserver signal( | 97 content::WindowedNotificationObserver signal( |
| 98 chrome::NOTIFICATION_PANEL_CLOSED, | 98 chrome::NOTIFICATION_PANEL_CLOSED, |
| 99 content::Source<Panel>(panel)); | 99 content::Source<Panel>(panel)); |
| 100 panel->Close(); | 100 panel->Close(); |
| 101 signal.Wait(); | 101 signal.Wait(); |
| 102 // Now we have one less panel. | 102 // Now we have one less panel. |
| 103 EXPECT_EQ(panel_count - 1, manager->num_panels()); | 103 EXPECT_EQ(panel_count - 1, manager->num_panels()); |
| 104 } | 104 } |
| 105 | 105 |
| 106 NSMenuItem* CreateMenuItem(NSMenu* menu, int command_id) { | 106 NSMenuItem* CreateMenuItem(NSMenu* menu, int command_id) { |
| 107 NSMenuItem* item = | 107 NSMenuItem* item = |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 TEST_F(PanelCocoaTest, TitlebarViewClose) { | 276 TEST_F(PanelCocoaTest, TitlebarViewClose) { |
| 277 Panel* panel = CreateTestPanel("Test Panel"); | 277 Panel* panel = CreateTestPanel("Test Panel"); |
| 278 PanelCocoa* native_window = static_cast<PanelCocoa*>(panel->native_panel()); | 278 PanelCocoa* native_window = static_cast<PanelCocoa*>(panel->native_panel()); |
| 279 | 279 |
| 280 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView]; | 280 PanelTitlebarViewCocoa* titlebar = [native_window->controller_ titlebarView]; |
| 281 EXPECT_TRUE(titlebar); | 281 EXPECT_TRUE(titlebar); |
| 282 | 282 |
| 283 PanelManager* manager = PanelManager::GetInstance(); | 283 PanelManager* manager = PanelManager::GetInstance(); |
| 284 EXPECT_EQ(1, manager->num_panels()); | 284 EXPECT_EQ(1, manager->num_panels()); |
| 285 // Simulate clicking Close Button and wait until the Panel closes. | 285 // Simulate clicking Close Button and wait until the Panel closes. |
| 286 ui_test_utils::WindowedNotificationObserver signal( | 286 content::WindowedNotificationObserver signal( |
| 287 chrome::NOTIFICATION_PANEL_CLOSED, | 287 chrome::NOTIFICATION_PANEL_CLOSED, |
| 288 content::Source<Panel>(panel)); | 288 content::Source<Panel>(panel)); |
| 289 [titlebar simulateCloseButtonClick]; | 289 [titlebar simulateCloseButtonClick]; |
| 290 signal.Wait(); | 290 signal.Wait(); |
| 291 EXPECT_EQ(0, manager->num_panels()); | 291 EXPECT_EQ(0, manager->num_panels()); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Verify some menu items being properly enabled/disabled for panels. | 294 // Verify some menu items being properly enabled/disabled for panels. |
| 295 TEST_F(PanelCocoaTest, MenuItems) { | 295 TEST_F(PanelCocoaTest, MenuItems) { |
| 296 Panel* panel = CreateTestPanel("Test Panel"); | 296 Panel* panel = CreateTestPanel("Test Panel"); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 NSWindow* frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; | 389 NSWindow* frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; |
| 390 EXPECT_NSEQ(frontmostWindow, [native_window->controller_ window]); | 390 EXPECT_NSEQ(frontmostWindow, [native_window->controller_ window]); |
| 391 | 391 |
| 392 native_window2->ActivatePanel(); | 392 native_window2->ActivatePanel(); |
| 393 frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; | 393 frontmostWindow = [[NSApp orderedWindows] objectAtIndex:0]; |
| 394 EXPECT_NSEQ(frontmostWindow, [native_window2->controller_ window]); | 394 EXPECT_NSEQ(frontmostWindow, [native_window2->controller_ window]); |
| 395 | 395 |
| 396 ClosePanelAndWait(panel); | 396 ClosePanelAndWait(panel); |
| 397 ClosePanelAndWait(panel2); | 397 ClosePanelAndWait(panel2); |
| 398 } | 398 } |
| OLD | NEW |