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;
19 @interface BookmarkAllTabsControllerOverride : BookmarkAllTabsController
22 @implementation BookmarkAllTabsControllerOverride
24 - (void)UpdateActiveTabPairs {
25 ActiveTabsNameURLPairVector* activeTabPairsVector =
26 [self activeTabPairsVector];
27 activeTabPairsVector->clear();
28 activeTabPairsVector->push_back(
29 ActiveTabNameURLPair(ASCIIToUTF16("at-0"), GURL("http://at-0.com")));
30 activeTabPairsVector->push_back(
31 ActiveTabNameURLPair(ASCIIToUTF16("at-1"), GURL("http://at-1.com")));
32 activeTabPairsVector->push_back(
33 ActiveTabNameURLPair(ASCIIToUTF16("at-2"), GURL("http://at-2.com")));
38 class BookmarkAllTabsControllerTest : public CocoaProfileTest {
40 const BookmarkNode* parent_node_;
41 BookmarkAllTabsControllerOverride* controller_;
42 const BookmarkNode* folder_a_;
45 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile());
46 const BookmarkNode* root = model->bookmark_bar_node();
47 folder_a_ = model->AddFolder(root, 0, ASCIIToUTF16("a"));
48 model->AddURL(folder_a_, 0, ASCIIToUTF16("a-0"), GURL("http://a-0.com"));
49 model->AddURL(folder_a_, 1, ASCIIToUTF16("a-1"), GURL("http://a-1.com"));
50 model->AddURL(folder_a_, 2, ASCIIToUTF16("a-2"), GURL("http://a-2.com"));
53 virtual BookmarkAllTabsControllerOverride* CreateController() {
54 return [[BookmarkAllTabsControllerOverride alloc]
55 initWithParentWindow:test_window()
59 title:base::string16()
60 configuration:BookmarkEditor::SHOW_TREE];
63 virtual void SetUp() {
64 CocoaProfileTest::SetUp();
65 ASSERT_TRUE(profile());
68 controller_ = CreateController();
69 [controller_ runAsModalSheet];
72 virtual void TearDown() {
74 CocoaProfileTest::TearDown();
78 TEST_F(BookmarkAllTabsControllerTest, BookmarkAllTabs) {
79 // OK button should always be enabled.
80 EXPECT_TRUE([controller_ okButtonEnabled]);
81 [controller_ selectTestNodeInBrowser:folder_a_];
82 [controller_ setDisplayName:@"ALL MY TABS"];
84 EXPECT_EQ(4, folder_a_->child_count());
85 const BookmarkNode* folderChild = folder_a_->GetChild(3);
86 EXPECT_EQ(folderChild->GetTitle(), ASCIIToUTF16("ALL MY TABS"));
87 EXPECT_EQ(3, folderChild->child_count());