Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7713)

Unified Diff: chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.mm

Issue 135933003: rAc: split TestableAutofillDialogView implementation into its own class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: GAE hates me. Reupload. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.mm b/chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.mm
new file mode 100644
index 0000000000000000000000000000000000000000..06515c5a0cc5ceeb5ba196890f5ce2c1405cbfcf
--- /dev/null
+++ b/chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.mm
@@ -0,0 +1,137 @@
+// Copyright (c) 2014 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 "chrome/browser/ui/cocoa/autofill/autofill_dialog_view_tester_cocoa.h"
+
+#include "base/strings/sys_string_conversions.h"
+#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
+#import "chrome/browser/ui/cocoa/autofill/autofill_dialog_window_controller.h"
+#import "chrome/browser/ui/cocoa/autofill/autofill_main_container.h"
+#import "chrome/browser/ui/cocoa/autofill/autofill_section_container.h"
+#import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h"
+
+
+// Mirrors the AutofillDialogViewTester API on the C++ side.
+@interface AutofillDialogWindowController (AutofillDialogViewTesterCocoa)
+
+- (void)setTextContents:(NSString*)text
+ forType:(autofill::ServerFieldType)type;
+- (void)setTextContents:(NSString*)text
+ ofSuggestionForSection:(autofill::DialogSection)section;
+- (void)activateFieldForType:(autofill::ServerFieldType)type;
+- (content::WebContents*)getSignInWebContents;
+- (BOOL)isShowingOverlay;
+
+@end
+
+
+@implementation AutofillDialogWindowController (AutofillDialogViewTesterCocoa)
+
+- (void)setTextContents:(NSString*)text
+ forType:(autofill::ServerFieldType)type {
+ for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
+ autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
+ // TODO(groby): Need to find the section for an input directly - wasteful.
+ [[mainContainer_ sectionForId:section] setFieldValue:text forType:type];
+ }
+}
+
+- (void)setTextContents:(NSString*)text
+ ofSuggestionForSection:(autofill::DialogSection)section {
+ [[mainContainer_ sectionForId:section] setSuggestionFieldValue:text];
+}
+
+- (void)activateFieldForType:(autofill::ServerFieldType)type {
+ for (size_t i = autofill::SECTION_MIN; i <= autofill::SECTION_MAX; ++i) {
+ autofill::DialogSection section = static_cast<autofill::DialogSection>(i);
+ [[mainContainer_ sectionForId:section] activateFieldForType:type];
+ }
+}
+
+- (content::WebContents*)getSignInWebContents {
+ return [signInContainer_ webContents];
+}
+
+- (BOOL)isShowingOverlay {
+ return ![[overlayController_ view] isHidden];
+}
+
+@end
+
+namespace autofill {
+
+scoped_ptr<AutofillDialogViewTester> AutofillDialogViewTester::For(
+ AutofillDialogView* dialog) {
+ return scoped_ptr<AutofillDialogViewTester>(
+ new AutofillDialogViewTesterCocoa(
+ static_cast<AutofillDialogCocoa*>(dialog)));
+}
+
+AutofillDialogViewTesterCocoa::AutofillDialogViewTesterCocoa(
+ AutofillDialogCocoa* dialog)
+ : dialog_(dialog) {}
+
+AutofillDialogViewTesterCocoa::~AutofillDialogViewTesterCocoa() {}
+
+void AutofillDialogViewTesterCocoa::SubmitForTesting() {
+ [controller() accept:nil];
+}
+
+void AutofillDialogViewTesterCocoa::CancelForTesting() {
+ [controller() cancel:nil];
+}
+
+base::string16 AutofillDialogViewTesterCocoa::GetTextContentsOfInput(
+ ServerFieldType type) {
+ for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
+ DialogSection section = static_cast<DialogSection>(i);
+ FieldValueMap contents;
+ [controller() getInputs:&contents forSection:section];
+ FieldValueMap::const_iterator it = contents.find(type);
+ if (it != contents.end())
+ return it->second;
+ }
+
+ NOTREACHED();
+ return base::string16();
+}
+
+void AutofillDialogViewTesterCocoa::SetTextContentsOfInput(
+ ServerFieldType type,
+ const base::string16& contents) {
+ [controller() setTextContents:base::SysUTF16ToNSString(contents)
+ forType:type];
Dan Beam 2014/01/28 22:10:35 nit: [controller() setTextContents:base::SysUTF16
+}
+
+void AutofillDialogViewTesterCocoa::SetTextContentsOfSuggestionInput(
+ DialogSection section,
+ const base::string16& text) {
+ [controller() setTextContents:base::SysUTF16ToNSString(text)
+ ofSuggestionForSection:section];
Evan Stade 2014/01/28 22:09:52 is this the correct indent?
Dan Beam 2014/01/28 22:10:35 [controller() setTextContents:base::SysUTF16ToNSSt
groby-ooo-7-16 2014/01/29 22:10:21 What Dan said. Victim of :s// :)
+}
+
+void AutofillDialogViewTesterCocoa::ActivateInput(ServerFieldType type) {
+ [controller() activateFieldForType:type];
+}
+
+gfx::Size AutofillDialogViewTesterCocoa::GetSize() const {
+ return gfx::Size(NSSizeToCGSize([[controller() window] frame].size));
+}
+
+content::WebContents* AutofillDialogViewTesterCocoa::GetSignInWebContents() {
+ return [controller() getSignInWebContents];
+}
+
+
Evan Stade 2014/01/28 22:09:52 ^H
+bool AutofillDialogViewTesterCocoa::IsShowingOverlay() const {
+ return [controller() isShowingOverlay];
+}
+
+AutofillDialogWindowController*
+ AutofillDialogViewTesterCocoa::controller() const {
+ return dialog_->sheet_delegate_;
+}
+
+}
Evan Stade 2014/01/28 22:09:52 // namespace autofill
Dan Beam 2014/01/28 22:10:35 nit: } // namespace autofill
+
Evan Stade 2014/01/28 22:09:52 ^H

Powered by Google App Engine
This is Rietveld 408576698