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. 4 5#import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" 6 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" 18 19namespace { 20 21class AutofillSignInContainerTest : public ChromeRenderViewHostTestHarness { 22 public: 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(); 29 30 container_.reset( 31 [[AutofillSignInContainer alloc] initWithDialog:&dialog_]); 32 EXPECT_CALL(delegate_, profile()) 33 .WillOnce(testing::Return(this->profile())); 34 [[test_window() contentView] addSubview:[container_ view]]; 35 } 36 37 virtual void TearDown() { 38 container_.reset(); // must reset at teardown - depends on test harness. 39 [test_window_ close]; 40 test_window_ = nil; 41 ChromeRenderViewHostTestHarness::TearDown(); 42 } 43 44 CocoaTestHelperWindow* test_window() { 45 if (!test_window_) { 46 test_window_ = [[CocoaTestHelperWindow alloc] init]; 47 if (base::debug::BeingDebugged()) { 48 [test_window_ orderFront:nil]; 49 } else { 50 [test_window_ orderBack:nil]; 51 } 52 } 53 return test_window_; 54 } 55 56 protected: 57 base::scoped_nsobject<AutofillSignInContainer> container_; 58 testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_; 59 autofill::AutofillDialogCocoa dialog_; 60 CocoaTestHelperWindow* test_window_; 61}; 62 63} // namespace 64 65TEST_VIEW(AutofillSignInContainerTest, [container_ view]) 66 67TEST_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()]; 72 73 EXPECT_TRUE(hasWebView); 74} 75 76