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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync/sync_ui_util_mac.h"
7 #import <Cocoa/Cocoa.h>
9 #include "base/memory/scoped_nsobject.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/l10n/l10n_util_mac.h"
21 class SyncStatusUIHelperMacTest : public CocoaTest {
24 TEST_F(SyncStatusUIHelperMacTest, UpdateSyncItem) {
25 scoped_nsobject<NSMenuItem> syncMenuItem(
26 [[NSMenuItem alloc] initWithTitle:@""
27 action:@selector(commandDispatch)
29 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
31 std::string userName = "foo@example.com";
33 NSString* bookmarksSynced =
34 l10n_util::GetNSStringFWithFixup(IDS_SYNC_MENU_SYNCED_LABEL,
35 UTF8ToUTF16(userName));
36 NSString* bookmarkSyncError =
37 l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_SYNC_ERROR_LABEL);
39 l10n_util::GetNSStringFWithFixup(
40 IDS_SYNC_MENU_PRE_SYNCED_LABEL,
41 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
43 [syncMenuItem setTitle:@""];
44 [syncMenuItem setHidden:NO];
46 sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO,
47 sync_ui_util::PRE_SYNCED,
49 EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSync]);
50 EXPECT_TRUE([syncMenuItem isHidden]);
52 [syncMenuItem setTitle:@""];
53 [syncMenuItem setHidden:YES];
54 sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, YES,
55 sync_ui_util::SYNC_ERROR,
57 EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarkSyncError]);
58 EXPECT_FALSE([syncMenuItem isHidden]);
60 [syncMenuItem setTitle:@""];
61 [syncMenuItem setHidden:NO];
62 sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO,
65 EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarksSynced]);
66 EXPECT_TRUE([syncMenuItem isHidden]);
69 TEST_F(SyncStatusUIHelperMacTest, UpdateSyncItemWithSeparator) {
70 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
71 NSMenuItem* syncMenuItem =
72 [menu addItemWithTitle:@""
73 action:@selector(commandDispatch)
75 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
76 NSMenuItem* followingSeparator = [NSMenuItem separatorItem];
77 [menu addItem:followingSeparator];
79 const sync_ui_util::MessageType kStatus = sync_ui_util::PRE_SYNCED;
81 [syncMenuItem setHidden:NO];
82 [followingSeparator setHidden:NO];
83 sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO, kStatus, "");
84 EXPECT_FALSE([followingSeparator isEnabled]);
85 EXPECT_TRUE([syncMenuItem isHidden]);
86 EXPECT_TRUE([followingSeparator isHidden]);
88 [syncMenuItem setHidden:YES];
89 [followingSeparator setHidden:YES];
90 sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, YES, kStatus, "");
91 EXPECT_FALSE([followingSeparator isEnabled]);
92 EXPECT_FALSE([syncMenuItem isHidden]);
93 EXPECT_FALSE([followingSeparator isHidden]);
96 TEST_F(SyncStatusUIHelperMacTest, UpdateSyncItemWithNonSeparator) {
97 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
98 NSMenuItem* syncMenuItem =
99 [menu addItemWithTitle:@""
100 action:@selector(commandDispatch)
102 [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
103 NSMenuItem* followingNonSeparator =
104 [menu addItemWithTitle:@""
105 action:@selector(commandDispatch)
108 const sync_ui_util::MessageType kStatus = sync_ui_util::PRE_SYNCED;
110 sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO, kStatus, "");
111 EXPECT_TRUE([followingNonSeparator isEnabled]);
112 EXPECT_FALSE([followingNonSeparator isHidden]);
114 sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, YES, kStatus, "");
115 EXPECT_TRUE([followingNonSeparator isEnabled]);
116 EXPECT_FALSE([followingNonSeparator isHidden]);