OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/browser_action_test_util.h" | 5 #include "chrome/browser/extensions/browser_action_test_util.h" |
6 | 6 |
7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" | 10 #import "chrome/browser/ui/cocoa/browser_window_cocoa.h" |
11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/extensions/browser_action_button.h" |
12 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" | 13 #import "chrome/browser/ui/cocoa/extensions/browser_actions_controller.h" |
13 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" | 14 #import "chrome/browser/ui/cocoa/extensions/extension_popup_controller.h" |
14 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 15 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
15 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" | 16 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" |
16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 BrowserActionsController* GetController(Browser* browser) { | 22 BrowserActionsController* GetController(Browser* browser) { |
22 BrowserWindowCocoa* window = | 23 BrowserWindowCocoa* window = |
23 static_cast<BrowserWindowCocoa*>(browser->window()); | 24 static_cast<BrowserWindowCocoa*>(browser->window()); |
24 | 25 |
25 return [[window->cocoa_controller() toolbarController] | 26 return [[window->cocoa_controller() toolbarController] |
26 browserActionsController]; | 27 browserActionsController]; |
27 } | 28 } |
28 | 29 |
29 NSButton* GetButton(Browser* browser, int index) { | 30 BrowserActionButton* GetButton(Browser* browser, int index) { |
30 return [GetController(browser) buttonWithIndex:index]; | 31 return [GetController(browser) buttonWithIndex:index]; |
31 } | 32 } |
32 | 33 |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 int BrowserActionTestUtil::NumberOfBrowserActions() { | 36 int BrowserActionTestUtil::NumberOfBrowserActions() { |
36 return [GetController(browser_) buttonCount]; | 37 return [GetController(browser_) buttonCount]; |
37 } | 38 } |
38 | 39 |
| 40 int BrowserActionTestUtil::VisibleBrowserActions() { |
| 41 return [GetController(browser_) visibleButtonCount]; |
| 42 } |
| 43 |
39 ExtensionAction* BrowserActionTestUtil::GetExtensionAction(int index) { | 44 ExtensionAction* BrowserActionTestUtil::GetExtensionAction(int index) { |
40 NOTREACHED(); | 45 NOTREACHED(); |
41 return NULL; | 46 return NULL; |
42 } | 47 } |
43 | 48 |
44 void BrowserActionTestUtil::InspectPopup(int index) { | 49 void BrowserActionTestUtil::InspectPopup(int index) { |
45 NOTREACHED(); | 50 NOTREACHED(); |
46 } | 51 } |
47 | 52 |
48 bool BrowserActionTestUtil::HasIcon(int index) { | 53 bool BrowserActionTestUtil::HasIcon(int index) { |
49 return [GetButton(browser_, index) image] != nil; | 54 return [GetButton(browser_, index) image] != nil; |
50 } | 55 } |
51 | 56 |
52 gfx::Image BrowserActionTestUtil::GetIcon(int index) { | 57 gfx::Image BrowserActionTestUtil::GetIcon(int index) { |
53 NSImage* ns_image = [GetButton(browser_, index) image]; | 58 NSImage* ns_image = [GetButton(browser_, index) image]; |
54 // gfx::Image takes ownership of the |ns_image| reference. We have to increase | 59 // gfx::Image takes ownership of the |ns_image| reference. We have to increase |
55 // the ref count so |ns_image| stays around when the image object is | 60 // the ref count so |ns_image| stays around when the image object is |
56 // destroyed. | 61 // destroyed. |
57 base::mac::NSObjectRetain(ns_image); | 62 base::mac::NSObjectRetain(ns_image); |
58 return gfx::Image(ns_image); | 63 return gfx::Image(ns_image); |
59 } | 64 } |
60 | 65 |
61 void BrowserActionTestUtil::Press(int index) { | 66 void BrowserActionTestUtil::Press(int index) { |
62 NSButton* button = GetButton(browser_, index); | 67 NSButton* button = GetButton(browser_, index); |
63 [button performClick:nil]; | 68 [button performClick:nil]; |
64 } | 69 } |
65 | 70 |
| 71 std::string BrowserActionTestUtil::GetExtensionId(int index) { |
| 72 return [GetButton(browser_, index) extension]->id(); |
| 73 } |
| 74 |
66 std::string BrowserActionTestUtil::GetTooltip(int index) { | 75 std::string BrowserActionTestUtil::GetTooltip(int index) { |
67 NSString* tooltip = [GetButton(browser_, index) toolTip]; | 76 NSString* tooltip = [GetButton(browser_, index) toolTip]; |
68 return base::SysNSStringToUTF8(tooltip); | 77 return base::SysNSStringToUTF8(tooltip); |
69 } | 78 } |
70 | 79 |
71 gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() { | 80 gfx::NativeView BrowserActionTestUtil::GetPopupNativeView() { |
72 return [[ExtensionPopupController popup] view]; | 81 return [[ExtensionPopupController popup] view]; |
73 } | 82 } |
74 | 83 |
75 bool BrowserActionTestUtil::HasPopup() { | 84 bool BrowserActionTestUtil::HasPopup() { |
76 return [ExtensionPopupController popup] != nil; | 85 return [ExtensionPopupController popup] != nil; |
77 } | 86 } |
78 | 87 |
79 gfx::Rect BrowserActionTestUtil::GetPopupBounds() { | 88 gfx::Rect BrowserActionTestUtil::GetPopupBounds() { |
80 NSRect bounds = [[[ExtensionPopupController popup] view] bounds]; | 89 NSRect bounds = [[[ExtensionPopupController popup] view] bounds]; |
81 return gfx::Rect(NSRectToCGRect(bounds)); | 90 return gfx::Rect(NSRectToCGRect(bounds)); |
82 } | 91 } |
83 | 92 |
84 bool BrowserActionTestUtil::HidePopup() { | 93 bool BrowserActionTestUtil::HidePopup() { |
85 ExtensionPopupController* controller = [ExtensionPopupController popup]; | 94 ExtensionPopupController* controller = [ExtensionPopupController popup]; |
86 // The window must be gone or we'll fail a unit test with windows left open. | 95 // The window must be gone or we'll fail a unit test with windows left open. |
87 [static_cast<InfoBubbleWindow*>([controller window]) | 96 [static_cast<InfoBubbleWindow*>([controller window]) |
88 setAllowedAnimations:info_bubble::kAnimateNone]; | 97 setAllowedAnimations:info_bubble::kAnimateNone]; |
89 [controller close]; | 98 [controller close]; |
90 return !HasPopup(); | 99 return !HasPopup(); |
91 } | 100 } |
92 | 101 |
| 102 // static |
| 103 void BrowserActionTestUtil::DisableAnimations() { |
| 104 } |
| 105 |
| 106 // static |
| 107 void BrowserActionTestUtil::EnableAnimations() { |
| 108 } |
| 109 |
| 110 // static |
93 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { | 111 gfx::Size BrowserActionTestUtil::GetMinPopupSize() { |
94 return gfx::Size(NSSizeToCGSize([ExtensionPopupController minPopupSize])); | 112 return gfx::Size(NSSizeToCGSize([ExtensionPopupController minPopupSize])); |
95 } | 113 } |
96 | 114 |
| 115 // static |
97 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { | 116 gfx::Size BrowserActionTestUtil::GetMaxPopupSize() { |
98 return gfx::Size(NSSizeToCGSize([ExtensionPopupController maxPopupSize])); | 117 return gfx::Size(NSSizeToCGSize([ExtensionPopupController maxPopupSize])); |
99 } | 118 } |
OLD | NEW |