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 "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h"
17 #import "ui/gfx/test/ui_cocoa_test_helper.h"
21 class AutofillSignInContainerTest : public ChromeRenderViewHostTestHarness {
23 AutofillSignInContainerTest() : dialog_(&delegate_), test_window_(nil) {}
24 virtual void SetUp() {
25 ChromeRenderViewHostTestHarness::SetUp();
26 // Inherting from ChromeRenderViewHostTestHarness means we can't inherit
27 // from from CocoaTest, so do a bootstrap and create test window.
28 CocoaTest::BootstrapCocoa();
31 [[AutofillSignInContainer alloc] initWithDialog:&dialog_]);
32 EXPECT_CALL(delegate_, profile())
33 .WillOnce(testing::Return(this->profile()));
34 [[test_window() contentView] addSubview:[container_ view]];
37 virtual void TearDown() {
38 container_.reset(); // must reset at teardown - depends on test harness.
41 ChromeRenderViewHostTestHarness::TearDown();
44 CocoaTestHelperWindow* test_window() {
46 test_window_ = [[CocoaTestHelperWindow alloc] init];
47 if (base::debug::BeingDebugged()) {
48 [test_window_ orderFront:nil];
50 [test_window_ orderBack:nil];
57 base::scoped_nsobject<AutofillSignInContainer> container_;
58 testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_;
59 autofill::AutofillDialogCocoa dialog_;
60 CocoaTestHelperWindow* test_window_;
65 TEST_VIEW(AutofillSignInContainerTest, [container_ view])
67 TEST_F(AutofillSignInContainerTest, Subviews) {
68 // isKindOfClass would be the better choice, but
69 // WebContentsViewCocoaClass is defined in content, and not public.
70 bool hasWebView =[[container_ view] isEqual:
71 [container_ webContents]->GetNativeView()];
73 EXPECT_TRUE(hasWebView);