Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / bookmarks / bookmark_all_tabs_controller_unittest.mm
blobe2dc89454b8253c3a8c95b51bde1c1dc4d1103ad
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.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #import "chrome/browser/ui/cocoa/bookmarks/bookmark_all_tabs_controller.h"
12 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
13 #include "chrome/test/base/testing_profile.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h"
17 using base::ASCIIToUTF16;
19 @interface BookmarkAllTabsControllerOverride : BookmarkAllTabsController
20 @end
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")));
36 @end
38 class BookmarkAllTabsControllerTest : public CocoaProfileTest {
39  public:
40   const BookmarkNode* parent_node_;
41   BookmarkAllTabsControllerOverride* controller_;
42   const BookmarkNode* folder_a_;
44   void CreateModel() {
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"));
51   }
53   virtual BookmarkAllTabsControllerOverride* CreateController() {
54     return [[BookmarkAllTabsControllerOverride alloc]
55             initWithParentWindow:test_window()
56                          profile:profile()
57                           parent:folder_a_
58                              url:GURL()
59                            title:base::string16()
60                    configuration:BookmarkEditor::SHOW_TREE];
61   }
63   virtual void SetUp() {
64     CocoaProfileTest::SetUp();
65     ASSERT_TRUE(profile());
67     CreateModel();
68     controller_ = CreateController();
69     [controller_ runAsModalSheet];
70   }
72   virtual void TearDown() {
73     controller_ = NULL;
74     CocoaProfileTest::TearDown();
75   }
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"];
83   [controller_ ok:nil];
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());