summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sync
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-18 12:35:25 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-18 12:35:25 +0000
commit6bf511968527b0d00c3f7bbe57300894981fae6d (patch)
treec92777efc6834440124140ac10521503e50cc6ed /chrome/browser/sync
parentd661f0522c34389d2a330d4b4ea12366127892fc (diff)
downloadchromium_src-6bf511968527b0d00c3f7bbe57300894981fae6d.zip
chromium_src-6bf511968527b0d00c3f7bbe57300894981fae6d.tar.gz
chromium_src-6bf511968527b0d00c3f7bbe57300894981fae6d.tar.bz2
Refactor mac signin menu item code to use SigninGlobalError.
Code to create the signin menu item has been moved out of browser/sync and into ui/cocoa so it can still be called even if sync is disabled. Also re-enabled test that was disabled due to incorrect freeing of Browser object. BUG=166148 TBR=sky Review URL: https://chromiumcodereview.appspot.com/11971038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177654 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync')
-rw-r--r--chrome/browser/sync/sync_ui_util_mac.h31
-rw-r--r--chrome/browser/sync/sync_ui_util_mac.mm88
-rw-r--r--chrome/browser/sync/sync_ui_util_mac_unittest.mm119
3 files changed, 0 insertions, 238 deletions
diff --git a/chrome/browser/sync/sync_ui_util_mac.h b/chrome/browser/sync/sync_ui_util_mac.h
deleted file mode 100644
index 09f63a1..0000000
--- a/chrome/browser/sync/sync_ui_util_mac.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_BROWSER_SYNC_SYNC_UI_UTIL_MAC_H_
-#define CHROME_BROWSER_SYNC_SYNC_UI_UTIL_MAC_H_
-
-#include <string>
-
-#include "chrome/browser/sync/sync_ui_util.h"
-
-#import <Cocoa/Cocoa.h>
-
-class Profile;
-
-namespace sync_ui_util {
-
-// Updates a bookmark sync UI item (expected to be a menu item). This is
-// called every time a menu containing a sync UI item is displayed.
-void UpdateSyncItem(id syncItem, BOOL syncEnabled, Profile* profile);
-
-// This function (used by UpdateSyncItem) is only exposed for testing.
-// Just use UpdateSyncItem() instead.
-void UpdateSyncItemForStatus(id syncItem, BOOL syncEnabled,
- sync_ui_util::MessageType status,
- const std::string& userName);
-
-} // namespace sync_ui_util
-
-#endif // CHROME_BROWSER_SYNC_SYNC_UI_UTIL_MAC_H_
-
diff --git a/chrome/browser/sync/sync_ui_util_mac.mm b/chrome/browser/sync/sync_ui_util_mac.mm
deleted file mode 100644
index dbf40f9..0000000
--- a/chrome/browser/sync/sync_ui_util_mac.mm
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/sync/sync_ui_util_mac.h"
-
-#import <Cocoa/Cocoa.h>
-
-#include "base/utf_string_conversions.h"
-#include "base/logging.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/signin/signin_manager.h"
-#include "chrome/browser/signin/signin_manager_factory.h"
-#include "chrome/browser/sync/profile_sync_service.h"
-#include "chrome/browser/sync/profile_sync_service_factory.h"
-#include "chrome/browser/sync/sync_ui_util.h"
-#include "chrome/common/pref_names.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/l10n/l10n_util_mac.h"
-
-using l10n_util::GetStringUTF16;
-using l10n_util::GetNSStringWithFixup;
-using l10n_util::GetNSStringFWithFixup;
-
-namespace sync_ui_util {
-
-void UpdateSyncItem(id syncItem, BOOL syncEnabled, Profile* profile) {
- ProfileSyncService* syncService =
- ProfileSyncServiceFactory::GetInstance()->GetForProfile(
- profile->GetOriginalProfile());
- SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
- UpdateSyncItemForStatus(
- syncItem,
- syncEnabled,
- sync_ui_util::GetStatus(syncService, *signin),
- profile->GetPrefs()->GetString(prefs::kGoogleServicesUsername));
-}
-
-void UpdateSyncItemForStatus(id syncItem, BOOL syncEnabled,
- sync_ui_util::MessageType status,
- const std::string& userName) {
- DCHECK([syncItem isKindOfClass:[NSMenuItem class]]);
- NSMenuItem* syncMenuItem = static_cast<NSMenuItem*>(syncItem);
- // Look for a separator immediately after the menu item.
- NSMenuItem* followingSeparator = nil;
- NSMenu* menu = [syncItem menu];
- if (menu) {
- NSInteger syncItemIndex = [menu indexOfItem:syncMenuItem];
- DCHECK_NE(syncItemIndex, -1);
- if ((syncItemIndex + 1) < [menu numberOfItems]) {
- NSMenuItem* menuItem = [menu itemAtIndex:(syncItemIndex + 1)];
- if ([menuItem isSeparatorItem]) {
- followingSeparator = menuItem;
- }
- }
- }
-
- // TODO(akalin): consolidate this code with the equivalent Windows code in
- // chrome/browser/ui/views/toolbar_view.cc.
- NSString* title = NULL;
- switch (status) {
- case sync_ui_util::SYNCED:
- title = GetNSStringFWithFixup(IDS_SYNC_MENU_SYNCED_LABEL,
- UTF8ToUTF16(userName));
- break;
- case sync_ui_util::SYNC_ERROR:
- title = GetNSStringWithFixup(IDS_SYNC_MENU_SYNC_ERROR_LABEL);
- break;
- case sync_ui_util::PRE_SYNCED:
- case sync_ui_util::SYNC_PROMO:
- default:
- title = GetNSStringFWithFixup(IDS_SYNC_MENU_PRE_SYNCED_LABEL,
- GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
- break;
- }
- [syncMenuItem setTitle:title];
-
- // If we don't have a sync service, hide any sync-related menu
- // items. However, sync_menu_item is enabled/disabled outside of this
- // function so we don't touch it here, and separators are always disabled.
- [syncMenuItem setHidden:!syncEnabled];
- [followingSeparator setHidden:!syncEnabled];
-}
-
-} // namespace sync_ui_util
diff --git a/chrome/browser/sync/sync_ui_util_mac_unittest.mm b/chrome/browser/sync/sync_ui_util_mac_unittest.mm
deleted file mode 100644
index b9ddc9c..0000000
--- a/chrome/browser/sync/sync_ui_util_mac_unittest.mm
+++ /dev/null
@@ -1,119 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "chrome/browser/sync/sync_ui_util_mac.h"
-
-#import <Cocoa/Cocoa.h>
-
-#include "base/memory/scoped_nsobject.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
-#include "grit/chromium_strings.h"
-#include "grit/generated_resources.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/l10n/l10n_util.h"
-#include "ui/base/l10n/l10n_util_mac.h"
-
-namespace {
-
-class SyncStatusUIHelperMacTest : public CocoaTest {
-};
-
-TEST_F(SyncStatusUIHelperMacTest, UpdateSyncItem) {
- scoped_nsobject<NSMenuItem> syncMenuItem(
- [[NSMenuItem alloc] initWithTitle:@""
- action:@selector(commandDispatch)
- keyEquivalent:@""]);
- [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
-
- std::string userName = "foo@example.com";
-
- NSString* bookmarksSynced =
- l10n_util::GetNSStringFWithFixup(IDS_SYNC_MENU_SYNCED_LABEL,
- UTF8ToUTF16(userName));
- NSString* bookmarkSyncError =
- l10n_util::GetNSStringWithFixup(IDS_SYNC_MENU_SYNC_ERROR_LABEL);
- NSString* startSync =
- l10n_util::GetNSStringFWithFixup(
- IDS_SYNC_MENU_PRE_SYNCED_LABEL,
- l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME));
-
- [syncMenuItem setTitle:@""];
- [syncMenuItem setHidden:NO];
-
- sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO,
- sync_ui_util::PRE_SYNCED,
- userName);
- EXPECT_TRUE([[syncMenuItem title] isEqualTo:startSync]);
- EXPECT_TRUE([syncMenuItem isHidden]);
-
- [syncMenuItem setTitle:@""];
- [syncMenuItem setHidden:YES];
- sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, YES,
- sync_ui_util::SYNC_ERROR,
- userName);
- EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarkSyncError]);
- EXPECT_FALSE([syncMenuItem isHidden]);
-
- [syncMenuItem setTitle:@""];
- [syncMenuItem setHidden:NO];
- sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO,
- sync_ui_util::SYNCED,
- userName);
- EXPECT_TRUE([[syncMenuItem title] isEqualTo:bookmarksSynced]);
- EXPECT_TRUE([syncMenuItem isHidden]);
-}
-
-TEST_F(SyncStatusUIHelperMacTest, UpdateSyncItemWithSeparator) {
- scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
- NSMenuItem* syncMenuItem =
- [menu addItemWithTitle:@""
- action:@selector(commandDispatch)
- keyEquivalent:@""];
- [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
- NSMenuItem* followingSeparator = [NSMenuItem separatorItem];
- [menu addItem:followingSeparator];
-
- const sync_ui_util::MessageType kStatus = sync_ui_util::PRE_SYNCED;
-
- [syncMenuItem setHidden:NO];
- [followingSeparator setHidden:NO];
- sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO, kStatus, "");
- EXPECT_FALSE([followingSeparator isEnabled]);
- EXPECT_TRUE([syncMenuItem isHidden]);
- EXPECT_TRUE([followingSeparator isHidden]);
-
- [syncMenuItem setHidden:YES];
- [followingSeparator setHidden:YES];
- sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, YES, kStatus, "");
- EXPECT_FALSE([followingSeparator isEnabled]);
- EXPECT_FALSE([syncMenuItem isHidden]);
- EXPECT_FALSE([followingSeparator isHidden]);
-}
-
-TEST_F(SyncStatusUIHelperMacTest, UpdateSyncItemWithNonSeparator) {
- scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]);
- NSMenuItem* syncMenuItem =
- [menu addItemWithTitle:@""
- action:@selector(commandDispatch)
- keyEquivalent:@""];
- [syncMenuItem setTag:IDC_SHOW_SYNC_SETUP];
- NSMenuItem* followingNonSeparator =
- [menu addItemWithTitle:@""
- action:@selector(commandDispatch)
- keyEquivalent:@""];
-
- const sync_ui_util::MessageType kStatus = sync_ui_util::PRE_SYNCED;
-
- sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, NO, kStatus, "");
- EXPECT_TRUE([followingNonSeparator isEnabled]);
- EXPECT_FALSE([followingNonSeparator isHidden]);
-
- sync_ui_util::UpdateSyncItemForStatus(syncMenuItem, YES, kStatus, "");
- EXPECT_TRUE([followingNonSeparator isEnabled]);
- EXPECT_FALSE([followingNonSeparator isHidden]);
-}
-
-} // namespace