| 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 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 10 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 class BaseBubbleControllerTest : public CocoaTest { | 87 class BaseBubbleControllerTest : public CocoaTest { |
| 88 public: | 88 public: |
| 89 BaseBubbleControllerTest() : controller_(nil) {} | 89 BaseBubbleControllerTest() : controller_(nil) {} |
| 90 | 90 |
| 91 void SetUp() override { | 91 void SetUp() override { |
| 92 bubble_window_.reset([[InfoBubbleWindow alloc] | 92 bubble_window_.reset([[InfoBubbleWindow alloc] |
| 93 initWithContentRect:NSMakeRect(0, 0, kBubbleWindowWidth, | 93 initWithContentRect:NSMakeRect(0, 0, kBubbleWindowWidth, |
| 94 kBubbleWindowHeight) | 94 kBubbleWindowHeight) |
| 95 styleMask:NSBorderlessWindowMask | 95 styleMask:NSBorderlessWindowMask |
| 96 backing:NSBackingStoreBuffered | 96 backing:NSBackingStoreBuffered |
| 97 defer:YES]); | 97 defer:NO]); |
| 98 [bubble_window_ setAllowedAnimations:0]; | 98 [bubble_window_ setAllowedAnimations:0]; |
| 99 | 99 |
| 100 // The bubble controller will release itself when the window closes. | 100 // The bubble controller will release itself when the window closes. |
| 101 controller_ = [[BaseBubbleController alloc] | 101 controller_ = [[BaseBubbleController alloc] |
| 102 initWithWindow:bubble_window_ | 102 initWithWindow:bubble_window_ |
| 103 parentWindow:test_window() | 103 parentWindow:test_window() |
| 104 anchoredAt:NSMakePoint(kAnchorPointX, kAnchorPointY)]; | 104 anchoredAt:NSMakePoint(kAnchorPointX, kAnchorPointY)]; |
| 105 EXPECT_TRUE([controller_ bubble]); | 105 EXPECT_TRUE([controller_ bubble]); |
| 106 EXPECT_EQ(bubble_window_.get(), [controller_ window]); | 106 EXPECT_EQ(bubble_window_.get(), [controller_ window]); |
| 107 } | 107 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 EXPECT_EQ(NSMaxY(frame), kAnchorPointY); | 246 EXPECT_EQ(NSMaxY(frame), kAnchorPointY); |
| 247 } | 247 } |
| 248 | 248 |
| 249 // Tests that when a new window gets key state (and the bubble resigns) that | 249 // Tests that when a new window gets key state (and the bubble resigns) that |
| 250 // the key window changes. | 250 // the key window changes. |
| 251 TEST_F(BaseBubbleControllerTest, ResignKeyCloses) { | 251 TEST_F(BaseBubbleControllerTest, ResignKeyCloses) { |
| 252 base::scoped_nsobject<NSWindow> other_window( | 252 base::scoped_nsobject<NSWindow> other_window( |
| 253 [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 500, 500, 500) | 253 [[NSWindow alloc] initWithContentRect:NSMakeRect(500, 500, 500, 500) |
| 254 styleMask:NSTitledWindowMask | 254 styleMask:NSTitledWindowMask |
| 255 backing:NSBackingStoreBuffered | 255 backing:NSBackingStoreBuffered |
| 256 defer:YES]); | 256 defer:NO]); |
| 257 | 257 |
| 258 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); | 258 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); |
| 259 EXPECT_FALSE([other_window isVisible]); | 259 EXPECT_FALSE([other_window isVisible]); |
| 260 | 260 |
| 261 [other_window makeKeyAndOrderFront:nil]; | 261 [other_window makeKeyAndOrderFront:nil]; |
| 262 SimulateKeyStatusChange(); | 262 SimulateKeyStatusChange(); |
| 263 | 263 |
| 264 EXPECT_FALSE([bubble_window_ isVisible]); | 264 EXPECT_FALSE([bubble_window_ isVisible]); |
| 265 EXPECT_TRUE([other_window isVisible]); | 265 EXPECT_TRUE([other_window isVisible]); |
| 266 } | 266 } |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 TEST_F(BaseBubbleControllerTest, BubbleStaysOpenWithSheet) { | 357 TEST_F(BaseBubbleControllerTest, BubbleStaysOpenWithSheet) { |
| 358 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); | 358 base::scoped_nsobject<BaseBubbleController> keep_alive = ShowBubble(); |
| 359 | 359 |
| 360 // Make a dummy NSPanel for the sheet. Don't use [NSOpenPanel openPanel], | 360 // Make a dummy NSPanel for the sheet. Don't use [NSOpenPanel openPanel], |
| 361 // otherwise a stray FI_TFloatingInputWindow is created which the unit test | 361 // otherwise a stray FI_TFloatingInputWindow is created which the unit test |
| 362 // harness doesn't like. | 362 // harness doesn't like. |
| 363 base::scoped_nsobject<NSPanel> panel( | 363 base::scoped_nsobject<NSPanel> panel( |
| 364 [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 100, 50) | 364 [[NSPanel alloc] initWithContentRect:NSMakeRect(0, 0, 100, 50) |
| 365 styleMask:NSTitledWindowMask | 365 styleMask:NSTitledWindowMask |
| 366 backing:NSBackingStoreBuffered | 366 backing:NSBackingStoreBuffered |
| 367 defer:YES]); | 367 defer:NO]); |
| 368 EXPECT_FALSE([panel isReleasedWhenClosed]); // scoped_nsobject releases it. | 368 EXPECT_FALSE([panel isReleasedWhenClosed]); // scoped_nsobject releases it. |
| 369 | 369 |
| 370 // With a NSOpenPanel, we would call -[NSSavePanel beginSheetModalForWindow] | 370 // With a NSOpenPanel, we would call -[NSSavePanel beginSheetModalForWindow] |
| 371 // here. In 10.9, we would call [NSWindow beginSheet:]. For 10.6, this: | 371 // here. In 10.9, we would call [NSWindow beginSheet:]. For 10.6, this: |
| 372 [[NSApplication sharedApplication] beginSheet:panel | 372 [[NSApplication sharedApplication] beginSheet:panel |
| 373 modalForWindow:bubble_window_ | 373 modalForWindow:bubble_window_ |
| 374 modalDelegate:nil | 374 modalDelegate:nil |
| 375 didEndSelector:NULL | 375 didEndSelector:NULL |
| 376 contextInfo:NULL]; | 376 contextInfo:NULL]; |
| 377 | 377 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 388 [panel close]; | 388 [panel close]; |
| 389 | 389 |
| 390 EXPECT_FALSE([bubble_window_ attachedSheet]); | 390 EXPECT_FALSE([bubble_window_ attachedSheet]); |
| 391 EXPECT_TRUE([bubble_window_ isVisible]); | 391 EXPECT_TRUE([bubble_window_ isVisible]); |
| 392 EXPECT_FALSE([panel isVisible]); | 392 EXPECT_FALSE([panel isVisible]); |
| 393 | 393 |
| 394 // Now that the sheet is gone, a key status change should close the bubble. | 394 // Now that the sheet is gone, a key status change should close the bubble. |
| 395 SimulateKeyStatusChange(); | 395 SimulateKeyStatusChange(); |
| 396 EXPECT_FALSE([bubble_window_ isVisible]); | 396 EXPECT_FALSE([bubble_window_ isVisible]); |
| 397 } | 397 } |
| OLD | NEW |