blob: ccc9dfde3c32797a57b05f0ca83b4ccaf1818aa6 (
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
|
// 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/message_loop.h"
#include "base/string16.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/url_constants.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() {
ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
ASSERT_NO_FATAL_FAILURE(SetupComponents());
chrome::FocusLocationBar(browser());
// Use Textfield's view id on pure views. See crbug.com/71144.
ViewID location_bar_focus_view_id = VIEW_ID_LOCATION_BAR;
#if defined(USE_AURA)
location_bar_focus_view_id = VIEW_ID_OMNIBOX;
#endif
ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(),
location_bar_focus_view_id));
}
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_BOOKMARK_MODEL_LOADED:
case chrome::NOTIFICATION_HISTORY_LOADED:
case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED:
case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED:
break;
default:
FAIL() << "Unexpected notification type";
}
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"));
// Page is not bookmarked yet.
ASSERT_FALSE(loc_bar->GetBookmarkStarVisibility());
// Simulate an action box click and menu item selection.
loc_bar->TestActionBoxMenuItemSelected(IDC_BOOKMARK_PAGE);
// Page is now bookmarked.
ASSERT_TRUE(loc_bar->GetBookmarkStarVisibility());
// Get the BookmarkModel to unbookmark the bookmark.
BookmarkModel* model =
BookmarkModelFactory::GetForProfile(browser()->profile());
bookmark_utils::RemoveAllBookmarks(model, GURL("http://www.google.com"));
// Page is now unbookmarked.
ASSERT_FALSE(loc_bar->GetBookmarkStarVisibility());
}
|