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