1 // Copyright (c) 2013 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 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h"
9 #import "chrome/browser/ui/cocoa/autofill/autofill_dialog_cocoa.h"
10 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_delegate.h"
15 #include "content/public/browser/web_contents_view.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/platform_test.h"
18 #import "ui/base/test/ui_cocoa_test_helper.h"
22 class AutofillSignInContainerTest : public ChromeRenderViewHostTestHarness {
24 AutofillSignInContainerTest() : dialog_(&delegate_), test_window_(nil) {}
25 virtual void SetUp() {
26 ChromeRenderViewHostTestHarness::SetUp();
27 // Inherting from ChromeRenderViewHostTestHarness means we can't inherit
28 // from from CocoaTest, so do a bootstrap and create test window.
29 CocoaTest::BootstrapCocoa();
32 [[AutofillSignInContainer alloc] initWithDialog:&dialog_]);
33 EXPECT_CALL(delegate_, profile())
34 .WillOnce(testing::Return(this->profile()));
35 [[test_window() contentView] addSubview:[container_ view]];
38 virtual void TearDown() {
39 container_.reset(); // must reset at teardown - depends on test harness.
42 ChromeRenderViewHostTestHarness::TearDown();
45 CocoaTestHelperWindow* test_window() {
47 test_window_ = [[CocoaTestHelperWindow alloc] init];
48 if (base::debug::BeingDebugged()) {
49 [test_window_ orderFront:nil];
51 [test_window_ orderBack:nil];
58 base::scoped_nsobject<AutofillSignInContainer> container_;
59 testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_;
60 autofill::AutofillDialogCocoa dialog_;
61 CocoaTestHelperWindow* test_window_;
66 TEST_VIEW(AutofillSignInContainerTest, [container_ view])
68 TEST_F(AutofillSignInContainerTest, Subviews) {
69 // isKindOfClass would be the better choice, but
70 // WebContentsViewCocoaClass is defined in content, and not public.
71 bool hasWebView =[[container_ view] isEqual:
72 [container_ webContents]->GetView()->GetNativeView()];
74 EXPECT_TRUE(hasWebView);