1 // Copyright 2014 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 "chrome/app/chrome_command_ids.h"
6 #include "chrome/browser/extensions/api/commands/command_service.h"
7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h"
12 #include "chrome/browser/ui/views/frame/browser_view.h"
13 #include "chrome/browser/ui/views/location_bar/star_view.h"
14 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
15 #include "chrome/test/base/ui_test_utils.h"
16 #include "extensions/common/manifest_constants.h"
17 #include "extensions/test/result_catcher.h"
18 #include "ui/events/event_utils.h"
20 typedef ExtensionApiTest BookmarkOverrideTest
;
23 // Bookmark this page keybinding.
24 #if defined(OS_MACOSX)
25 const char kBookmarkKeybinding
[] = "Command+D";
27 const char kBookmarkKeybinding
[] = "Ctrl+D";
28 #endif // defined(OS_MACOSX)
31 // Test that clicking the star brings up the bookmark UI, if no extension
32 // requests to override ctrl-D and the user has assigned it to an extension.
33 // Flaky on all platforms: https://crbug.com/448956.
34 IN_PROC_BROWSER_TEST_F(BookmarkOverrideTest
, DISABLED_NonOverrideStarClick
) {
35 ASSERT_TRUE(test_server()->Start());
36 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_
;
37 const extensions::Extension
* extension
= GetSingleLoadedExtension();
39 extensions::CommandService
* command_service
=
40 extensions::CommandService::Get(browser()->profile());
42 // Simulate the user setting the keybinding to Ctrl+D.
43 command_service
->UpdateKeybindingPrefs(
44 extension
->id(), extensions::manifest_values::kBrowserActionCommandEvent
,
47 // Check that the BookmarkBubbleView is shown when clicking on the star.
48 BrowserView
* browser_view
= reinterpret_cast<BrowserView
*>(
50 views::View
* star_view
=
51 browser_view
->GetToolbarView()->location_bar()->star_view();
53 ui::MouseEvent
pressed_event(
54 ui::ET_MOUSE_PRESSED
, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
55 ui::EF_LEFT_MOUSE_BUTTON
, ui::EF_LEFT_MOUSE_BUTTON
);
56 ui::MouseEvent
released_event(
57 ui::ET_MOUSE_RELEASED
, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
58 ui::EF_LEFT_MOUSE_BUTTON
, ui::EF_LEFT_MOUSE_BUTTON
);
60 // Verify that clicking once shows the bookmark bubble.
61 EXPECT_FALSE(BookmarkBubbleView::bookmark_bubble());
62 star_view
->OnMousePressed(pressed_event
);
63 EXPECT_FALSE(BookmarkBubbleView::bookmark_bubble());
64 star_view
->OnMouseReleased(released_event
);
65 EXPECT_TRUE(BookmarkBubbleView::bookmark_bubble());
68 // Test that invoking the IDC_BOOKMARK_PAGE command (as done by the wrench menu)
69 // brings up the bookmark UI, if no extension requests to override ctrl-D and
70 // the user has assigned it to an extension.
71 // Flaky on all platforms: https://crbug.com/448956.
72 IN_PROC_BROWSER_TEST_F(BookmarkOverrideTest
, DISABLED_NonOverrideBookmarkPage
) {
73 ASSERT_TRUE(test_server()->Start());
74 ASSERT_TRUE(RunExtensionTest("keybinding/basics")) << message_
;
75 const extensions::Extension
* extension
= GetSingleLoadedExtension();
77 extensions::CommandService
* command_service
=
78 extensions::CommandService::Get(browser()->profile());
80 // Simulate the user setting the keybinding to Ctrl+D.
81 command_service
->UpdateKeybindingPrefs(
82 extension
->id(), extensions::manifest_values::kBrowserActionCommandEvent
,
85 // Check that the BookmarkBubbleView is shown when executing
87 EXPECT_FALSE(BookmarkBubbleView::bookmark_bubble());
88 chrome::ExecuteCommand(browser(), IDC_BOOKMARK_PAGE
);
89 EXPECT_TRUE(BookmarkBubbleView::bookmark_bubble());