blob: 5c74844e9479f89c2b9b5ed616f7d52f66583e27 [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
[email protected]b782578e2009-02-27 23:52:345#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]9423d9412009-04-14 22:13:5511#include "chrome/common/url_constants.h"
[email protected]be3877f2009-01-14 15:51:1012#include "chrome/test/browser_with_test_window_test.h"
[email protected]b7ca4e62009-01-23 20:37:2913#include "chrome/test/testing_profile.h"
[email protected]be3877f2009-01-14 15:51:1014
15typedef BrowserWithTestWindowTest BrowserCommandsTest;
16
17// Tests IDC_SELECT_TAB_0, IDC_SELECT_NEXT_TAB, IDC_SELECT_PREVIOUS_TAB and
18// IDC_SELECT_LAST_TAB.
19TEST_F(BrowserCommandsTest, TabNavigationAccelerators) {
[email protected]9423d9412009-04-14 22:13:5520 GURL about_blank(chrome::kAboutBlankURL);
21
[email protected]be3877f2009-01-14 15:51:1022 // Create three tabs.
[email protected]9423d9412009-04-14 22:13:5523 AddTab(browser(), about_blank);
24 AddTab(browser(), about_blank);
25 AddTab(browser(), about_blank);
[email protected]be3877f2009-01-14 15:51:1026
27 // Select the second tab.
28 browser()->SelectTabContentsAt(1, false);
29
30 // Navigate to the first tab using an accelerator.
31 browser()->ExecuteCommand(IDC_SELECT_TAB_0);
32 ASSERT_EQ(0, browser()->selected_index());
33
34 // Navigate to the second tab using the next accelerators.
35 browser()->ExecuteCommand(IDC_SELECT_NEXT_TAB);
36 ASSERT_EQ(1, browser()->selected_index());
37
38 // Navigate back to the first tab using the previous accelerators.
39 browser()->ExecuteCommand(IDC_SELECT_PREVIOUS_TAB);
40 ASSERT_EQ(0, browser()->selected_index());
41
42 // Navigate to the last tab using the select last accelerator.
43 browser()->ExecuteCommand(IDC_SELECT_LAST_TAB);
44 ASSERT_EQ(2, browser()->selected_index());
45}
46
47// Tests IDC_DUPLICATE_TAB.
48TEST_F(BrowserCommandsTest, DuplicateTab) {
[email protected]9423d9412009-04-14 22:13:5549 GURL url1("http://foo/1");
50 GURL url2("http://foo/2");
51 GURL url3("http://foo/3");
[email protected]be3877f2009-01-14 15:51:1052
53 // Navigate to the three urls, then go back.
[email protected]9423d9412009-04-14 22:13:5554 AddTab(browser(), url1);
[email protected]0683cf62009-04-10 19:31:4055 NavigateAndCommitActiveTab(url2);
56 NavigateAndCommitActiveTab(url3);
[email protected]be3877f2009-01-14 15:51:1057
58 size_t initial_window_count = BrowserList::size();
59
60 // Duplicate the tab.
61 browser()->ExecuteCommand(IDC_DUPLICATE_TAB);
62
63 // The duplicated tab should not end up in a new window.
[email protected]a0a8b1d2009-03-11 14:57:2264 size_t window_count = BrowserList::size();
[email protected]be3877f2009-01-14 15:51:1065 ASSERT_EQ(initial_window_count, window_count);
66
67 // And we should have a newly duplicated tab.
68 ASSERT_EQ(2, browser()->tab_count());
69
70 // Verify the stack of urls.
71 NavigationController* controller =
72 browser()->GetTabContentsAt(1)->controller();
73 ASSERT_EQ(3, controller->GetEntryCount());
74 ASSERT_EQ(2, controller->GetCurrentEntryIndex());
75 ASSERT_TRUE(url1 == controller->GetEntryAtIndex(0)->url());
76 ASSERT_TRUE(url2 == controller->GetEntryAtIndex(1)->url());
77 ASSERT_TRUE(url3 == controller->GetEntryAtIndex(2)->url());
78}
[email protected]b7ca4e62009-01-23 20:37:2979
80TEST_F(BrowserCommandsTest, BookmarkCurrentPage) {
81 // We use profile() here, since it's a TestingProfile.
82 profile()->CreateBookmarkModel(true);
83 profile()->BlockUntilBookmarkModelLoaded();
84
85 // Navigate to a url.
[email protected]9423d9412009-04-14 22:13:5586 GURL url1("http://foo/1");
87 AddTab(browser(), url1);
[email protected]b7ca4e62009-01-23 20:37:2988 browser()->OpenURL(url1, GURL(), CURRENT_TAB, PageTransition::TYPED);
89
90 // TODO(beng): remove this once we can use WebContentses directly in testing
91 // instead of the TestTabContents which causes this command not to
92 // be enabled when the tab is added (and selected).
93 browser()->command_updater()->UpdateCommandEnabled(IDC_STAR, true);
94
95 // Star it.
96 browser()->ExecuteCommand(IDC_STAR);
97
98 // It should now be bookmarked in the bookmark model.
99 EXPECT_EQ(profile(), browser()->profile());
100 EXPECT_TRUE(browser()->profile()->GetBookmarkModel()->IsBookmarked(url1));
101}