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 #import <Cocoa/Cocoa.h>
7 #include "base/strings/sys_string_conversions.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h"
11 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "components/bookmarks/browser/bookmark_model.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h"
17 using base::ASCIIToUTF16;
18 using bookmarks::BookmarkModel;
19 using bookmarks::BookmarkNode;
21 @interface BookmarkAllTabsControllerOverride : BookmarkAllTabsController
24 @implementation BookmarkAllTabsControllerOverride
26 - (void)UpdateActiveTabPairs {
27 ActiveTabsNameURLPairVector* activeTabPairsVector =
28 [self activeTabPairsVector];
29 activeTabPairsVector->clear();
30 activeTabPairsVector->push_back(
31 ActiveTabNameURLPair(ASCIIToUTF16("at-0"), GURL("http://at-0.com")));
32 activeTabPairsVector->push_back(
33 ActiveTabNameURLPair(ASCIIToUTF16("at-1"), GURL("http://at-1.com")));
34 activeTabPairsVector->push_back(
35 ActiveTabNameURLPair(ASCIIToUTF16("at-2"), GURL("http://at-2.com")));
40 class BookmarkAllTabsControllerTest : public CocoaProfileTest {
42 const BookmarkNode* parent_node_;
43 BookmarkAllTabsControllerOverride* controller_;
44 const BookmarkNode* folder_a_;
47 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
48 const BookmarkNode* root = model->bookmark_bar_node();
49 folder_a_ = model->AddFolder(root, 0, ASCIIToUTF16("a"));
50 model->AddURL(folder_a_, 0, ASCIIToUTF16("a-0"), GURL("http://a-0.com"));
51 model->AddURL(folder_a_, 1, ASCIIToUTF16("a-1"), GURL("http://a-1.com"));
52 model->AddURL(folder_a_, 2, ASCIIToUTF16("a-2"), GURL("http://a-2.com"));
55 virtual BookmarkAllTabsControllerOverride* CreateController() {
56 return [[BookmarkAllTabsControllerOverride alloc]
57 initWithParentWindow:test_window()
61 title:base::string16()
62 configuration:BookmarkEditor::SHOW_TREE];
65 void SetUp() override {
66 CocoaProfileTest::SetUp();
67 ASSERT_TRUE(profile());
70 controller_ = CreateController();
71 [controller_ runAsModalSheet];
74 void TearDown() override {
76 CocoaProfileTest::TearDown();
80 TEST_F(BookmarkAllTabsControllerTest, BookmarkAllTabs) {
81 // OK button should always be enabled.
82 EXPECT_TRUE([controller_ okButtonEnabled]);
83 [controller_ selectTestNodeInBrowser:folder_a_];
84 [controller_ setDisplayName:@"ALL MY TABS"];
86 EXPECT_EQ(4, folder_a_->child_count());
87 const BookmarkNode* folderChild = folder_a_->GetChild(3);
88 EXPECT_EQ(folderChild->GetTitle(), ASCIIToUTF16("ALL MY TABS"));
89 EXPECT_EQ(3, folderChild->child_count());