| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util_mac.h" |
| 5 #include "base/scoped_nsobject.h" | 6 #include "base/scoped_nsobject.h" |
| 6 #include "base/scoped_nsautorelease_pool.h" | 7 #include "base/scoped_nsautorelease_pool.h" |
| 7 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" |
| 8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
| 10 #include "chrome/browser/cocoa/browser_test_helper.h" | 12 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 11 #include "chrome/browser/cocoa/browser_window_controller.h" | 13 #include "chrome/browser/cocoa/browser_window_controller.h" |
| 12 #include "chrome/browser/cocoa/cocoa_test_helper.h" | 14 #include "chrome/browser/cocoa/cocoa_test_helper.h" |
| 13 #include "chrome/browser/cocoa/find_bar_bridge.h" | 15 #include "chrome/browser/cocoa/find_bar_bridge.h" |
| 16 #include "chrome/browser/sync/sync_status_ui_helper.h" |
| 14 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/pref_service.h" | 18 #include "chrome/common/pref_service.h" |
| 16 #include "chrome/test/testing_browser_process.h" | 19 #include "chrome/test/testing_browser_process.h" |
| 17 #include "chrome/test/testing_profile.h" | 20 #include "chrome/test/testing_profile.h" |
| 21 #include "grit/generated_resources.h" |
| 18 | 22 |
| 19 @interface BrowserWindowController (JustForTesting) | 23 @interface BrowserWindowController (JustForTesting) |
| 20 // Already defined in BWC. | 24 // Already defined in BWC. |
| 21 - (void)saveWindowPositionToPrefs:(PrefService*)prefs; | 25 - (void)saveWindowPositionToPrefs:(PrefService*)prefs; |
| 22 - (void)layoutSubviews; | 26 - (void)layoutSubviews; |
| 23 @end | 27 @end |
| 24 | 28 |
| 25 @interface BrowserWindowController (ExposedForTesting) | 29 @interface BrowserWindowController (ExposedForTesting) |
| 26 // Implementations are below. | 30 // Implementations are below. |
| 27 - (NSView*)infoBarContainerView; | 31 - (NSView*)infoBarContainerView; |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 [subviews indexOfObject:[controller_ toolbarView]]; | 426 [subviews indexOfObject:[controller_ toolbarView]]; |
| 423 EXPECT_NE(NSNotFound, toolbar_index); | 427 EXPECT_NE(NSNotFound, toolbar_index); |
| 424 NSUInteger bookmark_index = | 428 NSUInteger bookmark_index = |
| 425 [subviews indexOfObject:[controller_ bookmarkView]]; | 429 [subviews indexOfObject:[controller_ bookmarkView]]; |
| 426 EXPECT_NE(NSNotFound, bookmark_index); | 430 EXPECT_NE(NSNotFound, bookmark_index); |
| 427 | 431 |
| 428 EXPECT_GT(findBar_index, toolbar_index); | 432 EXPECT_GT(findBar_index, toolbar_index); |
| 429 EXPECT_GT(findBar_index, bookmark_index); | 433 EXPECT_GT(findBar_index, bookmark_index); |
| 430 } | 434 } |
| 431 | 435 |
| 436 TEST_F(BrowserWindowControllerTest, TestSyncMenuItem) { |
| 437 scoped_nsobject<NSMenuItem> syncMenuItem( |
| 438 [[NSMenuItem alloc] initWithTitle:@"" |
| 439 action:@selector(commandDispatch) |
| 440 keyEquivalent:@""]); |
| 441 [syncMenuItem setTag:IDC_SYNC_BOOKMARKS]; |
| 442 |
| 443 NSString* bookmarksSynced = |
| 444 l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_BOOKMARKS_SYNCED_LABEL); |
| 445 NSString* bookmarkSyncError = |
| 446 l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_BOOKMARK_SYNC_ERROR_LABEL); |
| 447 NSString* startSync = |
| 448 l10n_util::GetNSStringWithFixup(IDS_SYNC_START_SYNC_BUTTON_LABEL); |
| 449 |
| 450 [syncMenuItem setTitle:@""]; |
| 451 [syncMenuItem setHidden:NO]; |
| 452 [controller_ updateSyncItem:syncMenuItem |
| 453 syncEnabled:NO |
| 454 status:SyncStatusUIHelper::PRE_SYNCED]; |
| 455 EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSync]); |
| 456 EXPECT_TRUE([syncMenuItem isHidden]); |
| 457 |
| 458 [syncMenuItem setTitle:@""]; |
| 459 [syncMenuItem setHidden:YES]; |
| 460 [controller_ updateSyncItem:syncMenuItem |
| 461 syncEnabled:YES |
| 462 status:SyncStatusUIHelper::SYNC_ERROR]; |
| 463 EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarkSyncError]); |
| 464 EXPECT_FALSE([syncMenuItem isHidden]); |
| 465 |
| 466 [syncMenuItem setTitle:@""]; |
| 467 [syncMenuItem setHidden:NO]; |
| 468 [controller_ updateSyncItem:syncMenuItem |
| 469 syncEnabled:NO |
| 470 status:SyncStatusUIHelper::SYNCED]; |
| 471 EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarksSynced]); |
| 472 EXPECT_TRUE([syncMenuItem isHidden]); |
| 473 } |
| 474 |
| 475 TEST_F(BrowserWindowControllerTest, TestSyncMenuItemWithSeparator) { |
| 476 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 477 NSMenuItem* syncMenuItem = |
| 478 [menu addItemWithTitle:@"" |
| 479 action:@selector(commandDispatch) |
| 480 keyEquivalent:@""]; |
| 481 [syncMenuItem setTag:IDC_SYNC_BOOKMARKS]; |
| 482 NSMenuItem* following_separator = [NSMenuItem separatorItem]; |
| 483 [menu addItem:following_separator]; |
| 484 |
| 485 const SyncStatusUIHelper::MessageType kStatus = |
| 486 SyncStatusUIHelper::PRE_SYNCED; |
| 487 |
| 488 [syncMenuItem setHidden:NO]; |
| 489 [following_separator setHidden:NO]; |
| 490 [controller_ updateSyncItem:syncMenuItem |
| 491 syncEnabled:NO |
| 492 status:kStatus]; |
| 493 EXPECT_FALSE([following_separator isEnabled]); |
| 494 EXPECT_TRUE([syncMenuItem isHidden]); |
| 495 EXPECT_TRUE([following_separator isHidden]); |
| 496 |
| 497 [syncMenuItem setHidden:YES]; |
| 498 [following_separator setHidden:YES]; |
| 499 [controller_ updateSyncItem:syncMenuItem |
| 500 syncEnabled:YES |
| 501 status:kStatus]; |
| 502 EXPECT_FALSE([following_separator isEnabled]); |
| 503 EXPECT_FALSE([syncMenuItem isHidden]); |
| 504 EXPECT_FALSE([following_separator isHidden]); |
| 505 } |
| 506 |
| 432 @interface BrowserWindowControllerFakeFullscreen : BrowserWindowController { | 507 @interface BrowserWindowControllerFakeFullscreen : BrowserWindowController { |
| 433 @private | 508 @private |
| 434 // We release the window ourselves, so we don't have to rely on the unittest | 509 // We release the window ourselves, so we don't have to rely on the unittest |
| 435 // doing it for us. | 510 // doing it for us. |
| 436 scoped_nsobject<NSWindow> fullscreenWindow_; | 511 scoped_nsobject<NSWindow> fullscreenWindow_; |
| 437 } | 512 } |
| 438 @end | 513 @end |
| 439 | 514 |
| 440 class BrowserWindowFullScreenControllerTest : public CocoaTest { | 515 class BrowserWindowFullScreenControllerTest : public CocoaTest { |
| 441 public: | 516 public: |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 fullscreenWindow_.reset( | 579 fullscreenWindow_.reset( |
| 505 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) | 580 [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,400,400) |
| 506 styleMask:NSBorderlessWindowMask | 581 styleMask:NSBorderlessWindowMask |
| 507 backing:NSBackingStoreBuffered | 582 backing:NSBackingStoreBuffered |
| 508 defer:NO]); | 583 defer:NO]); |
| 509 return fullscreenWindow_.get(); | 584 return fullscreenWindow_.get(); |
| 510 } | 585 } |
| 511 @end | 586 @end |
| 512 | 587 |
| 513 /* TODO(???): test other methods of BrowserWindowController */ | 588 /* TODO(???): test other methods of BrowserWindowController */ |
| OLD | NEW |