| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/profile_menu_controller.h" | 5 #import "chrome/browser/ui/cocoa/profile_menu_controller.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/threading/thread_restrictions.h" | 8 #include "base/threading/thread_restrictions.h" |
| 9 #include "chrome/browser/profiles/avatar_menu_model.h" | 9 #include "chrome/browser/profiles/avatar_menu_model.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
| 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 13 #include "chrome/browser/ui/cocoa/run_loop_testing.h" | 13 #include "chrome/browser/ui/cocoa/run_loop_testing.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/test_browser_window.h" | 15 #include "chrome/test/base/test_browser_window.h" |
| 16 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 17 #include "testing/gtest_mac.h" | 17 #include "testing/gtest_mac.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 << " (from line " << line << ")"; | 64 << " (from line " << line << ")"; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 | 68 |
| 69 ProfileMenuController* controller() { return controller_.get(); } | 69 ProfileMenuController* controller() { return controller_.get(); } |
| 70 | 70 |
| 71 NSMenuItem* menu_item() { return item_.get(); } | 71 NSMenuItem* menu_item() { return item_.get(); } |
| 72 | 72 |
| 73 private: | 73 private: |
| 74 scoped_nsobject<NSMenuItem> item_; | 74 base::scoped_nsobject<NSMenuItem> item_; |
| 75 scoped_nsobject<ProfileMenuController> controller_; | 75 base::scoped_nsobject<ProfileMenuController> controller_; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 TEST_F(ProfileMenuControllerTest, InitializeMenu) { | 78 TEST_F(ProfileMenuControllerTest, InitializeMenu) { |
| 79 NSMenu* menu = [controller() menu]; | 79 NSMenu* menu = [controller() menu]; |
| 80 // <sep>, Edit, <sep>, New. | 80 // <sep>, Edit, <sep>, New. |
| 81 ASSERT_EQ(4, [menu numberOfItems]); | 81 ASSERT_EQ(4, [menu numberOfItems]); |
| 82 | 82 |
| 83 TestBottomItems(); | 83 TestBottomItems(); |
| 84 | 84 |
| 85 EXPECT_TRUE([menu_item() isHidden]); | 85 EXPECT_TRUE([menu_item() isHidden]); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 item = [menu itemAtIndex:2]; | 118 item = [menu itemAtIndex:2]; |
| 119 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); | 119 EXPECT_EQ(@selector(switchToProfileFromMenu:), [item action]); |
| 120 | 120 |
| 121 TestBottomItems(); | 121 TestBottomItems(); |
| 122 | 122 |
| 123 EXPECT_FALSE([menu_item() isHidden]); | 123 EXPECT_FALSE([menu_item() isHidden]); |
| 124 } | 124 } |
| 125 | 125 |
| 126 TEST_F(ProfileMenuControllerTest, InsertItems) { | 126 TEST_F(ProfileMenuControllerTest, InsertItems) { |
| 127 scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle: @""]); | 127 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@""]); |
| 128 ASSERT_EQ(0, [menu numberOfItems]); | 128 ASSERT_EQ(0, [menu numberOfItems]); |
| 129 | 129 |
| 130 // With only one profile, insertItems should be a no-op. | 130 // With only one profile, insertItems should be a no-op. |
| 131 BOOL result = [controller() insertItemsIntoMenu:menu | 131 BOOL result = [controller() insertItemsIntoMenu:menu |
| 132 atOffset:0 | 132 atOffset:0 |
| 133 fromDock:NO]; | 133 fromDock:NO]; |
| 134 EXPECT_FALSE(result); | 134 EXPECT_FALSE(result); |
| 135 EXPECT_EQ(0, [menu numberOfItems]); | 135 EXPECT_EQ(0, [menu numberOfItems]); |
| 136 [menu removeAllItems]; | 136 [menu removeAllItems]; |
| 137 | 137 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 local_state->SetString(prefs::kProfileLastUsed, | 236 local_state->SetString(prefs::kProfileLastUsed, |
| 237 profile3_path.BaseName().MaybeAsASCII()); | 237 profile3_path.BaseName().MaybeAsASCII()); |
| 238 | 238 |
| 239 // Simulate the active browser changing to NULL and ensure a profile doesn't | 239 // Simulate the active browser changing to NULL and ensure a profile doesn't |
| 240 // get created by disallowing IO operations temporarily. | 240 // get created by disallowing IO operations temporarily. |
| 241 const bool io_was_allowed = base::ThreadRestrictions::SetIOAllowed(false); | 241 const bool io_was_allowed = base::ThreadRestrictions::SetIOAllowed(false); |
| 242 [controller() activeBrowserChangedTo:NULL]; | 242 [controller() activeBrowserChangedTo:NULL]; |
| 243 base::ThreadRestrictions::SetIOAllowed(io_was_allowed); | 243 base::ThreadRestrictions::SetIOAllowed(io_was_allowed); |
| 244 } | 244 } |
| 245 | 245 |
| OLD | NEW |