Home | History | Annotate | Download | only in gtk
      1 // Copyright (c) 2011 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 
      5 #include <gtk/gtk.h>
      6 
      7 #include "chrome/browser/ui/browser.h"
      8 #include "chrome/browser/ui/browser_window.h"
      9 #include "chrome/browser/ui/gtk/view_id_util.h"
     10 #include "chrome/common/url_constants.h"
     11 #include "chrome/test/in_process_browser_test.h"
     12 
     13 class ViewIDTest : public InProcessBrowserTest {
     14  public:
     15   ViewIDTest() : root_window_(NULL) {}
     16 
     17   void CheckViewID(ViewID id, bool should_have) {
     18     if (!root_window_)
     19       root_window_ = GTK_WIDGET(browser()->window()->GetNativeHandle());
     20 
     21     ASSERT_TRUE(root_window_);
     22     EXPECT_EQ(should_have, !!ViewIDUtil::GetWidget(root_window_, id))
     23         << " Failed id=" << id;
     24   }
     25 
     26  private:
     27   GtkWidget* root_window_;
     28 };
     29 
     30 IN_PROC_BROWSER_TEST_F(ViewIDTest, Basic) {
     31   // Make sure FindBar is created to test
     32   // VIEW_ID_FIND_IN_PAGE_TEXT_FIELD and VIEW_ID_FIND_IN_PAGE.
     33   browser()->ShowFindBar();
     34 
     35   for (int i = VIEW_ID_TOOLBAR; i < VIEW_ID_PREDEFINED_COUNT; ++i) {
     36     // The following ids are used only in views implementation.
     37     if (i == VIEW_ID_CONTENTS_SPLIT ||
     38         i == VIEW_ID_INFO_BAR_CONTAINER ||
     39         i == VIEW_ID_DOWNLOAD_SHELF ||
     40         i == VIEW_ID_BOOKMARK_BAR_ELEMENT ||
     41         i == VIEW_ID_TAB ||
     42         i == VIEW_ID_SIDE_BAR_CONTAINER ||
     43         i == VIEW_ID_SIDE_BAR_SPLIT ||
     44         i == VIEW_ID_FEEDBACK_BUTTON) {
     45       continue;
     46     }
     47 
     48     CheckViewID(static_cast<ViewID>(i), true);
     49   }
     50 
     51   CheckViewID(VIEW_ID_PREDEFINED_COUNT, false);
     52 }
     53 
     54 IN_PROC_BROWSER_TEST_F(ViewIDTest, Delegate) {
     55   CheckViewID(VIEW_ID_TAB_0, true);
     56   CheckViewID(VIEW_ID_TAB_1, false);
     57 
     58   browser()->OpenURL(GURL(chrome::kAboutBlankURL), GURL(),
     59                      NEW_BACKGROUND_TAB, PageTransition::TYPED);
     60 
     61   CheckViewID(VIEW_ID_TAB_0, true);
     62   CheckViewID(VIEW_ID_TAB_1, true);
     63 }
     64