summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpamg@google.com <pamg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-17 18:27:16 +0000
committerpamg@google.com <pamg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-17 18:27:16 +0000
commit96077b3a3d2f5ca3c2e3ecd5aaee79e053bd13ab (patch)
tree5945bf4eed19e5085bb9cf0e158ab15e1b03bf08 /chrome/browser
parent1714598684df482fdd969a4baec3c2f99de86cdb (diff)
downloadchromium_src-96077b3a3d2f5ca3c2e3ecd5aaee79e053bd13ab.zip
chromium_src-96077b3a3d2f5ca3c2e3ecd5aaee79e053bd13ab.tar.gz
chromium_src-96077b3a3d2f5ca3c2e3ecd5aaee79e053bd13ab.tar.bz2
First batch of unit tests for mac Page Actions.
Fix leak of page_action_views_ in LocationBarViewMac. TEST=covered by unit tests and valgrind UI tests BUG=30448, 12281 Review URL: http://codereview.chromium.org/506046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34842 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_unittest.mm99
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.h16
-rw-r--r--chrome/browser/cocoa/location_bar_view_mac.mm2
3 files changed, 114 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
index b52012b..a73110e 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_unittest.mm
@@ -28,6 +28,34 @@ class MockSecurityImageView : public LocationBarViewMac::SecurityImageView {
MOCK_METHOD0(OnMousePressed, bool());
};
+class MockPageActionImageView : public LocationBarViewMac::PageActionImageView {
+ public:
+ MockPageActionImageView() {}
+ virtual ~MockPageActionImageView() {}
+
+ // We can't use gmock's MOCK_METHOD macro, because it doesn't like the
+ // NSRect argument to OnMousePressed.
+ virtual bool OnMousePressed(NSRect bounds) {
+ mouse_was_pressed_ = true;
+ return true;
+ }
+
+ bool MouseWasPressed() { return mouse_was_pressed_; }
+
+ private:
+ bool mouse_was_pressed_;
+};
+
+class TestPageActionViewList : public LocationBarViewMac::PageActionViewList {
+ public:
+ TestPageActionViewList()
+ : LocationBarViewMac::PageActionViewList(NULL, NULL, NULL) {}
+
+ void Add(LocationBarViewMac::PageActionImageView* view) {
+ views_.push_back(view);
+ }
+};
+
// Mock up an incrementing event number.
NSUInteger eventNumber = 0;
@@ -550,6 +578,77 @@ TEST_F(AutocompleteTextFieldObserverTest, SecurityIconMouseDown) {
[field_ mouseDown:event];
}
+TEST_F(AutocompleteTextFieldObserverTest, PageActionMouseDown) {
+ AutocompleteTextFieldCell* cell = [field_ autocompleteTextFieldCell];
+
+ MockSecurityImageView security_image_view(NULL, NULL);
+ security_image_view.SetImageShown(
+ LocationBarViewMac::SecurityImageView::LOCK);
+ [cell setSecurityImageView:&security_image_view];
+
+ MockPageActionImageView page_action_view;
+ NSImage* image = [NSImage imageNamed:@"NSApplicationIcon"];
+ page_action_view.SetImage(image);
+
+ MockPageActionImageView page_action_view2;
+ page_action_view2.SetImage(image);
+
+ TestPageActionViewList list;
+ list.Add(&page_action_view);
+ list.Add(&page_action_view2);
+ [cell setPageActionViewList:&list];
+
+ // One page action, no security lock.
+ security_image_view.SetVisible(false);
+ page_action_view.SetVisible(true);
+ page_action_view2.SetVisible(false);
+ NSRect iconFrame([cell pageActionFrameForIndex:0 inFrame:[field_ bounds]]);
+ NSPoint location(NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame)));
+ NSEvent* event(Event(field_, location, NSLeftMouseDown, 1));
+
+ [field_ mouseDown:event];
+ EXPECT_TRUE(page_action_view.MouseWasPressed());
+
+ // Two page actions, no security lock.
+ page_action_view2.SetVisible(true);
+ iconFrame = [cell pageActionFrameForIndex:0 inFrame:[field_ bounds]];
+ location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
+ event = Event(field_, location, NSLeftMouseDown, 1);
+
+ [field_ mouseDown:event];
+ EXPECT_TRUE(page_action_view.MouseWasPressed());
+
+ iconFrame = [cell pageActionFrameForIndex:1 inFrame:[field_ bounds]];
+ location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
+ event = Event(field_, location, NSLeftMouseDown, 1);
+
+ [field_ mouseDown:event];
+ EXPECT_TRUE(page_action_view.MouseWasPressed());
+
+ // Two page actions plus security lock.
+ security_image_view.SetVisible(true);
+ iconFrame = [cell pageActionFrameForIndex:0 inFrame:[field_ bounds]];
+ location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
+ event = Event(field_, location, NSLeftMouseDown, 1);
+
+ [field_ mouseDown:event];
+ EXPECT_TRUE(page_action_view.MouseWasPressed());
+
+ iconFrame = [cell pageActionFrameForIndex:1 inFrame:[field_ bounds]];
+ location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
+ event = Event(field_, location, NSLeftMouseDown, 1);
+
+ [field_ mouseDown:event];
+ EXPECT_TRUE(page_action_view.MouseWasPressed());
+
+ iconFrame = [cell securityImageFrameForFrame:[field_ bounds]];
+ location = NSMakePoint(NSMidX(iconFrame), NSMidY(iconFrame));
+ event = Event(field_, location, NSLeftMouseDown, 1);
+
+ EXPECT_CALL(security_image_view, OnMousePressed());
+ [field_ mouseDown:event];
+}
+
// Verify that -setAttributedStringValue: works as expected when
// focussed or when not focussed. Our code mostly depends on about
// whether -stringValue works right.
diff --git a/chrome/browser/cocoa/location_bar_view_mac.h b/chrome/browser/cocoa/location_bar_view_mac.h
index 6426172..45a891a 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.h
+++ b/chrome/browser/cocoa/location_bar_view_mac.h
@@ -18,6 +18,7 @@
#include "chrome/browser/extensions/image_loading_tracker.h"
#include "chrome/browser/location_bar.h"
#include "chrome/browser/toolbar_model.h"
+#include "third_party/skia/include/core/SkBitmap.h"
@class AutocompleteTextField;
class BubblePositioner;
@@ -192,6 +193,15 @@ class LocationBarViewMac : public AutocompleteEditController,
// is the current page URL.
void UpdateVisibility(TabContents* contents, const GURL& url);
+ protected:
+ // For unit testing only.
+ PageActionImageView() : owner_(NULL),
+ profile_(NULL),
+ page_action_(NULL),
+ tracker_(NULL),
+ current_tab_id_(-1),
+ preview_enabled_(false) {}
+
private:
// Overridden from NotificationObserver:
virtual void Observe(NotificationType type,
@@ -256,10 +266,12 @@ class LocationBarViewMac : public AutocompleteEditController,
// describe the bounds of the affected action's icon.
void OnMousePressed(NSRect iconFrame, size_t index);
- private:
- // Any installed Page Actions.
+ protected:
+ // Any installed Page Actions (weak references: owned by the extensions
+ // service). Exposed for unit testing only.
std::vector<PageActionImageView*> views_;
+ private:
// The location bar view that owns us.
LocationBarViewMac* owner_;
diff --git a/chrome/browser/cocoa/location_bar_view_mac.mm b/chrome/browser/cocoa/location_bar_view_mac.mm
index 7e13ff3..fbe9f09 100644
--- a/chrome/browser/cocoa/location_bar_view_mac.mm
+++ b/chrome/browser/cocoa/location_bar_view_mac.mm
@@ -32,7 +32,6 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils_mac.h"
-#include "third_party/skia/include/core/SkBitmap.h"
// TODO(shess): This code is mostly copied from the gtk
// implementation. Make sure it's all appropriate and flesh it out.
@@ -103,6 +102,7 @@ LocationBarViewMac::LocationBarViewMac(
LocationBarViewMac::~LocationBarViewMac() {
// TODO(shess): Placeholder for omnibox changes.
+ delete page_action_views_;
}
std::wstring LocationBarViewMac::GetInputString() const {