Index: chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm |
diff --git a/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm b/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9c63ece3dd8999f80731fa8be0d025ac5e3731e4 |
--- /dev/null |
+++ b/chrome/browser/ui/cocoa/browser/password_generation_bubble_controller_unittest.mm |
@@ -0,0 +1,70 @@ |
+// 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. |
+ |
+#import "chrome/browser/ui/cocoa/browser/password_generation_bubble_controller.h" |
+ |
+#include "base/logging.h" |
+#include "base/sys_string_conversions.h" |
+#include "chrome/browser/autofill/password_generator.h" |
+#include "chrome/browser/ui/cocoa/cocoa_profile_test.h" |
+#include "content/public/common/password_form.h" |
+#include "testing/gtest_mac.h" |
+#include "ui/base/test/cocoa_test_event_utils.h" |
+ |
+class PasswordGenerationBubbleControllerTest : public CocoaProfileTest { |
+ public: |
+ virtual void SetUp() { |
+ CocoaTest::SetUp(); |
+ |
+ content::PasswordForm form; |
+ generator_.reset(new autofill::PasswordGenerator(20)); |
+ NSRect frame = [test_window() frame]; |
+ NSPoint point = NSMakePoint(NSMidX(frame), NSMidY(frame)); |
+ |
+ controller_ = [[PasswordGenerationBubbleController alloc] |
sail
2012/11/28 06:47:16
does this delete it self? if so add a comment abov
Garrett Casto
2012/11/30 20:56:26
Done.
|
+ initWithWindow:test_window() |
+ anchoredAt:point |
+ renderViewHost:nil |
+ passwordManager:nil |
+ usingGenerator:generator_.get() |
+ forForm:form]; |
+ } |
+ |
+ PasswordGenerationBubbleController* controller() { return controller_; } |
+ |
+ protected: |
+ // Weak. |
+ PasswordGenerationBubbleController* controller_; |
sail
2012/11/28 06:47:16
initialize this to nil in the constructor?
Garrett Casto
2012/11/30 20:56:26
Done.
|
+ |
+ scoped_ptr<autofill::PasswordGenerator> generator_; |
+}; |
+ |
+TEST_F(PasswordGenerationBubbleControllerTest, Regenerate) { |
+ [controller() showWindow:nil]; |
+ |
+ NSView* contents = [[controller() window] contentView]; |
+ for (NSView* subview in [contents subviews]) { |
sail
2012/11/28 06:47:16
it would be better to just add an accessor to Pass
Garrett Casto
2012/11/30 20:56:26
Done.
|
+ // Get the textfield. |
+ if ([subview isKindOfClass:[PasswordGenerationTextField class]]) { |
+ PasswordGenerationTextField* textfield = |
+ static_cast<PasswordGenerationTextField*>(subview); |
+ // Grab the starting password value. |
+ NSString* before = [textfield stringValue]; |
+ |
+ // Click on the regenerate icon. |
+ NSRect rect = [textfield getIconFrame]; |
+ rect = [[textfield window] convertRectToScreen:rect]; |
sail
2012/11/28 06:47:16
try adding "rect = [textfield convertRect:rect toV
Garrett Casto
2012/11/30 20:56:26
I actually tried this before, and it doesn't work.
|
+ NSPoint point = NSMakePoint(rect.origin.x + 1, rect.origin.y + 1); |
+ [test_window() sendEvent: |
+ cocoa_test_event_utils::LeftMouseDownAtPointInWindow( |
+ point, [textfield window])]; |
+ |
+ // Make sure that the password has changed. Technically this will fail |
+ // about once every 1e28 times, but not something we really need to worry |
+ // about. |
+ NSString* after = [textfield stringValue]; |
+ EXPECT_FALSE([before isEqualToString:after]); |
+ } |
+ } |
+} |