blob: 3b90289a4477309452040b8973a9e82397322cc3 [file] [log] [blame]
[email protected]be3877f2009-01-14 15:51:101// Copyright (c) 2006-2008 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.
4
5#include "chrome/app/chrome_dll_resource.h"
[email protected]b7ca4e62009-01-23 20:37:296#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]be3877f2009-01-14 15:51:107#include "chrome/browser/browser.h"
8#include "chrome/browser/browser_list.h"
[email protected]f3ec7742009-01-15 00:59:169#include "chrome/browser/tab_contents/navigation_controller.h"
10#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]be3877f2009-01-14 15:51:1011#include "chrome/test/browser_with_test_window_test.h"
[email protected]b7ca4e62009-01-23 20:37:2912#include "chrome/test/testing_profile.h"
[email protected]be3877f2009-01-14 15:51:1013
14typedef BrowserWithTestWindowTest BrowserCommandsTest;
15
16// Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
17// IDC_SELECT_LAST_TAB.
18TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
19 // Create three tabs.
20 AddTestingTab(browser());
21 AddTestingTab(browser());
22 AddTestingTab(browser());
23
24 // Select the second tab.
25 browser()->SelectTabContentsAt(1, false);
26
27 // Navigate to the first tab using an accelerator.
28 browser()->ExecuteCommand(IDC_SELECT_TAB_0);
29 ASSERT_EQ(0, browser()->selected_index());
30
31 // Navigate to the second tab using the next accelerators.
32 browser()->ExecuteCommand(IDC_SELECT_NEXT_TAB);
33 ASSERT_EQ(1, browser()->selected_index());
34
35 // Navigate back to the first tab using the previous accelerators.
36 browser()->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
37 ASSERT_EQ(0, browser()->selected_index());
38
39 // Navigate to the last tab using the select last accelerator.
40 browser()->ExecuteCommand(IDC_SELECT_LAST_TAB);
41 ASSERT_EQ(2, browser()->selected_index());
42}
43
44// Tests IDC_DUPLICATE_TAB.
45TEST_F(BrowserCommandsTest, DuplicateTab) {
46 GURL url1 = test_url_with_path("1");
47 GURL url2 = test_url_with_path("2");
48 GURL url3 = test_url_with_path("3");
49
50 // Navigate to the three urls, then go back.
51 AddTestingTab(browser());
52 browser()->OpenURL(url1, GURL(), CURRENT_TAB, PageTransition::TYPED);
53 browser()->OpenURL(url2, GURL(), CURRENT_TAB, PageTransition::TYPED);
54 browser()->OpenURL(url3, GURL(), CURRENT_TAB, PageTransition::TYPED);
55
56 size_t initial_window_count = BrowserList::size();
57
58 // Duplicate the tab.
59 browser()->ExecuteCommand(IDC_DUPLICATE_TAB);
60
61 // The duplicated tab should not end up in a new window.
62 int window_count = BrowserList::size();
63 ASSERT_EQ(initial_window_count, window_count);
64
65 // And we should have a newly duplicated tab.
66 ASSERT_EQ(2, browser()->tab_count());
67
68 // Verify the stack of urls.
69 NavigationController* controller =
70 browser()->GetTabContentsAt(1)->controller();
71 ASSERT_EQ(3, controller->GetEntryCount());
72 ASSERT_EQ(2, controller->GetCurrentEntryIndex());
73 ASSERT_TRUE(url1 == controller->GetEntryAtIndex(0)->url());
74 ASSERT_TRUE(url2 == controller->GetEntryAtIndex(1)->url());
75 ASSERT_TRUE(url3 == controller->GetEntryAtIndex(2)->url());
76}
[email protected]b7ca4e62009-01-23 20:37:2977
78TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
79 // We use profile() here, since it's a TestingProfile.
80 profile()->CreateBookmarkModel(true);
81 profile()->BlockUntilBookmarkModelLoaded();
82
83 // Navigate to a url.
84 GURL url1 = test_url_with_path("1");
85 AddTestingTab(browser());
86 browser()->OpenURL(url1, GURL(), CURRENT_TAB, PageTransition::TYPED);
87
88 // TODO(beng): remove this once we can use WebContentses directly in testing
89 // instead of the TestTabContents which causes this command not to
90 // be enabled when the tab is added (and selected).
91 browser()->command_updater()->UpdateCommandEnabled(IDC_STAR, true);
92
93 // Star it.
94 browser()->ExecuteCommand(IDC_STAR);
95
96 // It should now be bookmarked in the bookmark model.
97 EXPECT_EQ(profile(), browser()->profile());
98 EXPECT_TRUE(browser()->profile()->GetBookmarkModel()->IsBookmarked(url1));
99}