| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_sign_in_container.h" |
| 6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "chrome/browser/ui/autofill/mock_autofill_dialog_controller.h" | 8 #include "chrome/browser/ui/autofill/mock_autofill_dialog_view_delegate.h" |
| 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 9 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 11 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 #include "content/public/browser/web_contents_view.h" | 13 #include "content/public/browser/web_contents_view.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
| 16 #import "ui/base/test/ui_cocoa_test_helper.h" | 16 #import "ui/base/test/ui_cocoa_test_helper.h" |
| 17 | 17 |
| 18 @interface AutofillSignInContainer (ExposedForTesting) | 18 @interface AutofillSignInContainer (ExposedForTesting) |
| 19 - (content::WebContents*)webContents; | 19 - (content::WebContents*)webContents; |
| 20 @end | 20 @end |
| 21 | 21 |
| 22 @implementation AutofillSignInContainer (ExposedForTesting) | 22 @implementation AutofillSignInContainer (ExposedForTesting) |
| 23 - (content::WebContents*)webContents { return webContents_.get(); } | 23 - (content::WebContents*)webContents { return webContents_.get(); } |
| 24 @end | 24 @end |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class AutofillSignInContainerTest : public ChromeRenderViewHostTestHarness { | 28 class AutofillSignInContainerTest : public ChromeRenderViewHostTestHarness { |
| 29 public: | 29 public: |
| 30 AutofillSignInContainerTest() : test_window_(nil) {} | 30 AutofillSignInContainerTest() : test_window_(nil) {} |
| 31 virtual void SetUp() { | 31 virtual void SetUp() { |
| 32 ChromeRenderViewHostTestHarness::SetUp(); | 32 ChromeRenderViewHostTestHarness::SetUp(); |
| 33 // Inherting from ChromeRenderViewHostTestHarness means we can't inherit | 33 // Inherting from ChromeRenderViewHostTestHarness means we can't inherit |
| 34 // from from CocoaTest, so do a bootstrap and create test window. | 34 // from from CocoaTest, so do a bootstrap and create test window. |
| 35 CocoaTest::BootstrapCocoa(); | 35 CocoaTest::BootstrapCocoa(); |
| 36 container_.reset( | 36 container_.reset( |
| 37 [[AutofillSignInContainer alloc] initWithController:&controller_]); | 37 [[AutofillSignInContainer alloc] initWithDelegate:&delegate_]); |
| 38 EXPECT_CALL(controller_, profile()) | 38 EXPECT_CALL(delegate_, profile()) |
| 39 .WillOnce(testing::Return(this->profile())); | 39 .WillOnce(testing::Return(this->profile())); |
| 40 [[test_window() contentView] addSubview:[container_ view]]; | 40 [[test_window() contentView] addSubview:[container_ view]]; |
| 41 } | 41 } |
| 42 | 42 |
| 43 virtual void TearDown() { | 43 virtual void TearDown() { |
| 44 container_.reset(); // must reset at teardown - depends on test harness. | 44 container_.reset(); // must reset at teardown - depends on test harness. |
| 45 [test_window_ close]; | 45 [test_window_ close]; |
| 46 test_window_ = nil; | 46 test_window_ = nil; |
| 47 ChromeRenderViewHostTestHarness::TearDown(); | 47 ChromeRenderViewHostTestHarness::TearDown(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 CocoaTestHelperWindow* test_window() { | 50 CocoaTestHelperWindow* test_window() { |
| 51 if (!test_window_) { | 51 if (!test_window_) { |
| 52 test_window_ = [[CocoaTestHelperWindow alloc] init]; | 52 test_window_ = [[CocoaTestHelperWindow alloc] init]; |
| 53 if (base::debug::BeingDebugged()) { | 53 if (base::debug::BeingDebugged()) { |
| 54 [test_window_ orderFront:nil]; | 54 [test_window_ orderFront:nil]; |
| 55 } else { | 55 } else { |
| 56 [test_window_ orderBack:nil]; | 56 [test_window_ orderBack:nil]; |
| 57 } | 57 } |
| 58 } | 58 } |
| 59 return test_window_; | 59 return test_window_; |
| 60 } | 60 } |
| 61 | 61 |
| 62 protected: | 62 protected: |
| 63 base::scoped_nsobject<AutofillSignInContainer> container_; | 63 base::scoped_nsobject<AutofillSignInContainer> container_; |
| 64 testing::NiceMock<autofill::MockAutofillDialogController> controller_; | 64 testing::NiceMock<autofill::MockAutofillDialogViewDelegate> delegate_; |
| 65 CocoaTestHelperWindow* test_window_; | 65 CocoaTestHelperWindow* test_window_; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 } // namespace | 68 } // namespace |
| 69 | 69 |
| 70 TEST_VIEW(AutofillSignInContainerTest, [container_ view]) | 70 TEST_VIEW(AutofillSignInContainerTest, [container_ view]) |
| 71 | 71 |
| 72 TEST_F(AutofillSignInContainerTest, Subviews) { | 72 TEST_F(AutofillSignInContainerTest, Subviews) { |
| 73 // isKindOfClass would be the better choice, but | 73 // isKindOfClass would be the better choice, but |
| 74 // WebContentsViewCocoaClass is defined in content, and not public. | 74 // WebContentsViewCocoaClass is defined in content, and not public. |
| 75 bool hasWebView =[[container_ view] isEqual: | 75 bool hasWebView =[[container_ view] isEqual: |
| 76 [container_ webContents]->GetView()->GetNativeView()]; | 76 [container_ webContents]->GetView()->GetNativeView()]; |
| 77 | 77 |
| 78 EXPECT_TRUE(hasWebView); | 78 EXPECT_TRUE(hasWebView); |
| 79 } | 79 } |
| OLD | NEW |