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.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/pref_names.h"
18 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "components/bookmarks/browser/bookmark_model.h"
21 #include "components/bookmarks/browser/bookmark_utils.h"
22 #include "components/bookmarks/test/bookmark_test_helpers.h"
23 #include "extensions/common/switches.h"
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 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::OpenDevToolsWindowForTest(browser(), true);
52 // Make sure download shelf is created to test VIEW_ID_DOWNLOAD_SHELF
53 browser()->window()->GetDownloadShelf()->Show();
55 // Create a bookmark to test VIEW_ID_BOOKMARK_BAR_ELEMENT
56 BookmarkModel* bookmark_model =
57 BookmarkModelFactory::GetForProfile(browser()->profile());
59 if (!bookmark_model->loaded())
60 test::WaitForBookmarkModelToLoad(bookmark_model);
62 bookmark_utils::AddIfNotBookmarked(
63 bookmark_model, GURL(content::kAboutBlankURL),
64 base::ASCIIToUTF16("about"));
67 for (int i = VIEW_ID_TOOLBAR; i < VIEW_ID_PREDEFINED_COUNT; ++i) {
68 // Mac implementation does not support following ids yet.
69 if (i == VIEW_ID_STAR_BUTTON ||
70 i == VIEW_ID_CONTENTS_SPLIT ||
71 i == VIEW_ID_BROWSER_ACTION ||
72 i == VIEW_ID_FEEDBACK_BUTTON ||
73 i == VIEW_ID_SCRIPT_BUBBLE ||
74 i == VIEW_ID_MIC_SEARCH_BUTTON ||
75 i == VIEW_ID_TRANSLATE_BUTTON) {
79 CheckViewID(static_cast<ViewID>(i), true);
82 CheckViewID(VIEW_ID_TAB, true);
83 CheckViewID(VIEW_ID_TAB_STRIP, true);
84 CheckViewID(VIEW_ID_PREDEFINED_COUNT, false);
88 NSWindow* root_window_;
91 IN_PROC_BROWSER_TEST_F(ViewIDTest, Basic) {
92 ASSERT_NO_FATAL_FAILURE(DoTest());
95 // Flaky on Mac: http://crbug.com/90557.
96 IN_PROC_BROWSER_TEST_F(ViewIDTest, DISABLED_Fullscreen) {
97 browser()->window()->EnterFullscreen(
98 GURL(), FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION);
99 ASSERT_NO_FATAL_FAILURE(DoTest());
102 IN_PROC_BROWSER_TEST_F(ViewIDTest, Tab) {
103 CheckViewID(VIEW_ID_TAB_0, true);
104 CheckViewID(VIEW_ID_TAB_LAST, true);
107 for (int i = 1; i <= 9; ++i) {
108 CheckViewID(static_cast<ViewID>(VIEW_ID_TAB_0 + i), false);
109 browser()->OpenURL(OpenURLParams(
110 GURL(content::kAboutBlankURL), Referrer(), NEW_BACKGROUND_TAB,
111 content::PAGE_TRANSITION_TYPED, false));
112 CheckViewID(static_cast<ViewID>(VIEW_ID_TAB_0 + i), true);
113 // VIEW_ID_TAB_LAST should always be available.
114 CheckViewID(VIEW_ID_TAB_LAST, true);
117 // Open the 11th tab.
118 browser()->OpenURL(OpenURLParams(
119 GURL(content::kAboutBlankURL), Referrer(), NEW_BACKGROUND_TAB,
120 content::PAGE_TRANSITION_TYPED, false));
121 CheckViewID(VIEW_ID_TAB_LAST, true);