mac: Redraw bookmark bar view buttons when the bookmark bar changes size.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_all_tabs_controller_unittest.mm
blob74bdde1032c2f50070c8936ce57b7f2d73dc87b7
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
22 @end
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")));
38 @end
40 class BookmarkAllTabsControllerTest : public CocoaProfileTest {
41  public:
42   const BookmarkNode* parent_node_;
43   BookmarkAllTabsControllerOverride* controller_;
44   const BookmarkNode* folder_a_;
46   void CreateModel() {
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"));
53   }
55   virtual BookmarkAllTabsControllerOverride* CreateController() {
56     return [[BookmarkAllTabsControllerOverride alloc]
57             initWithParentWindow:test_window()
58                          profile:profile()
59                           parent:folder_a_
60                              url:GURL()
61                            title:base::string16()
62                    configuration:BookmarkEditor::SHOW_TREE];
63   }
65   void SetUp() override {
66     CocoaProfileTest::SetUp();
67     ASSERT_TRUE(profile());
69     CreateModel();
70     controller_ = CreateController();
71     [controller_ runAsModalSheet];
72   }
74   void TearDown() override {
75     controller_ = NULL;
76     CocoaProfileTest::TearDown();
77   }
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"];
85   [controller_ ok:nil];
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());