[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / view_id_util_browsertest.mm
blob033a15ce28c78d5b796c490ac36a6fd796ea3ff2
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 {
30  public:
31   ViewIDTest() : root_window_(nil) {
32     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::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());
58     if (bookmark_model) {
59       if (!bookmark_model->loaded())
60         test::WaitForBookmarkModelToLoad(bookmark_model);
62       bookmark_utils::AddIfNotBookmarked(
63           bookmark_model, GURL(content::kAboutBlankURL),
64           base::ASCIIToUTF16("about"));
65     }
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_FEEDBACK_BUTTON ||
72           i == VIEW_ID_SCRIPT_BUBBLE ||
73           i == VIEW_ID_MIC_SEARCH_BUTTON ||
74           i == VIEW_ID_TRANSLATE_BUTTON) {
75         continue;
76       }
78       CheckViewID(static_cast<ViewID>(i), true);
79     }
81     CheckViewID(VIEW_ID_TAB, true);
82     CheckViewID(VIEW_ID_TAB_STRIP, true);
83     CheckViewID(VIEW_ID_PREDEFINED_COUNT, false);
84   }
86  private:
87   NSWindow* root_window_;
90 IN_PROC_BROWSER_TEST_F(ViewIDTest, Basic) {
91   ASSERT_NO_FATAL_FAILURE(DoTest());
94 // Flaky on Mac: http://crbug.com/90557.
95 IN_PROC_BROWSER_TEST_F(ViewIDTest, DISABLED_Fullscreen) {
96   browser()->window()->EnterFullscreen(
97       GURL(), FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION);
98   ASSERT_NO_FATAL_FAILURE(DoTest());
101 IN_PROC_BROWSER_TEST_F(ViewIDTest, Tab) {
102   CheckViewID(VIEW_ID_TAB_0, true);
103   CheckViewID(VIEW_ID_TAB_LAST, true);
105   // Open 9 new tabs.
106   for (int i = 1; i <= 9; ++i) {
107     CheckViewID(static_cast<ViewID>(VIEW_ID_TAB_0 + i), false);
108     browser()->OpenURL(OpenURLParams(
109         GURL(content::kAboutBlankURL), Referrer(), NEW_BACKGROUND_TAB,
110          content::PAGE_TRANSITION_TYPED, false));
111     CheckViewID(static_cast<ViewID>(VIEW_ID_TAB_0 + i), true);
112     // VIEW_ID_TAB_LAST should always be available.
113     CheckViewID(VIEW_ID_TAB_LAST, true);
114   }
116   // Open the 11th tab.
117   browser()->OpenURL(OpenURLParams(
118       GURL(content::kAboutBlankURL), Referrer(), NEW_BACKGROUND_TAB,
119       content::PAGE_TRANSITION_TYPED, false));
120   CheckViewID(VIEW_ID_TAB_LAST, true);