| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/mac/scoped_nsobject.h" | 5 #import "base/mac/scoped_nsobject.h" |
| 6 #include "base/strings/string16.h" | 6 #include "base/strings/string16.h" |
| 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 7 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" | 9 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_menu_cocoa_controller.h" |
| 10 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" | 10 #include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/bookmarks/browser/bookmark_model.h" | 12 #include "components/bookmarks/browser/bookmark_model.h" |
| 13 #include "components/bookmarks/browser/bookmark_utils.h" | 13 #include "components/bookmarks/browser/bookmark_utils.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using bookmarks::BookmarkModel; | 16 using bookmarks::BookmarkModel; |
| 17 using bookmarks::BookmarkNode; | 17 using bookmarks::BookmarkNode; |
| 18 | 18 |
| 19 @interface FakeBookmarkMenuController : BookmarkMenuCocoaController { | 19 @interface FakeBookmarkMenuController : BookmarkMenuCocoaController { |
| 20 @public | 20 @public |
| 21 const BookmarkNode* nodes_[2]; | 21 const BookmarkNode* nodes_[2]; |
| 22 BOOL opened_[2]; | 22 BOOL opened_[2]; |
| 23 BOOL opened_new_foreground_tab; | |
| 24 BOOL opened_new_window; | |
| 25 BOOL opened_off_the_record; | |
| 26 } | 23 } |
| 27 - (id)initWithProfile:(Profile*)profile; | 24 - (id)initWithProfile:(Profile*)profile; |
| 28 @end | 25 @end |
| 29 | 26 |
| 30 @implementation FakeBookmarkMenuController | 27 @implementation FakeBookmarkMenuController |
| 31 | 28 |
| 32 - (id)initWithProfile:(Profile*)profile { | 29 - (id)initWithProfile:(Profile*)profile { |
| 33 if ((self = [super init])) { | 30 if ((self = [super init])) { |
| 34 base::string16 empty; | 31 base::string16 empty; |
| 35 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile); | 32 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 47 } | 44 } |
| 48 | 45 |
| 49 - (void)openURLForNode:(const BookmarkNode*)node { | 46 - (void)openURLForNode:(const BookmarkNode*)node { |
| 50 std::string url = node->url().possibly_invalid_spec(); | 47 std::string url = node->url().possibly_invalid_spec(); |
| 51 if (url.find("http://0.com") != std::string::npos) | 48 if (url.find("http://0.com") != std::string::npos) |
| 52 opened_[0] = YES; | 49 opened_[0] = YES; |
| 53 if (url.find("http://1.com") != std::string::npos) | 50 if (url.find("http://1.com") != std::string::npos) |
| 54 opened_[1] = YES; | 51 opened_[1] = YES; |
| 55 } | 52 } |
| 56 | 53 |
| 57 - (void)openAll:(NSInteger)tag | |
| 58 withDisposition:(WindowOpenDisposition)disposition { | |
| 59 if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB) { | |
| 60 opened_new_foreground_tab = YES; | |
| 61 } else if (disposition == WindowOpenDisposition::NEW_WINDOW) { | |
| 62 opened_new_window = YES; | |
| 63 } else if (disposition == WindowOpenDisposition::OFF_THE_RECORD) { | |
| 64 opened_off_the_record = YES; | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 @end // FakeBookmarkMenuController | 54 @end // FakeBookmarkMenuController |
| 69 | 55 |
| 70 class BookmarkMenuCocoaControllerTest : public CocoaProfileTest { | 56 class BookmarkMenuCocoaControllerTest : public CocoaProfileTest { |
| 71 public: | 57 public: |
| 72 void SetUp() override { | 58 void SetUp() override { |
| 73 CocoaProfileTest::SetUp(); | 59 CocoaProfileTest::SetUp(); |
| 74 ASSERT_TRUE(profile()); | 60 ASSERT_TRUE(profile()); |
| 75 | 61 |
| 76 controller_.reset( | 62 controller_.reset( |
| 77 [[FakeBookmarkMenuController alloc] initWithProfile:profile()]); | 63 [[FakeBookmarkMenuController alloc] initWithProfile:profile()]); |
| 78 } | 64 } |
| 79 | 65 |
| 80 FakeBookmarkMenuController* controller() { return controller_.get(); } | 66 FakeBookmarkMenuController* controller() { return controller_.get(); } |
| 81 | 67 |
| 82 private: | 68 private: |
| 83 base::scoped_nsobject<FakeBookmarkMenuController> controller_; | 69 base::scoped_nsobject<FakeBookmarkMenuController> controller_; |
| 84 }; | 70 }; |
| 85 | 71 |
| 86 TEST_F(BookmarkMenuCocoaControllerTest, TestOpenItem) { | 72 TEST_F(BookmarkMenuCocoaControllerTest, TestOpenItem) { |
| 87 FakeBookmarkMenuController* c = controller(); | 73 FakeBookmarkMenuController* c = controller(); |
| 88 NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; | 74 NSMenuItem *item = [[[NSMenuItem alloc] init] autorelease]; |
| 89 for (int i = 0; i < 2; i++) { | 75 for (int i = 0; i < 2; i++) { |
| 90 [item setTag:i]; | 76 [item setTag:i]; |
| 91 ASSERT_EQ(c->opened_[i], NO); | 77 ASSERT_EQ(c->opened_[i], NO); |
| 92 [c openBookmarkMenuItem:item]; | 78 [c openBookmarkMenuItem:item]; |
| 93 ASSERT_NE(c->opened_[i], NO); | 79 ASSERT_NE(c->opened_[i], NO); |
| 94 } | 80 } |
| 95 | |
| 96 // Test three versions of 'Open All Bookmarks' item. tag id means nothing. | |
| 97 // I just reset the tag id to zero. | |
| 98 [item setTag:0]; | |
| 99 EXPECT_EQ(c->opened_new_foreground_tab, NO); | |
| 100 [c openAllBookmarks:item]; | |
| 101 EXPECT_NE(c->opened_new_foreground_tab, NO); | |
| 102 | |
| 103 EXPECT_EQ(c->opened_new_window, NO); | |
| 104 [c openAllBookmarksNewWindow:item]; | |
| 105 EXPECT_NE(c->opened_new_window, NO); | |
| 106 | |
| 107 EXPECT_EQ(c->opened_off_the_record, NO); | |
| 108 [c openAllBookmarksIncognitoWindow:item]; | |
| 109 EXPECT_NE(c->opened_off_the_record, NO); | |
| 110 } | 81 } |
| OLD | NEW |