summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/omnibox/action_box_browsertest.cc
blob: a9a200917a000e6422852f54bb418896cdd3174b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/message_loop.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/toolbar/action_box_menu_model.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"

class ActionBoxTest : public InProcessBrowserTest,
                      public content::NotificationObserver {
 protected:
  ActionBoxTest() {}

  virtual void SetUpOnMainThread() OVERRIDE {
    ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
    ASSERT_NO_FATAL_FAILURE(SetupComponents());
    chrome::FocusLocationBar(browser());
    ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
  }

  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
    // Enable Action Box UI for the test.
    command_line->AppendSwitchASCII(switches::kActionBox, "1");
  }

  void SetupComponents() {}

  virtual void Observe(int type,
                       const content::NotificationSource& source,
                       const content::NotificationDetails& details) OVERRIDE {
    switch (type) {
      case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
      case chrome::NOTIFICATION_TAB_PARENTED:
      case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY:
      case chrome::NOTIFICATION_HISTORY_LOADED:
      case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED:
      case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED:
        break;
      default:
        FAIL() << "Unexpected notification type";
    }
    base::MessageLoop::current()->Quit();
  }

  DISALLOW_COPY_AND_ASSIGN(ActionBoxTest);
};

// Test if Bookmark star appears after bookmarking a page in the action box, and
// disappears after unbookmarking a page.
IN_PROC_BROWSER_TEST_F(ActionBoxTest, BookmarkAPageTest) {
  LocationBarTesting* loc_bar =
      browser()->window()->GetLocationBar()->GetLocationBarForTesting();

  // Navigate somewhere we can bookmark.
  ui_test_utils::NavigateToURL(browser(), GURL("http://www.google.com"));

  // Make sure the bookmarking system is up and running.
  BookmarkModel* model =
      BookmarkModelFactory::GetForProfile(browser()->profile());
  ui_test_utils::WaitForBookmarkModelToLoad(model);

  // Page is not bookmarked yet.
  ASSERT_FALSE(loc_bar->GetBookmarkStarVisibility());

  // Simulate an action box click and menu item selection.
  chrome::ExecuteCommand(browser(), IDC_BOOKMARK_PAGE_FROM_STAR);

  // Page is now bookmarked.
  ASSERT_TRUE(loc_bar->GetBookmarkStarVisibility());

  // Get the BookmarkModel to unbookmark the bookmark.
  bookmark_utils::RemoveAllBookmarks(model, GURL("http://www.google.com"));

  // Page is now unbookmarked.
  ASSERT_FALSE(loc_bar->GetBookmarkStarVisibility());

}