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 #include "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
10 #include "chrome/browser/devtools/devtools_window_testing.h"
11 #include "chrome/browser/download/download_shelf.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/cocoa/view_id_util.h"
17 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "components/bookmarks/browser/bookmark_model.h"
20 #include "components/bookmarks/browser/bookmark_utils.h"
21 #include "components/bookmarks/test/bookmark_test_helpers.h"
22 #include "extensions/common/switches.h"
24 using bookmarks::BookmarkModel;
25 using content::OpenURLParams;
26 using content::Referrer;
28 // Basic sanity check of ViewID use on the mac.
29 class ViewIDTest : public InProcessBrowserTest {
31 ViewIDTest() : root_window_(nil) {
32 base::CommandLine::ForCurrentProcess()->AppendSwitch(
33 extensions::switches::kEnableExperimentalExtensionApis);
36 void CheckViewID(ViewID view_id, bool should_have) {
38 root_window_ = browser()->window()->GetNativeWindow();
40 ASSERT_TRUE(root_window_);
41 NSView* view = view_id_util::GetView(root_window_, view_id);
42 EXPECT_EQ(should_have, !!view) << " Failed id=" << view_id;
46 // Make sure FindBar is created to test VIEW_ID_FIND_IN_PAGE_TEXT_FIELD.
47 chrome::ShowFindBar(browser());
49 // Make sure docked devtools is created to test VIEW_ID_DEV_TOOLS_DOCKED
50 DevToolsWindow* devtools_window =
51 DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
53 // Make sure download shelf is created to test VIEW_ID_DOWNLOAD_SHELF
54 browser()->window()->GetDownloadShelf()->Show();
56 // Create a bookmark to test VIEW_ID_BOOKMARK_BAR_ELEMENT
57 BookmarkModel* bookmark_model =
58 BookmarkModelFactory::GetForProfile(browser()->profile());
60 if (!bookmark_model->loaded())
61 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
63 bookmarks::AddIfNotBookmarked(bookmark_model,
64 GURL(url::kAboutBlankURL),
65 base::ASCIIToUTF16("about"));
68 for (int i = VIEW_ID_TOOLBAR; i < VIEW_ID_PREDEFINED_COUNT; ++i) {
69 // Mac implementation does not support following ids yet.
70 if (i == VIEW_ID_STAR_BUTTON ||
71 i == VIEW_ID_CONTENTS_SPLIT ||
72 i == VIEW_ID_BROWSER_ACTION ||
73 i == VIEW_ID_FEEDBACK_BUTTON ||
74 i == VIEW_ID_SCRIPT_BUBBLE ||
75 i == VIEW_ID_MIC_SEARCH_BUTTON ||
76 i == VIEW_ID_TRANSLATE_BUTTON) {
80 CheckViewID(static_cast<ViewID>(i), true);
83 CheckViewID(VIEW_ID_TAB, true);
84 CheckViewID(VIEW_ID_TAB_STRIP, true);
85 CheckViewID(VIEW_ID_PREDEFINED_COUNT, false);
87 DevToolsWindowTesting::CloseDevToolsWindowSync(devtools_window);
91 NSWindow* root_window_;
94 IN_PROC_BROWSER_TEST_F(ViewIDTest, Basic) {
95 ASSERT_NO_FATAL_FAILURE(DoTest());
98 // Flaky on Mac: http://crbug.com/90557.
99 IN_PROC_BROWSER_TEST_F(ViewIDTest, DISABLED_Fullscreen) {
100 browser()->window()->EnterFullscreen(
101 GURL(), EXCLUSIVE_ACCESS_BUBBLE_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION,
103 ASSERT_NO_FATAL_FAILURE(DoTest());
106 IN_PROC_BROWSER_TEST_F(ViewIDTest, Tab) {
107 CheckViewID(VIEW_ID_TAB_0, true);
108 CheckViewID(VIEW_ID_TAB_LAST, true);
111 for (int i = 1; i <= 9; ++i) {
112 CheckViewID(static_cast<ViewID>(VIEW_ID_TAB_0 + i), false);
113 browser()->OpenURL(OpenURLParams(GURL(url::kAboutBlankURL),
116 ui::PAGE_TRANSITION_TYPED,
118 CheckViewID(static_cast<ViewID>(VIEW_ID_TAB_0 + i), true);
119 // VIEW_ID_TAB_LAST should always be available.
120 CheckViewID(VIEW_ID_TAB_LAST, true);
123 // Open the 11th tab.
124 browser()->OpenURL(OpenURLParams(GURL(url::kAboutBlankURL),
127 ui::PAGE_TRANSITION_TYPED,
129 CheckViewID(VIEW_ID_TAB_LAST, true);