| 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 #include "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 5 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 12 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" | 13 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
| 11 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" | 14 #include "chrome/browser/ui/cocoa/history_menu_bridge.h" |
| 12 #include "chrome/browser/ui/cocoa/history_menu_cocoa_controller.h" | |
| 13 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 17 |
| 16 @interface FakeHistoryMenuController : HistoryMenuCocoaController { | 18 @interface FakeHistoryMenuController : HistoryMenuCocoaController { |
| 17 @public | 19 @public |
| 18 BOOL opened_[2]; | 20 BOOL opened_[2]; |
| 19 } | 21 } |
| 20 @end | 22 @end |
| 21 | 23 |
| 22 @implementation FakeHistoryMenuController | 24 @implementation FakeHistoryMenuController |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 63 |
| 62 std::map<NSMenuItem*, HistoryMenuBridge::HistoryItem*>& menu_item_map() { | 64 std::map<NSMenuItem*, HistoryMenuBridge::HistoryItem*>& menu_item_map() { |
| 63 return bridge_->menu_item_map_; | 65 return bridge_->menu_item_map_; |
| 64 } | 66 } |
| 65 | 67 |
| 66 FakeHistoryMenuController* controller() { | 68 FakeHistoryMenuController* controller() { |
| 67 return static_cast<FakeHistoryMenuController*>(bridge_->controller_.get()); | 69 return static_cast<FakeHistoryMenuController*>(bridge_->controller_.get()); |
| 68 } | 70 } |
| 69 | 71 |
| 70 private: | 72 private: |
| 71 scoped_ptr<HistoryMenuBridge> bridge_; | 73 std::unique_ptr<HistoryMenuBridge> bridge_; |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 TEST_F(HistoryMenuCocoaControllerTest, OpenURLForItem) { | 76 TEST_F(HistoryMenuCocoaControllerTest, OpenURLForItem) { |
| 75 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@"History"]); | 77 base::scoped_nsobject<NSMenu> menu([[NSMenu alloc] initWithTitle:@"History"]); |
| 76 CreateItems(menu.get()); | 78 CreateItems(menu.get()); |
| 77 | 79 |
| 78 std::map<NSMenuItem*, HistoryMenuBridge::HistoryItem*>& items = | 80 std::map<NSMenuItem*, HistoryMenuBridge::HistoryItem*>& items = |
| 79 menu_item_map(); | 81 menu_item_map(); |
| 80 std::map<NSMenuItem*, HistoryMenuBridge::HistoryItem*>::iterator it = | 82 std::map<NSMenuItem*, HistoryMenuBridge::HistoryItem*>::iterator it = |
| 81 items.begin(); | 83 items.begin(); |
| 82 | 84 |
| 83 for ( ; it != items.end(); ++it) { | 85 for ( ; it != items.end(); ++it) { |
| 84 HistoryMenuBridge::HistoryItem* item = it->second; | 86 HistoryMenuBridge::HistoryItem* item = it->second; |
| 85 EXPECT_FALSE(controller()->opened_[item->session_id]); | 87 EXPECT_FALSE(controller()->opened_[item->session_id]); |
| 86 [controller() openHistoryMenuItem:it->first]; | 88 [controller() openHistoryMenuItem:it->first]; |
| 87 EXPECT_TRUE(controller()->opened_[item->session_id]); | 89 EXPECT_TRUE(controller()->opened_[item->session_id]); |
| 88 } | 90 } |
| 89 } | 91 } |
| OLD | NEW |