BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / view_id_util_browsertest.mm
blobdafee4c58c99d628af81e730c9b4913c3437350b
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 {
30  public:
31   ViewIDTest() : root_window_(nil) {
32     base::CommandLine::ForCurrentProcess()->AppendSwitch(
33         extensions::switches::kEnableExperimentalExtensionApis);
34   }
36   void CheckViewID(ViewID view_id, bool should_have) {
37     if (!root_window_)
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;
43   }
45   void DoTest() {
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());
59     if (bookmark_model) {
60       if (!bookmark_model->loaded())
61         bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
63       bookmarks::AddIfNotBookmarked(bookmark_model,
64                                     GURL(url::kAboutBlankURL),
65                                     base::ASCIIToUTF16("about"));
66     }
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) {
77         continue;
78       }
80       CheckViewID(static_cast<ViewID>(i), true);
81     }
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);
88   }
90  private:
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,
102       false);
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);
110   // Open 9 new tabs.
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),
114                                      Referrer(),
115                                      NEW_BACKGROUND_TAB,
116                                      ui::PAGE_TRANSITION_TYPED,
117                                      false));
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);
121   }
123   // Open the 11th tab.
124   browser()->OpenURL(OpenURLParams(GURL(url::kAboutBlankURL),
125                                    Referrer(),
126                                    NEW_BACKGROUND_TAB,
127                                    ui::PAGE_TRANSITION_TYPED,
128                                    false));
129   CheckViewID(VIEW_ID_TAB_LAST, true);